Hey! I have been using MQTT with QoS 0 to transmit my sensor readings to nRF Cloud. However, I see data loss regularly, and I expect that is happening between my device and nRF Cloud, since the device is mobile and connects over LTE.
I'd like to upgrade to QoS 1, to see if it resolves my data loss. However, I had some questions about how QoS is handled in the nRF Cloud library, as I have been digging into the source code, but I am a bit new to both nRF devices and C.
- If I simply send my message with MQTT_QOS_1_AT_LEAST_ONCE, does the library handle checking for PUBACKs with matching IDs and retrying messages that are not eventually ACKed?
- Either way, is it possible for me to access these PUBACKs from the nRF cloud library events? I see that there is a `NRF_CLOUD_EVT_SENSOR_DATA_ACK` nrf_cloud_evt type, and the old asset tracker v2 (which is deprecated, but it's the only one I find that shows how to do this) example extracts a message id from that, and then uses the nRF Quality of Service library to handle tracking acknowledgements in the application itself.
- The reason I say either way is that I'd like to protect against the case where my device transmits a message, but then reboots before the PUBACK is received. And to do that I need to keep track of whether a message has been acknowledged in non-volatile memory.
I am using the 2.8.0 version of the nRF Connect SDK. Here is my transmission code:
int cloud_transmit_measurement_block(const uint8_t *data, size_t size, const uint8_t *iv) { const int ret = encode_measurement_block(json_buffer, sizeof(json_buffer), data, size, iv); if (ret < 0) { LOG_ERR("Could not encode measurement block, err: %d", ret); return ret; } struct nrf_cloud_tx_data msg = { .data = { .ptr = json_buffer, .len = ret, }, .id = sys_rand32_get(), .qos = MQTT_QOS_1_AT_LEAST_ONCE, .topic_type = NRF_CLOUD_TOPIC_MESSAGE, }; return cloud_transmit(&msg);}
If anyone can point me in the right direction here, it would be greatly appreciated. I am happy to provide more context if needed. Thanks!