How to ensure that MQTT connection is always present?
Posted: Wed Jan 06, 2016 5:26 am
I am using SMING framework "MqttClient_Hello" example.
The code to connect to the MQTT broker is quite simple. The relevant code is below;
I want the MQTT connection to always be present at all time. If for whatever reason the connection is broken, I would like a reconnection to take place. How can this be done?
The code to connect to the MQTT broker is quite simple. The relevant code is below;
Code: Select all
void startMqttClient();
void onMessageReceived(String topic, String message);
MqttClient mqtt("192.168.1.8", 1883, onMessageReceived);
// Run MQTT client
void startMqttClient()
{
mqtt.connect("esp8266");
mqtt.subscribe("TopicTest");
}
I want the MQTT connection to always be present at all time. If for whatever reason the connection is broken, I would like a reconnection to take place. How can this be done?