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.

213 lines
5.4 KiB

  1. /**************************************************************
  2. *
  3. * DO NOT USE THIS - this is just a compilation test!
  4. * This is NOT an example for use of this library!
  5. *
  6. **************************************************************/
  7. #include <TinyGsmClient.h>
  8. TinyGsm modem(Serial);
  9. void setup() {
  10. Serial.begin(115200);
  11. delay(3000);
  12. }
  13. void loop() {
  14. // Test the basic functions
  15. modem.begin();
  16. modem.begin("1234");
  17. modem.init();
  18. modem.init("1234");
  19. modem.setBaud(115200);
  20. modem.testAT();
  21. modem.getModemInfo();
  22. modem.getModemName();
  23. modem.factoryDefault();
  24. // Test Power functions
  25. modem.restart();
  26. // modem.sleepEnable(); // Not available for all modems
  27. // modem.radioOff(); // Not available for all modems
  28. modem.poweroff();
  29. // Test generic network functions
  30. modem.getRegistrationStatus();
  31. modem.isNetworkConnected();
  32. modem.waitForNetwork();
  33. modem.waitForNetwork(15000L);
  34. modem.getSignalQuality();
  35. modem.getLocalIP();
  36. modem.localIP();
  37. // Test the GPRS and SIM card functions
  38. #if defined(TINY_GSM_MODEM_HAS_GPRS)
  39. modem.simUnlock();
  40. modem.simUnlock("1234");
  41. modem.getSimCCID();
  42. modem.getIMEI();
  43. modem.getIMSI();
  44. modem.getSimStatus();
  45. modem.gprsConnect("myAPN");
  46. modem.gprsConnect("myAPN", "myUser");
  47. modem.gprsConnect("myAPN", "myAPNUser", "myAPNPass");
  48. modem.gprsDisconnect();
  49. modem.getOperator();
  50. #endif
  51. // Test WiFi Functions
  52. #if defined(TINY_GSM_MODEM_HAS_WIFI)
  53. modem.networkConnect("mySSID", "mySSIDPassword");
  54. modem.networkDisconnect();
  55. #endif
  56. // Test TCP functions
  57. modem.maintain();
  58. TinyGsmClient client;
  59. TinyGsmClient client2(modem);
  60. TinyGsmClient client3(modem, 1);
  61. client.init(&modem);
  62. client.init(&modem, 1);
  63. char server[] = "somewhere";
  64. char resource[] = "something";
  65. client.connect(server, 80);
  66. // Make a HTTP GET request:
  67. client.print(String("GET ") + resource + " HTTP/1.0\r\n");
  68. client.print(String("Host: ") + server + "\r\n");
  69. client.print("Connection: close\r\n\r\n");
  70. uint32_t timeout = millis();
  71. while (client.connected() && millis() - timeout < 10000L) {
  72. while (client.available()) {
  73. client.read();
  74. timeout = millis();
  75. }
  76. }
  77. client.stop();
  78. #if defined(TINY_GSM_MODEM_HAS_SSL)
  79. TinyGsmClientSecure client_secure(modem);
  80. TinyGsmClientSecure client2(modem);
  81. TinyGsmClientSecure client3(modem, 1);
  82. client_secure.init(&modem);
  83. client_secure.init(&modem, 1);
  84. client_secure.connect(server, 443);
  85. // Make a HTTP GET request:
  86. client_secure.print(String("GET ") + resource + " HTTP/1.0\r\n");
  87. client_secure.print(String("Host: ") + server + "\r\n");
  88. client_secure.print("Connection: close\r\n\r\n");
  89. timeout = millis();
  90. while (client_secure.connected() && millis() - timeout < 10000L) {
  91. while (client_secure.available()) {
  92. client_secure.read();
  93. timeout = millis();
  94. }
  95. }
  96. client_secure.stop();
  97. #endif
  98. // Test the calling functions
  99. #if defined(TINY_GSM_MODEM_HAS_CALLING)
  100. modem.callNumber(String("+380000000000"));
  101. modem.callHangup();
  102. #if not defined(TINY_GSM_MODEM_SEQUANS_MONARCH)
  103. modem.callAnswer();
  104. modem.dtmfSend('A', 1000);
  105. #endif
  106. #endif
  107. // Test the SMS functions
  108. #if defined(TINY_GSM_MODEM_HAS_SMS)
  109. modem.sendSMS(String("+380000000000"), String("Hello from "));
  110. #if not defined(TINY_GSM_MODEM_XBEE) && not defined(TINY_GSM_MODEM_SARAR4)
  111. modem.sendUSSD("*111#");
  112. #endif
  113. #if not defined(TINY_GSM_MODEM_XBEE) && not defined(TINY_GSM_MODEM_M590) && \
  114. not defined(TINY_GSM_MODEM_SARAR4)
  115. modem.sendSMS_UTF16("+380000000000", "Hello", 5);
  116. #endif
  117. #endif
  118. // Test the GSM location functions
  119. #if defined(TINY_GSM_MODEM_HAS_GSM_LOCATION)
  120. modem.getGsmLocationRaw();
  121. modem.getGsmLocation();
  122. float glatitude = -9999;
  123. float glongitude = -9999;
  124. float gacc = 0;
  125. float gyear = 0;
  126. float gmonth = 0;
  127. float gday = 0;
  128. float ghour = 0;
  129. float gmin = 0;
  130. float gsec = 0;
  131. modem.getGsmLocation(&glatitude, &glongitude);
  132. modem.getGsmLocation(&glatitude, &glongitude, &gacc, &gyear, &gmonth, &gday,
  133. &ghour, &gmin, &gsec);
  134. modem.getGsmLocationTime(&gyear, &gmonth, &gday, &ghour, &gmin, &gsec);
  135. #endif
  136. // Test the GPS functions
  137. #if defined(TINY_GSM_MODEM_HAS_GPS)
  138. modem.enableGPS();
  139. modem.getGPSraw();
  140. float latitude = -9999;
  141. float longitude = -9999;
  142. float speed = 0;
  143. float alt = 0;
  144. int vsat = 0;
  145. int usat = 0;
  146. float acc = 0;
  147. float year = 0;
  148. float month = 0;
  149. float day = 0;
  150. float hour = 0;
  151. float minute = 0;
  152. float second = 0;
  153. modem.getGPS(&latitude, &longitude);
  154. modem.getGPS(&latitude, &longitude, &speed, &alt, &vsat, &usat, &acc, &year,
  155. &month, &day, &hour, &minute, &second);
  156. modem.disableGPS();
  157. #endif
  158. // Test the Network time function
  159. #if defined(TINY_GSM_MODEM_HAS_TIME)
  160. modem.getGSMDateTime(DATE_FULL);
  161. int year3 = 0;
  162. int month3 = 0;
  163. int day3 = 0;
  164. int hour3 = 0;
  165. int min3 = 0;
  166. int sec3 = 0;
  167. float timezone = 0;
  168. modem.getNetworkTime(&year3, &month3, &day3, &hour3, &min3, &sec3, &timezone);
  169. #endif
  170. // Test Battery functions
  171. #if defined(TINY_GSM_MODEM_HAS_BATTERY)
  172. uint8_t chargeState = 0;
  173. int8_t chargePercent = 0;
  174. uint16_t milliVolts = 0;
  175. modem.getBattStats(chargeState, chargePercent, milliVolts);
  176. #endif
  177. // Test the temperature function
  178. #if defined(TINY_GSM_MODEM_HAS_TEMPERATURE)
  179. modem.getTemperature();
  180. #endif
  181. }