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.

220 lines
5.8 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(6000);
  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.waitForNetwork(15000L, true);
  35. modem.getSignalQuality();
  36. modem.getLocalIP();
  37. modem.localIP();
  38. // Test the GPRS and SIM card functions
  39. #if defined(TINY_GSM_MODEM_HAS_GPRS)
  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. // modem.addCertificate(); // not yet impemented
  80. // modem.deleteCertificate(); // not yet impemented
  81. TinyGsmClientSecure client_secure(modem);
  82. TinyGsmClientSecure client_secure2(modem);
  83. TinyGsmClientSecure client_secure3(modem, 1);
  84. client_secure.init(&modem);
  85. client_secure.init(&modem, 1);
  86. client_secure.connect(server, 443);
  87. // Make a HTTP GET request:
  88. client_secure.print(String("GET ") + resource + " HTTP/1.0\r\n");
  89. client_secure.print(String("Host: ") + server + "\r\n");
  90. client_secure.print("Connection: close\r\n\r\n");
  91. timeout = millis();
  92. while (client_secure.connected() && millis() - timeout < 10000L) {
  93. while (client_secure.available()) {
  94. client_secure.read();
  95. timeout = millis();
  96. }
  97. }
  98. client_secure.stop();
  99. #endif
  100. // Test the calling functions
  101. #if defined(TINY_GSM_MODEM_HAS_CALLING) && not defined(__AVR_ATmega32U4__)
  102. modem.callNumber(String("+380000000000"));
  103. modem.callHangup();
  104. #if not defined(TINY_GSM_MODEM_SEQUANS_MONARCH)
  105. modem.callAnswer();
  106. modem.dtmfSend('A', 1000);
  107. #endif
  108. #endif
  109. // Test the SMS functions
  110. #if defined(TINY_GSM_MODEM_HAS_SMS) && not defined(__AVR_ATmega32U4__)
  111. modem.sendSMS(String("+380000000000"), String("Hello from "));
  112. #if not defined(TINY_GSM_MODEM_XBEE) && not defined(TINY_GSM_MODEM_SARAR4)
  113. modem.sendUSSD("*111#");
  114. #endif
  115. #if not defined(TINY_GSM_MODEM_XBEE) && not defined(TINY_GSM_MODEM_M590) && \
  116. not defined(TINY_GSM_MODEM_SARAR4)
  117. modem.sendSMS_UTF16("+380000000000", "Hello", 5);
  118. #endif
  119. #endif
  120. // Test the GSM location functions
  121. #if defined(TINY_GSM_MODEM_HAS_GSM_LOCATION) && not defined(__AVR_ATmega32U4__)
  122. modem.getGsmLocationRaw();
  123. modem.getGsmLocation();
  124. float glatitude = -9999;
  125. float glongitude = -9999;
  126. float gacc = 0;
  127. int gyear = 0;
  128. int gmonth = 0;
  129. int gday = 0;
  130. int ghour = 0;
  131. int gmin = 0;
  132. int gsec = 0;
  133. modem.getGsmLocation(&glatitude, &glongitude);
  134. modem.getGsmLocation(&glatitude, &glongitude, &gacc, &gyear, &gmonth, &gday,
  135. &ghour, &gmin, &gsec);
  136. modem.getGsmLocationTime(&gyear, &gmonth, &gday, &ghour, &gmin, &gsec);
  137. #endif
  138. // Test the GPS functions
  139. #if defined(TINY_GSM_MODEM_HAS_GPS) && not defined(__AVR_ATmega32U4__)
  140. modem.enableGPS();
  141. modem.getGPSraw();
  142. float latitude = -9999;
  143. float longitude = -9999;
  144. float speed = 0;
  145. float alt = 0;
  146. int vsat = 0;
  147. int usat = 0;
  148. float acc = 0;
  149. int year = 0;
  150. int month = 0;
  151. int day = 0;
  152. int hour = 0;
  153. int minute = 0;
  154. int second = 0;
  155. modem.getGPS(&latitude, &longitude);
  156. modem.getGPS(&latitude, &longitude, &speed, &alt, &vsat, &usat, &acc, &year,
  157. &month, &day, &hour, &minute, &second);
  158. modem.disableGPS();
  159. #endif
  160. // Test the Network time function
  161. #if defined(TINY_GSM_MODEM_HAS_NTP) && not defined(__AVR_ATmega32U4__)
  162. modem.NTPServerSync("pool.ntp.org", 3);
  163. #endif
  164. // Test the Network time function
  165. #if defined(TINY_GSM_MODEM_HAS_TIME) && not defined(__AVR_ATmega32U4__)
  166. modem.getGSMDateTime(DATE_FULL);
  167. int year3 = 0;
  168. int month3 = 0;
  169. int day3 = 0;
  170. int hour3 = 0;
  171. int min3 = 0;
  172. int sec3 = 0;
  173. float timezone = 0;
  174. modem.getNetworkTime(&year3, &month3, &day3, &hour3, &min3, &sec3, &timezone);
  175. #endif
  176. // Test Battery functions
  177. #if defined(TINY_GSM_MODEM_HAS_BATTERY)
  178. uint8_t chargeState = 0;
  179. int8_t chargePercent = 0;
  180. uint16_t milliVolts = 0;
  181. modem.getBattStats(chargeState, chargePercent, milliVolts);
  182. #endif
  183. // Test the temperature function
  184. #if defined(TINY_GSM_MODEM_HAS_TEMPERATURE)
  185. modem.getTemperature();
  186. #endif
  187. }