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.

127 lines
2.9 KiB

  1. /**************************************************************
  2. *
  3. * This sketch connects to a website and downloads a page.
  4. * It can be used to perform HTTP/RESTful API calls.
  5. *
  6. * TinyGSM Getting Started guide:
  7. * http://tiny.cc/tiny-gsm-readme
  8. *
  9. **************************************************************/
  10. // Hologram Dash uses UBLOX U2 modems
  11. #define TINY_GSM_MODEM_UBLOX
  12. // Increase RX buffer if needed
  13. //#define TINY_GSM_RX_BUFFER 512
  14. #include <TinyGsmClient.h>
  15. // Uncomment this if you want to see all AT commands
  16. //#define DUMP_AT_COMMANDS
  17. // Set serial for debug console (to the Serial Monitor, speed 115200)
  18. #define SerialMon Serial
  19. // We'll be using SerialSystem in Passthrough mode
  20. #define SerialAT SerialSystem
  21. // Your GPRS credentials
  22. // Leave empty, if missing user or pass
  23. const char apn[] = "YourAPN";
  24. const char user[] = "";
  25. const char pass[] = "";
  26. // Server details
  27. const char server[] = "vsh.pp.ua";
  28. const char resource[] = "/TinyGSM/logo.txt";
  29. const int port = 80;
  30. #ifdef DUMP_AT_COMMANDS
  31. #include <StreamDebugger.h>
  32. StreamDebugger debugger(SerialAT, SerialMon);
  33. TinyGsm mdm(debugger);
  34. #else
  35. TinyGsm mdm(SerialAT);
  36. #endif
  37. TinyGsmClient client(mdm);
  38. void setup() {
  39. // Set console baud rate
  40. SerialMon.begin(115200);
  41. delay(10);
  42. // Set up Passthrough
  43. HologramCloud.enterPassthrough();
  44. delay(3000);
  45. // Restart takes quite some time
  46. // To skip it, call init() instead of restart()
  47. SerialMon.println(F("Initializing modem..."));
  48. mdm.restart();
  49. String modemInfo = mdm.getModemInfo();
  50. SerialMon.print(F("Modem: "));
  51. SerialMon.println(modemInfo);
  52. // Unlock your SIM card with a PIN
  53. //mdm.simUnlock("1234");
  54. }
  55. void loop() {
  56. SerialMon.print(F("Waiting for network..."));
  57. if (!mdm.waitForNetwork()) {
  58. SerialMon.println(" fail");
  59. delay(10000);
  60. return;
  61. }
  62. SerialMon.println(" OK");
  63. SerialMon.print(F("Connecting to "));
  64. SerialMon.print(apn);
  65. if (!mdm.gprsConnect(apn, user, pass)) {
  66. SerialMon.println(" fail");
  67. delay(10000);
  68. return;
  69. }
  70. SerialMon.println(" OK");
  71. SerialMon.print(F("Connecting to "));
  72. SerialMon.print(server);
  73. if (!client.connect(server, port)) {
  74. SerialMon.println(" fail");
  75. delay(10000);
  76. return;
  77. }
  78. SerialMon.println(" OK");
  79. // Make a HTTP GET request:
  80. client.print(String("GET ") + resource + " HTTP/1.0\r\n");
  81. client.print(String("Host: ") + server + "\r\n");
  82. client.print("Connection: close\r\n\r\n");
  83. unsigned long timeout = millis();
  84. while (client.connected() && millis() - timeout < 10000L) {
  85. // Print available data
  86. while (client.available()) {
  87. char c = client.read();
  88. SerialMon.print(c);
  89. timeout = millis();
  90. }
  91. }
  92. SerialMon.println();
  93. // Shutdown
  94. client.stop();
  95. SerialMon.println(F("Server disconnected"));
  96. mdm.gprsDisconnect();
  97. SerialMon.println(F("GPRS disconnected"));
  98. // Do nothing forevermore
  99. while (true) {
  100. delay(1000);
  101. }
  102. }