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.

184 lines
5.1 KiB

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