March 2018
Beginner to intermediate
410 pages
10h 40m
English
Since MQTT uses TCP, it requires a live socket connection to work. Since a socket connection may fail for different reasons over time, we need to build a recovery mechanism into our device. The simplest such mechanism is to check the state of the connection at regular intervals, and reconnect if we detect that the connection has been lost. We can use our sampling timer for this. Once a minute, we check the connection state, and initiate a reconnection if it is offline or in an error state. The reconnection itself fails, if the network is not available at the time. In that case, new reconnection attempts will be performed every minute:
if (Timestamp.Second == 0 && this.mqttClient != null && (this.mqttClient.State ...
Read now
Unlock full access