I'm using v1.2.0 for the nrf project and I am fairly confident I am using modem firmware 1.1.1 (though I don't know how to verify that).
I'm basing my project on "cloud_client" example using the aws_iot backend, and have this function setup:
static void aws_iot_test_work(struct k_work *work) { LOG_DBG("AWS IoT Work!"); int err = cloud_connect(s_cloud_backend); if (err) { LOG_DBG("connect error: %d", err); return; } LOG_DBG("Connect success!"); struct pollfd fds[] = { { .fd = s_cloud_backend->config->socket, .events = POLLIN } }; while(1) { err = poll(fds, ARRAY_SIZE(fds), K_MSEC(10000)); if (err < 0) { LOG_DBG("poll error!: %d", err); goto out_disconnect; } if (err == 0) { LOG_DBG("Timeout!"); goto out_disconnect; } if ((fds[0].revents & POLLIN) == POLLIN) { LOG_DBG("Input!"); cloud_input(s_cloud_backend); } if ((fds[0].revents & POLLNVAL) == POLLNVAL) { LOG_DBG("Socket error: POLLNVAL, the cloud socket was unexpectedly closed."); goto out_disconnect; } if ((fds[0].revents & POLLHUP) == POLLHUP) { LOG_DBG("Socket error: POLLHUP, connection was closed by the cloud."); goto out_disconnect; } if ((fds[0].revents & POLLERR) == POLLERR) { LOG_DBG("Socket error: POLLERR, cloud connection was unexpectedly closed"); goto out_disconnect; } } out_disconnect: err = cloud_disconnect(s_cloud_backend); if(err) { LOG_DBG("disconnect failure! %d", err); } }
Running this function once works. It connects, waits 10 seconds, and then disconnects just fine.
When I run it a second time though it hangs the process. I've traced the problem to this line in "zephyr/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c":
ret = connect(client->transport.tls.sock, client->broker, peer_addr_size);
After this I believe its just making calls into bsdlib which we don't have source for.
Any thoughts on what else I need to do with the mqtt_client or socket so I can reuse it?