You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
5.1 KiB

8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
  1. /**************************************************************
  2. *
  3. * To run this tool you need StreamDebugger library:
  4. * https://github.com/vshymanskyy/StreamDebugger
  5. * or from http://librarymanager/all#StreamDebugger
  6. *
  7. * TinyGSM Getting Started guide:
  8. * http://tiny.cc/tiny-gsm-readme
  9. *
  10. **************************************************************/
  11. // Select your modem:
  12. #define TINY_GSM_MODEM_SIM800
  13. // #define TINY_GSM_MODEM_SIM808
  14. // #define TINY_GSM_MODEM_SIM900
  15. // #define TINY_GSM_MODEM_UBLOX
  16. // #define TINY_GSM_MODEM_BG96
  17. // #define TINY_GSM_MODEM_A6
  18. // #define TINY_GSM_MODEM_A7
  19. // #define TINY_GSM_MODEM_M590
  20. // #define TINY_GSM_MODEM_ESP8266
  21. // #define TINY_GSM_MODEM_XBEE
  22. // Increase the buffer
  23. #define TINY_GSM_RX_BUFFER 512
  24. // Define the serial console for debug prints, if needed
  25. //#define TINY_GSM_DEBUG Serial
  26. #include <TinyGsmClient.h>
  27. // Your GPRS credentials
  28. // Leave empty, if missing user or pass
  29. const char apn[] = "YourAPN";
  30. const char user[] = "";
  31. const char pass[] = "";
  32. // Set serial for debug console (to the Serial Monitor, speed 115200)
  33. #define SerialMon Serial
  34. // Set serial for AT commands (to the module)
  35. // Use Hardware Serial on Mega, Leonardo, Micro
  36. #define SerialAT Serial1
  37. // or Software Serial on Uno, Nano
  38. //#include <SoftwareSerial.h>
  39. //SoftwareSerial SerialAT(2, 3); // RX, TX
  40. #include <StreamDebugger.h>
  41. StreamDebugger debugger(SerialAT, SerialMon);
  42. TinyGsm modem(debugger);
  43. const char server[] = "vsh.pp.ua";
  44. const char resource[] = "/TinyGSM/logo.txt";
  45. const int port = 80;
  46. TinyGsmClient client(modem);
  47. // For SSL:
  48. //const int port = 443;
  49. //TinyGsmClientSecure client(modem);
  50. void setup() {
  51. // Set console baud rate
  52. SerialMon.begin(115200);
  53. delay(10);
  54. // Set GSM module baud rate
  55. SerialAT.begin(115200);
  56. delay(3000);
  57. }
  58. void loop() {
  59. // Restart takes quite some time
  60. // To skip it, call init() instead of restart()
  61. SerialMon.print("Initializing modem...");
  62. if (!modem.restart()) {
  63. SerialMon.println(F(" [fail]"));
  64. SerialMon.println(F("************************"));
  65. SerialMon.println(F(" Is your modem connected properly?"));
  66. SerialMon.println(F(" Is your serial speed (baud rate) correct?"));
  67. SerialMon.println(F(" Is your modem powered on?"));
  68. SerialMon.println(F(" Do you use a good, stable power source?"));
  69. SerialMon.println(F(" Try useing File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration"));
  70. SerialMon.println(F("************************"));
  71. delay(10000);
  72. return;
  73. }
  74. SerialMon.println(F(" [OK]"));
  75. String modemInfo = modem.getModemInfo();
  76. SerialMon.print("Modem: ");
  77. SerialMon.println(modemInfo);
  78. // Unlock your SIM card with a PIN
  79. //modem.simUnlock("1234");
  80. SerialMon.print("Waiting for network...");
  81. if (!modem.waitForNetwork()) {
  82. SerialMon.println(F(" [fail]"));
  83. SerialMon.println(F("************************"));
  84. SerialMon.println(F(" Is your sim card locked?"));
  85. SerialMon.println(F(" Do you have a good signal?"));
  86. SerialMon.println(F(" Is antenna attached?"));
  87. SerialMon.println(F(" Does the SIM card work with your phone?"));
  88. SerialMon.println(F("************************"));
  89. delay(10000);
  90. return;
  91. }
  92. SerialMon.println(F(" [OK]"));
  93. SerialMon.print("Connecting to ");
  94. SerialMon.print(apn);
  95. if (!modem.gprsConnect(apn, user, pass)) {
  96. SerialMon.println(F(" [fail]"));
  97. SerialMon.println(F("************************"));
  98. SerialMon.println(F(" Is GPRS enabled by network provider?"));
  99. SerialMon.println(F(" Try checking your card balance."));
  100. SerialMon.println(F("************************"));
  101. delay(10000);
  102. return;
  103. }
  104. SerialMon.println(F(" [OK]"));
  105. IPAddress local = modem.localIP();
  106. SerialMon.print("Local IP: ");
  107. SerialMon.println(local);
  108. SerialMon.print(F("Connecting to "));
  109. SerialMon.print(server);
  110. if (!client.connect(server, port)) {
  111. SerialMon.println(F(" [fail]"));
  112. delay(10000);
  113. return;
  114. }
  115. SerialMon.println(F(" [OK]"));
  116. // Make a HTTP GET request:
  117. client.print(String("GET ") + resource + " HTTP/1.0\r\n");
  118. client.print(String("Host: ") + server + "\r\n");
  119. client.print("Connection: close\r\n\r\n");
  120. // Wait for data to arrive
  121. while (client.connected() && !client.available()) {
  122. delay(100);
  123. SerialMon.print('.');
  124. };
  125. SerialMon.println();
  126. // Skip all headers
  127. client.find("\r\n\r\n");
  128. // Read data
  129. unsigned long timeout = millis();
  130. unsigned long bytesReceived = 0;
  131. while (client.connected() && millis() - timeout < 10000L) {
  132. while (client.available()) {
  133. char c = client.read();
  134. //SerialMon.print(c);
  135. bytesReceived += 1;
  136. timeout = millis();
  137. }
  138. }
  139. client.stop();
  140. SerialMon.println(F("Server disconnected"));
  141. modem.gprsDisconnect();
  142. SerialMon.println(F("GPRS disconnected"));
  143. SerialMon.println();
  144. SerialMon.println(F("************************"));
  145. SerialMon.print (F(" Received: "));
  146. SerialMon.print(bytesReceived);
  147. SerialMon.println(F(" bytes"));
  148. SerialMon.print (F(" Test: "));
  149. SerialMon.println((bytesReceived == 121) ? "PASSED" : "FAILED");
  150. SerialMon.println(F("************************"));
  151. // Do nothing forevermore
  152. while (true) {
  153. delay(1000);
  154. }
  155. }