MQTT subscribe disconnects every few seconds
Posted: Wed Jan 14, 2015 5:18 am
I have esp_mqtt-master working and have removed the publishing code with the aim of making a unit to switch the heating in my greenhouse. It does receive the published messages but continually disconnects and reconnects to the MQTT server every few seconds. I get the debug messsage 'TCP: Disconnected callback' a second or so after the 'subscribe' message was sent. Any ideas please?
Solved: I was using test.mosquitto mqtt server which does not require formal registration and I did not realise the significance of the client Id until I found this from IBM - "If your MQTT client connects successfully and later disconnects with no apparent reason" - if "Another client is started and connects with the same client ID. ... In this case, WebSphere® MQ accepts the connection from the second MQTT client and forcefully disconnects the first MQTT client." I guess this is related to my problem as when I updated MQTT_CLIENT_ID in user_config.h, the problem went away.
Solved: I was using test.mosquitto mqtt server which does not require formal registration and I did not realise the significance of the client Id until I found this from IBM - "If your MQTT client connects successfully and later disconnects with no apparent reason" - if "Another client is started and connects with the same client ID. ... In this case, WebSphere® MQ accepts the connection from the second MQTT client and forcefully disconnects the first MQTT client." I guess this is related to my problem as when I updated MQTT_CLIENT_ID in user_config.h, the problem went away.