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.

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