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.

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