Window10
nrf tag: 1.2.0
SES v4.4.2a
I'm attempting to code a one-shot mqtt function, but it fails in v1.2.0 whiile it succeeded in v1.1.0. I coded the below main.c by modifying mqtt_simple a bit. I don't touch other files but main.c
A mqtt_disconect generates error -57. Why does this happen?
<main.c>
void main(void)
{
int err;
printk("The MQTT simple sample started\n");
modem_configure();
client_init(&client);
while (1) {
err = mqtt_connect(&client);
if (err != 0) {
printk("ERROR: mqtt_connect %d\n", err);
return;
} else {
printk("MQTT connected!\n");
}
err = fds_init(&client);
if (err != 0) {
printk("ERROR: fds_init %d\n", err);
return;
}
err = poll(&fds, 1, 500);
if (err < 0) {
printk("ERROR: poll %d\n", errno);
break;
} else {
printk("after poll\n");
}
err = mqtt_live(&client);
if ((err != 0) && (err != -EAGAIN)) {
printk("ERROR: mqtt_live %d\n", err);
break;
}
if ((fds.revents & POLLIN) == POLLIN) {
err = mqtt_input(&client);
if (err != 0) {
printk("ERROR: mqtt_input %d\n", err);
break;
}
}
if ((fds.revents & POLLERR) == POLLERR) {
printk("POLLERR\n");
break;
}
if ((fds.revents & POLLNVAL) == POLLNVAL) {
printk("POLLNVAL\n");
break;
}
err = mqtt_disconnect(&client);
if (err) {
// ENOTCONN 57 /* Socket is not connected */
printk("Could not disconnect MQTT client. Error: %d\n", err);
} else {
printk("MQTT disconnected!\n");
}
k_sleep(10*1000);
}
}
<output>
*** Booting Zephyr OS build v2.1.99-ncs1 *** The MQTT simple sample started LTE Link Connecting ... LTE Link Connected! IPv4 Address found 137.135.83.217 MQTT connected! after poll Could not disconnect MQTT client. Error: -57 MQTT connected! after poll Could not disconnect MQTT client. Error: -57 MQTT connected! after poll Could not disconnect MQTT client. Error: -57