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

MQTT disconnect in mqtt_simple sample

Hi, 

I am trying to do MQTT disconnect, but I am always getting an error. 

First I successfully connect to the MQTT server, then I send some data, and then I want to disconnect. When I am connecting the handler form mqtt is called (mqtt_evt_handler) and go to the case: MQTT_EVT_CONNACK, but when I do mqtt_disconnect, I always receive an error, and never disconnect properly. Also when disconnecting handler is never called. 
The code for disconnection

printk("Disconnecting MQTT client...\n");
err = mqtt_disconnect(&client);
rc = poll(&fds, 1, K_SECONDS(CONFIG_MQTT_KEEPALIVE));
if (rc < 0) {
      printk("ERROR: poll %d\n", errno);
}
if (err) {
        printk("Could not disconnect MQTT client. Error: %d\n", err);
}

Log:
297239 - Disconnecting MQTT client...
297242 - Could not disconnect MQTT client. Error: -57

What might be the problem?

Best regards,
Voja. 

Parents Reply Children
No Data
Related