0

I am using ESP8266 chip and the SMING software framework MqttClient_Hello example.

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 relevant code in MqttClient_Hello;

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");
}

What needs to be changed in the code to ensure constant connection?

mpromonet
  • 11,326
  • 43
  • 62
  • 91
guagay_wk
  • 26,337
  • 54
  • 186
  • 295

1 Answers1

1

So SMING does not seem to have a disconnect or error callback.
int mqtt_ping(mqtt_broker_handle_t* broker){...} is implemented in libemqtt and you could try to maintain the connection with a regular ping and try to reconnect if it fails.

DooMMasteR
  • 277
  • 2
  • 13