This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

MQTT Socket error after 4 consecutive MQTT connect/disconnect

Hi,

we are using MQTT to push the sensor and GPS data with 1 hour interval. After 4 consecutive connect and disconnect, MQTT is returning socket error. It requires the device reboot to connect again, so rebooting the device after every 4 MQTT connections. Because of reboot the device is taking longer time to get GPS fix for first time.

It is 100% reproducible. we are using our own MQTT broker and also tried the other brokers as well and behavior is same.

Error log returned by MQTT is "ERROR: mqtt_connect -12".

Please help us to resolve the issue.

Parents Reply
  • Interesting!!

    Tested with the changes  as you mentioned and MQTT working as expected after consecutive MQTT connect/disconnect

    printk("Disconnecting MQTT client...\n");
    err = mqtt_disconnect(&client);
    if (err) {
    printk("Could not disconnect MQTT client. Error: %d\n", err);
    }

    err = mqtt_live(&client);
    if (err != 0) {
    printk("ERROR: mqtt_live %d\n", err);
    }

    Thanks for your support.

Children
No Data
Related