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.

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