|
10 | 10 | * For more MQTT examples, see PubSubClient library |
11 | 11 | * |
12 | 12 | ************************************************************** |
13 | | - * Use Mosquitto client tools to work with MQTT |
14 | | - * Ubuntu/Linux: sudo apt-get install mosquitto-clients |
15 | | - * Windows: https://mosquitto.org/download/ |
| 13 | + * This example connects to HiveMQ's showcase broker. |
16 | 14 | * |
17 | | - * Subscribe for messages: |
18 | | - * mosquitto_sub -h test.mosquitto.org -t GsmClientTest/init -t GsmClientTest/ledStatus -q 1 |
19 | | - * Toggle led: |
20 | | - * mosquitto_pub -h test.mosquitto.org -t GsmClientTest/led -q 1 -m "toggle" |
| 15 | + * You can quickly test sending and receiving messages from the HiveMQ webclient |
| 16 | + * available at http://www.hivemq.com/demos/websocket-client/. |
21 | 17 | * |
22 | | - * You can use Node-RED for wiring together MQTT-enabled devices |
23 | | - * https://nodered.org/ |
24 | | - * Also, take a look at these additional Node-RED modules: |
25 | | - * node-red-contrib-blynk-ws |
26 | | - * node-red-dashboard |
| 18 | + * Subscribe to the topic GsmClientTest/ledStatus |
| 19 | + * Publish "toggle" to the topic GsmClientTest/led and the LED on your board |
| 20 | + * should toggle and you should see a new message published to |
| 21 | + * GsmClientTest/ledStatus with the newest LED status. |
27 | 22 | * |
28 | 23 | **************************************************************/ |
29 | 24 |
|
@@ -251,6 +246,34 @@ void setup() { |
251 | 246 | } |
252 | 247 |
|
253 | 248 | void loop() { |
| 249 | + // Make sure we're still registered on the network |
| 250 | + if (!modem.isNetworkConnected()) { |
| 251 | + SerialMon.println("Network disconnected"); |
| 252 | + if (!modem.waitForNetwork(180000L, true)) { |
| 253 | + SerialMon.println(" fail"); |
| 254 | + delay(10000); |
| 255 | + return; |
| 256 | + } |
| 257 | + if (modem.isNetworkConnected()) { |
| 258 | + SerialMon.println("Network re-connected"); |
| 259 | + } |
| 260 | + |
| 261 | +#if TINY_GSM_USE_GPRS |
| 262 | + // and make sure GPRS/EPS is still connected |
| 263 | + if (!modem.isGprsConnected()) { |
| 264 | + SerialMon.println("GPRS disconnected!"); |
| 265 | + SerialMon.print(F("Connecting to ")); |
| 266 | + SerialMon.print(apn); |
| 267 | + if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { |
| 268 | + SerialMon.println(" fail"); |
| 269 | + delay(10000); |
| 270 | + return; |
| 271 | + } |
| 272 | + if (modem.isGprsConnected()) { SerialMon.println("GPRS reconnected"); } |
| 273 | + } |
| 274 | +#endif |
| 275 | + } |
| 276 | + |
254 | 277 | if (!mqtt.connected()) { |
255 | 278 | SerialMon.println("=== MQTT NOT CONNECTED ==="); |
256 | 279 | // Reconnect every 10 seconds |
|
0 commit comments