Yes, I’m using an MQTT client for publishing and subscribing to data. I’m not sure how the client is implemented but it’s likely using the same socket.
The main difference between my code and the sample is that I don’t use net_connect() to connect to the network but rather use this custom function:
int MQTT::connect_to_network()
{
int err;
// Initialize modem library
err = nrf_modem_lib_init();
if (err)
{
LOG_ERR("Failed to initialize the modem library, error: %d", err);
k_sleep(K_SECONDS(CONFIG_MQTT_RECONNECT_DELAY_S));
sys_reboot(SYS_REBOOT_COLD);
}
k_msleep(1000);
// Connect to LTE network
LOG_DBG("Connecting to LTE network");
lte_lc_register_handler(lte_handler);
err = lte_lc_connect();
if (err)
{
LOG_ERR("Error when connecting to network: %d", err);
k_sleep(K_SECONDS(CONFIG_MQTT_RECONNECT_DELAY_S));
sys_reboot(SYS_REBOOT_COLD);
}
LOG_DBG("Connected to LTE network!");
k_msleep(100);
// Activate connectivity statistics
char response[3];
nrf_modem_at_scanf("AT%XCONNSTAT=1", "%s", response);
if (strstr(response, "OK") == NULL)
{
LOG_ERR("Failed to set connectivity statistics.");
}
return 0;
}
Commenting out all of my MQTT related code, adding the configs for network connection manager to the project config and connecting using net_connect() doesn’t fix the issue.
However if I try to use MQTT with connection manager and net_connect(), the connection fails more often. It also reconnects sometimes, but is overall much less stable:
[00:00:49.447,021] <inf> golioth_coap_client_zephyr: Ending session
[00:00:52.218,994] <inf> golioth_coap_client_zephyr: Golioth CoAP client connected
[00:00:52.219,177] <inf> golioth_coap_client_zephyr: Entering CoAP I/O loop
[00:00:52.562,713] <inf> golioth_fw_update: Received OTA manifest
[00:00:52.562,774] <inf> golioth_fw_update: Current version = 1.0.8, Target version = 1.0.8
[00:00:52.562,805] <inf> golioth_fw_update: Current version matches target version.
[00:00:52.562,805] <inf> golioth_fw_update: Manifest does not contain different firmware version. Nothing to do.
[00:00:52.562,805] <inf> golioth_fw_update: State = Idle
[00:01:22.850,250] <wrn> golioth_coap_client_zephyr: Receive timeout
[00:01:22.850,280] <inf> golioth_coap_client_zephyr: Ending session
[00:01:26.877,960] <err> golioth_coap_client_zephyr: Failed to connect to socket: -11
[00:01:26.879,272] <err> golioth_coap_client_zephyr: Failed to connect: -11
[00:01:26.879,272] <wrn> golioth_coap_client_zephyr: Failed to connect: -11
[00:01:34.881,805] <err> golioth_coap_client_zephyr: Failed to connect to socket: -11
[00:01:34.882,965] <err> golioth_coap_client_zephyr: Failed to connect: -11
[00:01:34.882,965] <wrn> golioth_coap_client_zephyr: Failed to connect: -11
[00:01:42.899,688] <err> golioth_coap_client_zephyr: Failed to connect to socket: -11
[00:01:42.901,214] <err> golioth_coap_client_zephyr: Failed to connect: -11
[00:01:42.901,245] <wrn> golioth_coap_client_zephyr: Failed to connect: -11
[00:01:50.070,037] <inf> golioth_coap_client_zephyr: Golioth CoAP client connected
[00:01:50.070,220] <inf> golioth_coap_client_zephyr: Entering CoAP I/O loop
[00:01:50.424,774] <inf> golioth_fw_update: Received OTA manifest
[00:01:50.424,835] <inf> golioth_fw_update: Current version = 1.0.8, Target version = 1.0.8
[00:01:50.424,835] <inf> golioth_fw_update: Current version matches target version.
[00:01:50.424,865] <inf> golioth_fw_update: Manifest does not contain different firmware version. Nothing to do.
[00:01:50.424,865] <inf> golioth_fw_update: State = Idle
[00:02:20.803,283] <wrn> golioth_coap_client_zephyr: Receive timeout
[00:02:20.803,283] <inf> golioth_coap_client_zephyr: Ending session
[00:02:24.816,497] <err> golioth_coap_client_zephyr: Failed to connect to socket: -11
[00:02:24.817,687] <err> golioth_coap_client_zephyr: Failed to connect: -11
[00:02:24.817,687] <wrn> golioth_coap_client_zephyr: Failed to connect: -11
[00:02:31.168,457] <inf> golioth_coap_client_zephyr: Golioth CoAP client connected
[00:02:31.168,670] <inf> golioth_coap_client_zephyr: Entering CoAP I/O loop
[00:02:31.495,239] <inf> golioth_fw_update: Received OTA manifest
[00:02:31.495,300] <inf> golioth_fw_update: Current version = 1.0.8, Target version = 1.0.8
[00:02:31.495,300] <inf> golioth_fw_update: Current version matches target version.
[00:02:31.495,330] <inf> golioth_fw_update: Manifest does not contain different firmware version. Nothing to do.
[00:02:31.495,330] <inf> golioth_fw_update: State = Idle```
updated the Golioth Firmware SDK version, but did not run a west update
afterwards.
I did, but I used west only for installation, as I’m compiling using the NRF VSCode extension, which was set to use NCS 2.9.0. There is a breaking change with the NCS 3.0.1 directly relating to the SDK:
/opt/nordic/ncs/v3.0.1/nrf/include/flash_map_pm.h:10:10: fatal error: pm_config.h: No such file or directory
Now, I can’t find an default partition manager file for the NRF9160/1 so I can’t compile the code, and the Golioth SDK also only provides .conf files for this processor family.
The Golioth Firmware SDK uses NCS v3.0.1 in v0.18.1.
Which version does 0.17.0 use? I can try to invest more time to migrate to the new NCS but I’m not sure if it would even fix the issue.