Skip to content

Commit 6bf8fee

Browse files
plskeggsnordicjm
authored andcommitted
samples: cellular: nrf_cloud_multi_service: reduce prov rate
Once device has connected to the cloud, slow down the provisioning check. Improve logging of shadow and FOTA polling intervals for CoAP. Make CoAP shadow and FOTA check intervals the same as the sensor update interval. Improve handling of credentials check to check for new error code for bad CA size, and also turn off network if credentials are bad and the nrf_provisioning service is not used. Jira: IRIS-9151 Signed-off-by: Pete Skeggs <[email protected]>
1 parent c4d49f6 commit 6bf8fee

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

samples/cellular/nrf_cloud_multi_service/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ config SEND_ONLINE_ALERT
245245
Enable this to demonstrate the alert feature of nRF Cloud. Reception of this alert
246246
indicates the device has rebooted.
247247

248+
config POST_PROVISIONING_INTERVAL_M
249+
int "Delay in minutes between provisioning checks once connected"
250+
default 30
251+
help
252+
Use a slower rate to check for provisioning after we have successfully connected.
253+
Until then use CONFIG_NRF_PROVISIONING_INTERVAL_S.
254+
248255
if NRF_CLOUD_COAP
249256

250257
menuconfig COAP_FOTA

samples/cellular/nrf_cloud_multi_service/overlay_coap.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ CONFIG_NEWLIB_LIBC_NANO=n
1313
# This is strictly for demo purposes.
1414
CONFIG_SENSOR_SAMPLE_INTERVAL_SECONDS=120
1515
CONFIG_LOCATION_TRACKING_SAMPLE_INTERVAL_SECONDS=360
16-
CONFIG_COAP_FOTA_JOB_CHECK_RATE_MINUTES=5
16+
CONFIG_COAP_FOTA_JOB_CHECK_RATE_MINUTES=2
17+
CONFIG_COAP_SHADOW_CHECK_RATE_SECONDS=120
1718

1819
# Logs
1920
CONFIG_LOG=y

samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <net/nrf_cloud_coap.h>
1717
#include "fota_support_coap.h"
1818
#endif
19+
#include <net/nrf_provisioning.h>
1920

2021
#include "cloud_connection.h"
2122
#include "provisioning_support.h"
@@ -143,6 +144,12 @@ static void cloud_ready(void)
143144
/* Notify that the nRF Cloud connection is ready for use. */
144145
k_event_post(&cloud_events, CLOUD_READY);
145146
LOG_DBG("Setting CLOUD_READY");
147+
148+
if (IS_ENABLED(CONFIG_NRF_PROVISIONING)) {
149+
LOG_INF("Reducing provisioning check interval to %d minutes",
150+
CONFIG_POST_PROVISIONING_INTERVAL_M);
151+
nrf_provisioning_set_interval(CONFIG_POST_PROVISIONING_INTERVAL_M * SEC_PER_MIN);
152+
}
146153
}
147154

148155
/* A callback that the application may register in order to handle custom device messages.
@@ -614,10 +621,22 @@ static void check_credentials(void)
614621
LOG_WRN("nRF Cloud credentials are not installed. "
615622
"Please install and reboot.");
616623
}
617-
k_sleep(K_FOREVER);
618-
} else if (status) {
619-
LOG_ERR("Error while checking for credentials: %d. Proceeding anyway.", status);
624+
} else if (status == -ENOPROTOOPT) {
625+
LOG_WRN("Required root CA certificate is missing.");
626+
} else {
627+
if (status) {
628+
LOG_ERR("Error while checking for credentials: %d. Proceeding anyway.",
629+
status);
630+
}
631+
return;
632+
}
633+
if (!IS_ENABLED(CONFIG_NRF_PROVISIONING)) {
634+
/* Save power since credentials will not work, and we are not using the
635+
* cloud-based nrf_provisioning service.
636+
*/
637+
conn_mgr_all_if_down(true);
620638
}
639+
k_sleep(K_FOREVER);
621640
}
622641

623642
void cloud_connection_thread_fn(void)

samples/cellular/nrf_cloud_multi_service/src/fota_support_coap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ int coap_fota_thread_fn(void)
8181
*/
8282
err = nrf_cloud_fota_poll_process(&ctx);
8383
if (err == -EAGAIN) {
84-
LOG_DBG("Retrying in %d minute(s)",
85-
CONFIG_COAP_FOTA_JOB_CHECK_RATE_MINUTES);
84+
LOG_INF("Checking for FOTA job in %d seconds",
85+
CONFIG_COAP_FOTA_JOB_CHECK_RATE_MINUTES * SEC_PER_MIN);
8686
k_sleep(K_MINUTES(CONFIG_COAP_FOTA_JOB_CHECK_RATE_MINUTES));
8787
continue;
8888
}

0 commit comments

Comments
 (0)