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.

157 lines
4.5 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
8 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. * 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[] = "cdn.rawgit.com";
  41. const char resource[] = "/vshymanskyy/tinygsm/master/extras/logo.txt";
  42. void setup() {
  43. // Set console baud rate
  44. SerialMon.begin(115200);
  45. delay(10);
  46. // Set GSM module baud rate
  47. SerialAT.begin(115200);
  48. delay(3000);
  49. }
  50. void loop() {
  51. // Restart takes quite some time
  52. // To skip it, call init() instead of restart()
  53. SerialMon.print("Initializing modem...");
  54. if (!modem.restart()) {
  55. SerialMon.println(" fail");
  56. SerialMon.println(F("************************"));
  57. SerialMon.println(F(" Is your modem connected properly?"));
  58. SerialMon.println(F(" Is your serial speed (baud rate) correct?"));
  59. SerialMon.println(F(" Is your modem powered on?"));
  60. SerialMon.println(F(" Do you use a good, stable power source?"));
  61. SerialMon.println(F(" Try useing File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration"));
  62. SerialMon.println(F("************************"));
  63. delay(10000);
  64. }
  65. // Unlock your SIM card with a PIN
  66. //modem.simUnlock("1234");
  67. SerialMon.print("Waiting for network...");
  68. if (!modem.waitForNetwork()) {
  69. SerialMon.println(" fail");
  70. SerialMon.println(F("************************"));
  71. SerialMon.println(F(" Is your sim card locked?"));
  72. SerialMon.println(F(" Do you have a good signal?"));
  73. SerialMon.println(F(" Is antenna attached?"));
  74. SerialMon.println(F(" Does the SIM card work with your phone?"));
  75. SerialMon.println(F("************************"));
  76. delay(10000);
  77. return;
  78. }
  79. SerialMon.println(" OK");
  80. SerialMon.print("Connecting to ");
  81. SerialMon.print(apn);
  82. if (!modem.gprsConnect(apn, user, pass)) {
  83. SerialMon.println(" fail");
  84. SerialMon.println(F("************************"));
  85. SerialMon.println(F(" Is GPRS enabled by network provider?"));
  86. SerialMon.println(F(" Try checking your card balance."));
  87. SerialMon.println(F("************************"));
  88. delay(10000);
  89. return;
  90. }
  91. SerialMon.println(" OK");
  92. SerialMon.print("Connecting to ");
  93. SerialMon.print(server);
  94. if (!client.connect(server, 80)) {
  95. SerialMon.println(" fail");
  96. delay(10000);
  97. return;
  98. }
  99. SerialMon.println(" OK");
  100. // Make a HTTP GET request:
  101. client.print(String("GET ") + resource + " HTTP/1.0\r\n");
  102. client.print(String("Host: ") + server + "\r\n");
  103. client.print("Connection: close\r\n\r\n");
  104. // Skip all headers
  105. client.find("\r\n\r\n");
  106. // Read data
  107. unsigned long timeout = millis();
  108. unsigned long bytesReceived = 0;
  109. while (client.connected() && millis() - timeout < 10000L) {
  110. while (client.available()) {
  111. char c = client.read();
  112. //SerialMon.print(c);
  113. bytesReceived += 1;
  114. timeout = millis();
  115. }
  116. }
  117. client.stop();
  118. SerialMon.println("Server disconnected");
  119. modem.gprsDisconnect();
  120. SerialMon.println("GPRS disconnected");
  121. SerialMon.println();
  122. SerialMon.println("************************");
  123. SerialMon.print (" Received: ");
  124. SerialMon.print(bytesReceived);
  125. SerialMon.println(" bytes");
  126. SerialMon.print (" Test: ");
  127. SerialMon.println((bytesReceived == 121) ? "PASSED" : "FAILED");
  128. SerialMon.println("************************");
  129. // Do nothing forevermore
  130. while (true) {
  131. delay(1000);
  132. }
  133. }