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.

189 lines
5.3 KiB

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