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.

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