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.

167 lines
4.1 KiB

  1. /**************************************************************
  2. *
  3. * DO NOT USE THIS - this is just a compilation test!
  4. *
  5. **************************************************************/
  6. #include <TinyGsmClient.h>
  7. TinyGsm modem(Serial);
  8. TinyGsmClient client(modem);
  9. #if defined(TINY_GSM_MODEM_HAS_SSL)
  10. TinyGsmClientSecure client_secure(modem);
  11. #endif
  12. char server[] = "somewhere";
  13. char resource[] = "something";
  14. void setup() {
  15. Serial.begin(115200);
  16. delay(3000);
  17. }
  18. void loop() {
  19. // Test the basic functions
  20. // modem.init();
  21. modem.begin();
  22. modem.setBaud(115200);
  23. modem.testAT();
  24. modem.factoryDefault();
  25. modem.getModemInfo();
  26. modem.getModemName();
  27. modem.maintain();
  28. // Test Power functions
  29. modem.restart();
  30. // modem.sleepEnable(); // Not available for all modems
  31. // modem.radioOff(); // Not available for all modems
  32. modem.poweroff();
  33. // Test the SIM card functions
  34. #if defined(TINY_GSM_MODEM_HAS_GPRS)
  35. modem.getSimCCID();
  36. modem.getIMEI();
  37. modem.getSimStatus();
  38. modem.getOperator();
  39. #endif
  40. // Test the calling functions
  41. #if defined(TINY_GSM_MODEM_HAS_CALLING)
  42. modem.callNumber(String("+380000000000"));
  43. #if not defined(TINY_GSM_MODEM_SEQUANS_MONARCH)
  44. modem.callAnswer();
  45. #endif
  46. modem.callHangup();
  47. #endif
  48. // Test the SMS functions
  49. #if defined(TINY_GSM_MODEM_HAS_SMS)
  50. #if not defined(TINY_GSM_MODEM_XBEE) && not defined(TINY_GSM_MODEM_SARAR4)
  51. modem.sendUSSD("*111#");
  52. #endif
  53. modem.sendSMS(String("+380000000000"), String("Hello from "));
  54. #if not defined(TINY_GSM_MODEM_XBEE) && not defined(TINY_GSM_MODEM_M590) && not defined(TINY_GSM_MODEM_SARAR4)
  55. modem.sendSMS_UTF16("+380000000000", "Hello", 5);
  56. #endif
  57. #endif
  58. // Test the GSM location functions
  59. #if defined(TINY_GSM_MODEM_HAS_GSM_LOCATION)
  60. modem.getGsmLocation();
  61. float glatitude = -9999;
  62. float glongitude = -9999;
  63. modem.getGsmLocation(&glatitude, &glongitude);
  64. #endif
  65. // Test the Network time function
  66. #if defined(TINY_GSM_MODEM_HAS_TIME)
  67. modem.getGSMDateTime(DATE_FULL);
  68. int year3 = 0;
  69. int month3 = 0;
  70. int day3 = 0;
  71. int hour3 = 0;
  72. int min3 = 0;
  73. int sec3 = 0;
  74. float timezone = 0;
  75. modem.getNetworkTime(&year3, &month3, &day3, &hour3, &min3, &sec3, &timezone);
  76. #endif
  77. // Test the GPS functions
  78. #if defined(TINY_GSM_MODEM_HAS_GPS)
  79. modem.enableGPS();
  80. modem.getGPSraw();
  81. float latitude = -9999;
  82. float longitude = -9999;
  83. modem.getGPS(&latitude, &longitude);
  84. #endif
  85. // Test Battery functions
  86. #if defined(TINY_GSM_MODEM_HAS_BATTERY)
  87. uint8_t chargeState = 0;
  88. int8_t chargePercent = 0;
  89. uint16_t milliVolts = 0;
  90. modem.getBattStats(chargeState, chargePercent, milliVolts);
  91. #endif
  92. // Test the temperature function
  93. #if defined(TINY_GSM_MODEM_HAS_TEMPERATURE)
  94. modem.getTemperature();
  95. #endif
  96. // Test the Networking functions
  97. modem.getRegistrationStatus();
  98. modem.getSignalQuality();
  99. modem.localIP();
  100. #if defined(TINY_GSM_MODEM_HAS_GPRS)
  101. modem.waitForNetwork();
  102. modem.gprsConnect("YourAPN", "", "");
  103. #endif
  104. #if defined(TINY_GSM_MODEM_HAS_WIFI)
  105. modem.networkConnect("YourSSID", "YourWiFiPass");
  106. modem.waitForNetwork();
  107. #endif
  108. client.connect(server, 80);
  109. // Make a HTTP GET request:
  110. client.print(String("GET ") + resource + " HTTP/1.0\r\n");
  111. client.print(String("Host: ") + server + "\r\n");
  112. client.print("Connection: close\r\n\r\n");
  113. uint32_t timeout = millis();
  114. while (client.connected() && millis() - timeout < 10000L) {
  115. while (client.available()) {
  116. client.read();
  117. timeout = millis();
  118. }
  119. }
  120. client.stop();
  121. #if defined(TINY_GSM_MODEM_HAS_SSL)
  122. client_secure.connect(server, 443);
  123. // Make a HTTP GET request:
  124. client_secure.print(String("GET ") + resource + " HTTP/1.0\r\n");
  125. client_secure.print(String("Host: ") + server + "\r\n");
  126. client_secure.print("Connection: close\r\n\r\n");
  127. timeout = millis();
  128. while (client_secure.connected() && millis() - timeout < 10000L) {
  129. while (client_secure.available()) {
  130. client_secure.read();
  131. timeout = millis();
  132. }
  133. }
  134. client_secure.stop();
  135. #endif
  136. #if defined(TINY_GSM_MODEM_HAS_GPRS)
  137. modem.gprsDisconnect();
  138. #endif
  139. #if defined(TINY_GSM_MODEM_HAS_WIFI)
  140. modem.networkDisconnect();
  141. #endif
  142. }