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.

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