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.

93 lines
2.1 KiB

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