Update API and examples
This commit is contained in:
		| @@ -35,14 +35,15 @@ char user[] = ""; | ||||
| char pass[] = ""; | ||||
|  | ||||
| // Use Hardware Serial on Mega, Leonardo, Micro | ||||
| #define GsmSerial Serial1 | ||||
| #define SerialAT Serial1 | ||||
|  | ||||
| // or Software Serial on Uno, Nano | ||||
| //#include <SoftwareSerial.h> | ||||
| //SoftwareSerial GsmSerial(2, 3); // RX, TX | ||||
| //SoftwareSerial SerialAT(2, 3); // RX, TX | ||||
|  | ||||
| TinyGsmClient gsm(GsmSerial); | ||||
| PubSubClient mqtt(gsm); | ||||
| TinyGsm modem(SerialAT); | ||||
| TinyGsmClient client(modem); | ||||
| PubSubClient mqtt(client); | ||||
|  | ||||
| const char* broker = "test.mosquitto.org"; | ||||
|  | ||||
| @@ -63,18 +64,24 @@ void setup() { | ||||
|   delay(10); | ||||
|  | ||||
|   // Set GSM module baud rate | ||||
|   GsmSerial.begin(115200); | ||||
|   SerialAT.begin(115200); | ||||
|   delay(3000); | ||||
|  | ||||
|   // Restart takes quite some time | ||||
|   // You can skip it in many cases | ||||
|   Serial.println("Restarting modem..."); | ||||
|   gsm.restart(); | ||||
|   modem.restart(); | ||||
|  | ||||
|   Serial.print("Waiting for network..."); | ||||
|   if (!modem.waitForNetwork()) { | ||||
|     Serial.println(" fail"); | ||||
|     while (true); | ||||
|   } | ||||
|   Serial.println(" OK"); | ||||
|  | ||||
|   Serial.print("Connecting to "); | ||||
|   Serial.print(apn); | ||||
|   if (!gsm.networkConnect(apn, user, pass)) { | ||||
|     Serial.println(" failed"); | ||||
|   if (!modem.gprsConnect(apn, user, pass)) { | ||||
|     Serial.println(" fail"); | ||||
|     while (true); | ||||
|   } | ||||
|   Serial.println(" OK"); | ||||
| @@ -88,7 +95,7 @@ boolean mqttConnect() { | ||||
|   Serial.print("Connecting to "); | ||||
|   Serial.print(broker); | ||||
|   if (!mqtt.connect("GsmClientTest")) { | ||||
|     Serial.println(" failed"); | ||||
|     Serial.println(" fail"); | ||||
|     return false; | ||||
|   } | ||||
|   Serial.println(" OK"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user