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.

113 lines
2.7 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
  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. char apn[] = "YourAPN";
  14. char user[] = "";
  15. char pass[] = "";
  16. // Set serial for debug console (to the Serial Monitor, speed 115200)
  17. #define SerialMon Serial
  18. // Set serial for AT commands (to the module)
  19. // Use Hardware Serial on Mega, Leonardo, Micro
  20. #define SerialAT Serial1
  21. // or Software Serial on Uno, Nano
  22. //#include <SoftwareSerial.h>
  23. //SoftwareSerial SerialAT(2, 3); // RX, TX
  24. #include <StreamDebugger.h>
  25. StreamDebugger debugger(SerialAT, SerialMon);
  26. #include <TinyGsmClient.h>
  27. TinyGsm modem(debugger);
  28. TinyGsmClient client(modem);
  29. char server[] = "cdn.rawgit.com";
  30. char resource[] = "/vshymanskyy/tinygsm/master/extras/test_simple.txt";
  31. void setup() {
  32. // Set console baud rate
  33. SerialMon.begin(115200);
  34. delay(10);
  35. // Set GSM module baud rate
  36. SerialAT.begin(115200);
  37. delay(3000);
  38. // Restart takes quite some time
  39. // To skip it, call init() instead of restart()
  40. modem.restart();
  41. // Unlock your SIM card with a PIN
  42. //modem.simUnlock("1234");
  43. SerialMon.println("Waiting for network... ");
  44. if (modem.waitForNetwork()) {
  45. SerialMon.println("OK");
  46. } else {
  47. SerialMon.println("fail");
  48. }
  49. }
  50. void loop() {
  51. if (!modem.gprsConnect(apn, user, pass)) {
  52. delay(10000);
  53. return;
  54. }
  55. if (!client.connect(server, 80)) {
  56. delay(10000);
  57. return;
  58. }
  59. // Make a HTTP GET request:
  60. client.print(String("GET ") + resource + " HTTP/1.0\r\n");
  61. client.print(String("Host: ") + server + "\r\n");
  62. client.print("Connection: close\r\n\r\n");
  63. // Skip all headers
  64. client.find("\r\n\r\n");
  65. // Read data
  66. unsigned long timeout = millis();
  67. unsigned long bytesReceived = 0;
  68. while (client.connected() && millis() - timeout < 10000L) {
  69. while (client.available()) {
  70. char c = client.read();
  71. //SerialMon.print(c);
  72. bytesReceived += 1;
  73. timeout = millis();
  74. }
  75. }
  76. client.stop();
  77. modem.gprsDisconnect();
  78. SerialMon.println();
  79. SerialMon.println("************************");
  80. SerialMon.print (" Received: ");
  81. SerialMon.print(bytesReceived);
  82. SerialMon.println("bytes");
  83. SerialMon.print (" Test: ");
  84. SerialMon.println((bytesReceived == 1000) ? "PASSED" : "FAIL");
  85. SerialMon.println("************************");
  86. // Do nothing forevermore
  87. while (true) {
  88. delay(1000);
  89. }
  90. }