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.

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