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.

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