mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	Make examples "wifi-ready"
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -14,8 +14,7 @@ | ||||
| .cproject | ||||
| .project | ||||
| .settings | ||||
| .pioenvs | ||||
| .piolibdeps | ||||
| .pio/* | ||||
| .clang_complete | ||||
| .gcc-flags.json | ||||
| platformio.ini | ||||
|   | ||||
| @@ -28,6 +28,16 @@ | ||||
| // #define TINY_GSM_MODEM_XBEE | ||||
| // #define TINY_GSM_MODEM_SEQUANS_MONARCH | ||||
|  | ||||
| // See all AT commands, if wanted | ||||
| // #define DUMP_AT_COMMANDS | ||||
|  | ||||
| // See the debugging, if wanted | ||||
| #define TINY_GSM_DEBUG SerialMon | ||||
|  | ||||
| // Range to attempt to autobaud | ||||
| #define GSM_AUTOBAUD_MIN 9600 | ||||
| #define GSM_AUTOBAUD_MAX 38400 | ||||
|  | ||||
| // Set serial for debug console (to the Serial Monitor, default speed 115200) | ||||
| #define SerialMon Serial | ||||
|  | ||||
| @@ -39,24 +49,15 @@ | ||||
| //#include <SoftwareSerial.h> | ||||
| //SoftwareSerial SerialAT(2, 3); // RX, TX | ||||
|  | ||||
| // See all AT commands, if wanted | ||||
| //#define DUMP_AT_COMMANDS | ||||
|  | ||||
| // See the debugging, if wanted | ||||
| #define TINY_GSM_DEBUG SerialMon | ||||
|  | ||||
| // Range to attempt to autobaud | ||||
| #define GSM_AUTOBAUD_MIN 9600 | ||||
| #define GSM_AUTOBAUD_MAX 38400 | ||||
|  | ||||
| /* | ||||
|  * Test enabled | ||||
|  */ | ||||
| #define TINY_GSM_USE_GPRS true | ||||
| #define TINY_GSM_USE_WIFI false | ||||
| #define TINY_GSM_USE_CALL true | ||||
| #define TINY_GSM_USE_SMS true | ||||
| #define TINY_GSM_USE_USSD true | ||||
| #define TINY_GSM_TEST_GPRS true | ||||
| #define TINY_GSM_TEST_WIFI false | ||||
| #define TINY_GSM_TEST_CALL true | ||||
| #define TINY_GSM_TEST_SMS true | ||||
| #define TINY_GSM_TEST_USSD true | ||||
| #define TINY_GSM_TEST_BATTERY true | ||||
| // powerdown modem after tests | ||||
| #define TINY_GSM_POWERDOWN false | ||||
|  | ||||
| @@ -69,11 +70,8 @@ | ||||
|  | ||||
| // Your GPRS credentials | ||||
| // Leave empty, if missing user or pass | ||||
| const char apn[]  = "YourAPN"; | ||||
| const char user[] = ""; | ||||
| const char pass[] = ""; | ||||
| const char wifiSSID[]  = "YourSSID"; | ||||
| const char wifiPass[] = "SSIDpw"; | ||||
| const char gprsUser[] = ""; | ||||
| const char gprsPass[] = ""; | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
|  | ||||
| @@ -98,11 +96,9 @@ void setup() { | ||||
|   digitalWrite(23, HIGH); | ||||
|  | ||||
|   DBG("Wait..."); | ||||
|   delay(3000); | ||||
|  | ||||
|   // Set GSM module baud rate | ||||
|   TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX); | ||||
|   // SerialAT.begin(9600); | ||||
|   delay(3000); | ||||
| } | ||||
|  | ||||
| void loop() { | ||||
| @@ -120,26 +116,34 @@ void loop() { | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   String modemInfo = modem.getModemInfo(); | ||||
|   DBG("Modem:", modemInfo); | ||||
|   String name = modem.getModemName(); | ||||
|   DBG("Modem Name:", name); | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS | ||||
|   String modemInfo = modem.getModemInfo(); | ||||
|   DBG("Modem Info:", modemInfo); | ||||
|  | ||||
| #if TINY_GSM_TEST_GPRS | ||||
|   // Unlock your SIM card with a PIN if needed | ||||
|   if ( GSM_PIN && modem.getSimStatus() != 3 ) { | ||||
|     modem.simUnlock(GSM_PIN); | ||||
|   } | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_WIFI | ||||
|   SerialMon.print(F("Setting SSID/password...")); | ||||
| #if TINY_GSM_TEST_WIFI | ||||
|   DBG("Setting SSID/password..."); | ||||
|   if (!modem.networkConnect(wifiSSID, wifiPass)) { | ||||
|     SerialMon.println(" fail"); | ||||
|     DBG(" fail"); | ||||
|     delay(10000); | ||||
|     return; | ||||
|   } | ||||
|   SerialMon.println(" OK"); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_TEST_GPRS && defined TINY_GSM_MODEM_XBEE | ||||
|   // The XBee must run the gprsConnect function BEFORE waiting for network! | ||||
|   modem.gprsConnect(apn, gprsUser, gprsPass); | ||||
| #endif | ||||
|  | ||||
|   DBG("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork()) { | ||||
|     delay(10000); | ||||
| @@ -150,9 +154,9 @@ void loop() { | ||||
|     DBG("Network connected"); | ||||
|   } | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS | ||||
| #if TINY_GSM_TEST_GPRS | ||||
|   DBG("Connecting to", apn); | ||||
|   if (!modem.gprsConnect(apn, user, pass)) { | ||||
|   if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { | ||||
|     delay(10000); | ||||
|     return; | ||||
|   } | ||||
| @@ -175,17 +179,9 @@ void loop() { | ||||
|   int csq = modem.getSignalQuality(); | ||||
|   DBG("Signal quality:", csq); | ||||
|  | ||||
|   // This is NOT supported on M590 | ||||
|   int battLevel = modem.getBattPercent(); | ||||
|   DBG("Battery lavel:", battLevel); | ||||
|  | ||||
|   // This is only supported on SIMxxx series | ||||
|   float battVoltage = modem.getBattVoltage() / 1000.0F; | ||||
|   DBG("Battery voltage:", battVoltage); | ||||
|  | ||||
|   // This is only supported on SIMxxx series | ||||
|   String gsmLoc = modem.getGsmLocation(); | ||||
|   DBG("GSM location:", gsmLoc); | ||||
|   // String gsmLoc = modem.getGsmLocation(); | ||||
|   // DBG("GSM location:", gsmLoc); | ||||
|  | ||||
|   // This is only supported on SIMxxx series | ||||
|   // String gsmTime = modem.getGSMDateTime(DATE_TIME); | ||||
| @@ -207,7 +203,7 @@ void loop() { | ||||
|   DBG("GPS raw data:", gps_raw); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_SMS && defined(SMS_TARGET) | ||||
| #if TINY_GSM_TEST_SMS && defined(SMS_TARGET) | ||||
|   res = modem.sendSMS(SMS_TARGET, String("Hello from ") + imei); | ||||
|   DBG("SMS:", res ? "OK" : "fail"); | ||||
|  | ||||
| @@ -216,7 +212,7 @@ void loop() { | ||||
|   DBG("UTF16 SMS:", res ? "OK" : "fail"); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_CALL && defined(CALL_TARGET) | ||||
| #if TINY_GSM_TEST_CALL && defined(CALL_TARGET) | ||||
|   DBG("Calling:", CALL_TARGET); | ||||
|  | ||||
|   // This is NOT supported on M590 | ||||
| @@ -241,7 +237,20 @@ void loop() { | ||||
|   } | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS | ||||
| #if TINY_GSM_TEST_BATTERY | ||||
|   uint8_t chargeState = -99; | ||||
|   int8_t percent = -99; | ||||
|   uint16_t milliVolts = -9999; | ||||
|   modem.getBattStats(chargeState, percent, milliVolts) | ||||
|   DBG("Battery charge state:", chargeState); | ||||
|   DBG("Battery charge 'percent':", percent); | ||||
|   DBG("Battery voltage:", milliVolts / 1000.0F); | ||||
|  | ||||
|   float temp = modem.getTemperature(); | ||||
|   DBG("Chip temperature:", temp); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_TEST_GPRS | ||||
|   modem.gprsDisconnect(); | ||||
|   if (!modem.isGprsConnected()) { | ||||
|     DBG("GPRS disconnected"); | ||||
| @@ -250,7 +259,7 @@ void loop() { | ||||
|   } | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_WIFI | ||||
| #if TINY_GSM_TEST_WIFI | ||||
|   modem.networkDisconnect(); | ||||
|   DBG("WiFi disconnected"); | ||||
| #endif | ||||
|   | ||||
| @@ -48,7 +48,7 @@ | ||||
| // #define TINY_GSM_MODEM_SEQUANS_MONARCH | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <BlynkSimpleSIM800.h> | ||||
| #include <BlynkSimpleTinyGSM.h> | ||||
|  | ||||
| // Set serial for debug console (to the Serial Monitor, default speed 115200) | ||||
| #define SerialMon Serial | ||||
|   | ||||
| @@ -12,9 +12,10 @@ | ||||
|  * | ||||
|  * For more HTTP API examples, see ArduinoHttpClient library | ||||
|  * | ||||
|  * NOTE: This example does NOT work with the XBee because the | ||||
|  * NOTE: This example may NOT work with the XBee because the | ||||
|  * HttpClient library does not empty to serial buffer fast enough | ||||
|  * and the buffer overflow causes the HttpClient library to stall. | ||||
|  * Boards with faster processors may work, 8MHz boards will not. | ||||
|  **************************************************************/ | ||||
|  | ||||
| // Select your modem: | ||||
| @@ -47,14 +48,11 @@ | ||||
|  | ||||
| // See the debugging, if wanted | ||||
| //#define TINY_GSM_DEBUG Serial | ||||
| //#define LOGGING | ||||
| //#define LOGGING  // <- Logging is for the HTTP library | ||||
|  | ||||
| // Add a reception delay, if needed | ||||
| //#define TINY_GSM_YIELD() { delay(1); } | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <ArduinoHttpClient.h> | ||||
|  | ||||
| // Set serial for debug console (to the Serial Monitor, default speed 115200) | ||||
| #define SerialMon Serial | ||||
|  | ||||
| @@ -85,6 +83,9 @@ const char server[] = "vsh.pp.ua"; | ||||
| const char resource[] = "/TinyGSM/logo.txt"; | ||||
| const int  port = 80; | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <ArduinoHttpClient.h> | ||||
|  | ||||
| #ifdef DUMP_AT_COMMANDS | ||||
|   #include <StreamDebugger.h> | ||||
|   StreamDebugger debugger(SerialAT, SerialMon); | ||||
| @@ -118,6 +119,7 @@ void setup() { | ||||
|   // To skip it, call init() instead of restart() | ||||
|   SerialMon.println("Initializing modem..."); | ||||
|   modem.restart(); | ||||
|   // modem.init(); | ||||
|  | ||||
|   String modemInfo = modem.getModemInfo(); | ||||
|   SerialMon.print("Modem: "); | ||||
| @@ -129,7 +131,7 @@ void setup() { | ||||
|  | ||||
| void loop() { | ||||
|  | ||||
| #if TINY_GSM_USE_WIFI | ||||
| #if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI | ||||
|   SerialMon.print(F("Setting SSID/password...")); | ||||
|   if (!modem.networkConnect(wifiSSID, wifiPass)) { | ||||
|     SerialMon.println(" fail"); | ||||
| @@ -139,6 +141,11 @@ void loop() { | ||||
|   SerialMon.println(" OK"); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE | ||||
|   // The XBee must run the gprsConnect function BEFORE waiting for network! | ||||
|   modem.gprsConnect(apn, gprsUser, gprsPass); | ||||
| #endif | ||||
|  | ||||
|   SerialMon.print("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork()) { | ||||
|     SerialMon.println(" fail"); | ||||
| @@ -148,10 +155,10 @@ void loop() { | ||||
|   SerialMon.println(" OK"); | ||||
|  | ||||
|   if (modem.isNetworkConnected()) { | ||||
|     SerialMon.print("Network connected"); | ||||
|     SerialMon.println("Network connected"); | ||||
|   } | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS | ||||
|     SerialMon.print(F("Connecting to ")); | ||||
|     SerialMon.print(apn); | ||||
|     if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { | ||||
|   | ||||
| @@ -10,19 +10,27 @@ | ||||
|  * TinyGSM Getting Started guide: | ||||
|  *   https://tiny.cc/tinygsm-readme | ||||
|  * | ||||
|  * SSL/TLS is currently supported only with: SIM8xx, uBlox, ESP8266 | ||||
|  * SSL/TLS is not yet supported on the Quectel modems | ||||
|  * The A6/A7/A20 and M590 are not capable of SSL/TLS | ||||
|  * | ||||
|  * For more HTTP API examples, see ArduinoHttpClient library | ||||
|  * | ||||
|  * NOTE: This example may NOT work with the XBee because the | ||||
|  * HttpClient library does not empty to serial buffer fast enough | ||||
|  * and the buffer overflow causes the HttpClient library to stall. | ||||
|  * Boards with faster processors may work, 8MHz boards will not. | ||||
|  **************************************************************/ | ||||
|  | ||||
| // Select your modem: | ||||
| #define TINY_GSM_MODEM_SIM800 | ||||
| // #define TINY_GSM_MODEM_SIM808 | ||||
| // #define TINY_GSM_MODEM_SIM868 | ||||
| // #define TINY_GSM_MODEM_SIM7000 | ||||
| // #define TINY_GSM_MODEM_UBLOX | ||||
| // #define TINY_GSM_MODEM_SARAR4 | ||||
| // #define TINY_GSM_MODEM_ESP8266 | ||||
| // #define TINY_GSM_MODEM_XBEE | ||||
| // #define TINY_GSM_MODEM_SEQUANS_MONARCH | ||||
|  | ||||
| // Increase RX buffer to capture the entire response | ||||
| // Chips without internal buffering (ESP8266) | ||||
| @@ -35,14 +43,11 @@ | ||||
|  | ||||
| // See the debugging, if wanted | ||||
| //#define TINY_GSM_DEBUG Serial | ||||
| //#define LOGGING | ||||
| //#define LOGGING  // <- Logging is for the HTTP library | ||||
|  | ||||
| // Add a reception delay, if needed | ||||
| //#define TINY_GSM_YIELD() { delay(1); } | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <ArduinoHttpClient.h> | ||||
|  | ||||
| // Set serial for debug console (to the Serial Monitor, default speed 115200) | ||||
| #define SerialMon Serial | ||||
|  | ||||
| @@ -73,6 +78,9 @@ const char server[] = "vsh.pp.ua"; | ||||
| const char resource[] = "/TinyGSM/logo.txt"; | ||||
| const int  port = 443; | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <ArduinoHttpClient.h> | ||||
|  | ||||
| #ifdef DUMP_AT_COMMANDS | ||||
|   #include <StreamDebugger.h> | ||||
|   StreamDebugger debugger(SerialAT, SerialMon); | ||||
| @@ -106,6 +114,7 @@ void setup() { | ||||
|   // To skip it, call init() instead of restart() | ||||
|   SerialMon.println("Initializing modem..."); | ||||
|   modem.restart(); | ||||
|   // modem.init(); | ||||
|  | ||||
|   String modemInfo = modem.getModemInfo(); | ||||
|   SerialMon.print("Modem: "); | ||||
| @@ -122,7 +131,7 @@ void setup() { | ||||
|  | ||||
| void loop() { | ||||
|  | ||||
| #if TINY_GSM_USE_WIFI | ||||
| #if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI | ||||
|   SerialMon.print(F("Setting SSID/password...")); | ||||
|   if (!modem.networkConnect(wifiSSID, wifiPass)) { | ||||
|     SerialMon.println(" fail"); | ||||
| @@ -132,6 +141,11 @@ void loop() { | ||||
|   SerialMon.println(" OK"); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE | ||||
|   // The XBee must run the gprsConnect function BEFORE waiting for network! | ||||
|   modem.gprsConnect(apn, gprsUser, gprsPass); | ||||
| #endif | ||||
|  | ||||
|   SerialMon.print("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork()) { | ||||
|     SerialMon.println(" fail"); | ||||
| @@ -141,10 +155,10 @@ void loop() { | ||||
|   SerialMon.println(" OK"); | ||||
|  | ||||
|   if (modem.isNetworkConnected()) { | ||||
|     SerialMon.print("Network connected"); | ||||
|     SerialMon.println("Network connected"); | ||||
|   } | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS | ||||
|     SerialMon.print(F("Connecting to ")); | ||||
|     SerialMon.print(apn); | ||||
|     if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { | ||||
|   | ||||
| @@ -46,12 +46,23 @@ | ||||
| // #define TINY_GSM_MODEM_XBEE | ||||
| // #define TINY_GSM_MODEM_SEQUANS_MONARCH | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <PubSubClient.h> | ||||
| // See all AT commands, if wanted | ||||
| // #define DUMP_AT_COMMANDS | ||||
|  | ||||
| // See the debugging, if wanted | ||||
| #define TINY_GSM_DEBUG SerialMon | ||||
|  | ||||
| // Range to attempt to autobaud | ||||
| #define GSM_AUTOBAUD_MIN 9600 | ||||
| #define GSM_AUTOBAUD_MAX 38400 | ||||
|  | ||||
| // Add a reception delay, if needed | ||||
| #define TINY_GSM_YIELD() { delay(2); } | ||||
|  | ||||
| // Set serial for debug console (to the Serial Monitor, default speed 115200) | ||||
| #define SerialMon Serial | ||||
|  | ||||
| // Set serial for AT commands (to the module) | ||||
| // Use Hardware Serial on Mega, Leonardo, Micro | ||||
| #define SerialAT Serial1 | ||||
|  | ||||
| @@ -73,7 +84,17 @@ const char* topicLed = "GsmClientTest/led"; | ||||
| const char* topicInit = "GsmClientTest/init"; | ||||
| const char* topicLedStatus = "GsmClientTest/ledStatus"; | ||||
|  | ||||
| #include <TinyGsmClient.h> | ||||
| #include <PubSubClient.h> | ||||
|  | ||||
| #ifdef DUMP_AT_COMMANDS | ||||
|   #include <StreamDebugger.h> | ||||
|   StreamDebugger debugger(SerialAT, SerialMon); | ||||
|   TinyGsm modem(debugger); | ||||
| #else | ||||
|  | ||||
| TinyGsm modem(SerialAT); | ||||
| #endif | ||||
| TinyGsmClient client(modem); | ||||
| PubSubClient mqtt(client); | ||||
|  | ||||
| @@ -83,12 +104,22 @@ int ledStatus = LOW; | ||||
| long lastReconnectAttempt = 0; | ||||
|  | ||||
| void setup() { | ||||
|   pinMode(LED_PIN, OUTPUT); | ||||
|  | ||||
|   // Set console baud rate | ||||
|   SerialMon.begin(115200); | ||||
|   delay(10); | ||||
|  | ||||
|   // Set your reset, enable, power pins here | ||||
|   pinMode(LED_PIN, OUTPUT); | ||||
|  | ||||
|   pinMode(20, OUTPUT); | ||||
|   digitalWrite(20, HIGH); | ||||
|  | ||||
|   pinMode(23, OUTPUT); | ||||
|   digitalWrite(23, LOW); | ||||
|  | ||||
|   SerialMon.println("Wait..."); | ||||
|  | ||||
|   // Set GSM module baud rate | ||||
|   SerialAT.begin(115200); | ||||
|   delay(3000); | ||||
| @@ -97,6 +128,7 @@ void setup() { | ||||
|   // To skip it, call init() instead of restart() | ||||
|   SerialMon.println("Initializing modem..."); | ||||
|   modem.restart(); | ||||
|   // modem.init(); | ||||
|  | ||||
|   String modemInfo = modem.getModemInfo(); | ||||
|   SerialMon.print("Modem: "); | ||||
| @@ -105,20 +137,43 @@ void setup() { | ||||
|   // Unlock your SIM card with a PIN | ||||
|   //modem.simUnlock("1234"); | ||||
|  | ||||
|   SerialMon.print("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork()) { | ||||
| #if TINY_GSM_USE_WIFI | ||||
|   SerialMon.print(F("Setting SSID/password...")); | ||||
|   if (!modem.networkConnect(wifiSSID, wifiPass)) { | ||||
|     SerialMon.println(" fail"); | ||||
|     while (true); | ||||
|     delay(10000); | ||||
|     return; | ||||
|   } | ||||
|   SerialMon.println(" OK"); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE | ||||
|   // The XBee must run the gprsConnect function BEFORE waiting for network! | ||||
|   modem.gprsConnect(apn, gprsUser, gprsPass); | ||||
| #endif | ||||
|  | ||||
|   SerialMon.print("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork(240000L)) { | ||||
|     SerialMon.println(" fail"); | ||||
|     delay(10000); | ||||
|     return; | ||||
|   } | ||||
|   SerialMon.println(" OK"); | ||||
|  | ||||
|   SerialMon.print("Connecting to "); | ||||
|   if (modem.isNetworkConnected()) { | ||||
|     SerialMon.println("Network connected"); | ||||
|   } | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS | ||||
|     SerialMon.print(F("Connecting to ")); | ||||
|   SerialMon.print(apn); | ||||
|   if (!modem.gprsConnect(apn, user, pass)) { | ||||
|     if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { | ||||
|     SerialMon.println(" fail"); | ||||
|     while (true); | ||||
|       delay(10000); | ||||
|       return; | ||||
|   } | ||||
|   SerialMon.println(" OK"); | ||||
| #endif | ||||
|  | ||||
|   // MQTT Broker setup | ||||
|   mqtt.setServer(broker, 1883); | ||||
|   | ||||
| @@ -47,16 +47,6 @@ | ||||
| //#include <SoftwareSerial.h> | ||||
| //SoftwareSerial SerialAT(2, 3); // RX, TX | ||||
|  | ||||
| // See all AT commands, if wanted | ||||
| //#define DUMP_AT_COMMANDS | ||||
|  | ||||
| // See the debugging, if wanted | ||||
| // #define TINY_GSM_DEBUG SerialMon | ||||
|  | ||||
| // Range to attempt to autobaud | ||||
| #define GSM_AUTOBAUD_MIN 9600 | ||||
| #define GSM_AUTOBAUD_MAX 38400 | ||||
|  | ||||
| #define TINY_GSM_USE_GPRS true | ||||
| #define TINY_GSM_USE_WIFI false | ||||
|  | ||||
| @@ -122,9 +112,12 @@ void setup() { | ||||
|   SerialMon.print("Modem: "); | ||||
|   SerialMon.println(modemInfo); | ||||
|  | ||||
|   // Unlock your SIM card with a PIN | ||||
|   //modem.simUnlock("1234"); | ||||
| #if TINY_GSM_USE_GPRS | ||||
|   // Unlock your SIM card with a PIN if needed | ||||
|   if ( GSM_PIN && modem.getSimStatus() != 3 ) { | ||||
|     modem.simUnlock(GSM_PIN); | ||||
| } | ||||
| #endif | ||||
|  | ||||
| void loop() { | ||||
|  | ||||
| @@ -138,6 +131,11 @@ void loop() { | ||||
|   SerialMon.println(" OK"); | ||||
| #endif | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE | ||||
|   // The XBee must run the gprsConnect function BEFORE waiting for network! | ||||
|   modem.gprsConnect(apn, gprsUser, gprsPass); | ||||
| #endif | ||||
|  | ||||
|   SerialMon.print("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork(240000L)) { | ||||
|     SerialMon.println(" fail"); | ||||
| @@ -150,9 +148,9 @@ void loop() { | ||||
|     SerialMon.println("Network connected"); | ||||
|   } | ||||
|  | ||||
| #if TINY_GSM_USE_GPRS | ||||
| #if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS | ||||
|     SerialMon.print(F("Connecting to ")); | ||||
|     SerialMon.println(apn); | ||||
|     SerialMon.print(apn); | ||||
|     if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { | ||||
|       SerialMon.println(" fail"); | ||||
|       delay(10000); | ||||
| @@ -172,9 +170,10 @@ void loop() { | ||||
|  | ||||
|   // Make a HTTP GET request: | ||||
|   SerialMon.println("Performing HTTP GET request..."); | ||||
|   client.print(String("GET ") + resource + " HTTP/1.0\r\n"); | ||||
|   client.print(String("GET ") + resource + " HTTP/1.1\r\n"); | ||||
|   client.print(String("Host: ") + server + "\r\n"); | ||||
|   client.print("Connection: close\r\n\r\n"); | ||||
|   client.println(); | ||||
|  | ||||
|   unsigned long timeout = millis(); | ||||
|   while (client.connected() && millis() - timeout < 10000L) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user