Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: lib: nrf_cloud: add ability to auto send fota and ui svc info #13430

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ Cellular samples

* The sample now explicitly uses the :c:func:`conn_mgr_all_if_connect` function to start network connectivity, instead of the :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START` and :kconfig:option:`CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT` Kconfig options.
* The sample to use the FOTA support functions in the :file:`nrf_cloud_fota_poll.c` and :file:`nrf_cloud_fota_common.c` files.
* The sample now enables the Kconfig options :kconfig:option:`CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_FOTA` and :kconfig:option:`CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_UI`.
jayteemo marked this conversation as resolved.
Show resolved Hide resolved
It no longer sends a device status update on initial connection; this is now handled by the :ref:`lib_nrf_cloud` library.

* Removed nRF7002 EK DTC overlay file ``nrf91xxdk_with_nrf7002ek.overlay`` because UART1 is disabled through the shield configuration.

Expand Down Expand Up @@ -608,6 +610,8 @@ Libraries for networking
* The :c:func:`nrf_cloud_obj_object_detach` function to get an object from an object.
* The :c:func:`nrf_cloud_obj_shadow_update` function to update the device's shadow with the data from an :c:struct:`nrf_cloud_obj` structure.
* An :c:struct:`nrf_cloud_obj_shadow_data` structure to the :c:struct:`nrf_cloud_evt` structure to be used during shadow update events.
* The :kconfig:option:`CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_FOTA` Kconfig option to enable sending configured FOTA service info on the device's initial connection to nRF Cloud.
* The :kconfig:option:`CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_UI` Kconfig option to enable sending configured UI service info on the device's initial connection to nRF Cloud.

* Updated:

Expand Down
1 change: 1 addition & 0 deletions samples/cellular/nrf_cloud_multi_service/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ config TEMP_DATA_USE_SENSOR
config TEMP_TRACKING
bool "Track temperature"
default y
select NRF_CLOUD_ENABLE_SVC_INF_UI_TEMP
help
Sets whether to take temperature measurements.

Expand Down
4 changes: 4 additions & 0 deletions samples/cellular/nrf_cloud_multi_service/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n
CONFIG_NRF_CLOUD_ALERT=y
CONFIG_NRF_CLOUD_LOG_DIRECT=y
CONFIG_NRF_CLOUD_LOG_OUTPUT_LEVEL=3

# On initial connection to the cloud, add info sections to the shadow
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS=y
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK=y
CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_SIM=y
CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_FOTA=y
CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_UI=y
62 changes: 4 additions & 58 deletions samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ static K_EVENT_DEFINE(cloud_events);
/* Atomic status flag tracking whether an initial association is in progress. */
atomic_t initial_association;

static void update_shadow(void);

/* Helper functions for pending on pendable events. */
bool await_network_ready(k_timeout_t timeout)
{
Expand Down Expand Up @@ -215,7 +213,6 @@ static bool connect_cloud(void)
if (!err) {
cloud_connected();
cloud_ready();
update_shadow();
return true;
}
#endif
Expand Down Expand Up @@ -245,59 +242,6 @@ static bool connect_cloud(void)
return true;
}

/**
* @brief Updates the nRF Cloud shadow with information about supported capabilities, current
* firmware running, FOTA support, and so on.
*/
static void update_shadow(void)
{
#if !defined(CONFIG_NRF_CLOUD_COAP) || defined(CONFIG_COAP_SHADOW)
static bool updated;
int err;
struct nrf_cloud_svc_info_fota fota_info = {
.application = nrf_cloud_fota_is_type_enabled(NRF_CLOUD_FOTA_APPLICATION),
.bootloader = nrf_cloud_fota_is_type_enabled(NRF_CLOUD_FOTA_BOOTLOADER),
.modem = nrf_cloud_fota_is_type_enabled(NRF_CLOUD_FOTA_MODEM_DELTA),
.modem_full = nrf_cloud_fota_is_type_enabled(NRF_CLOUD_FOTA_MODEM_FULL)
};
struct nrf_cloud_svc_info_ui ui_info = {
.gnss = location_tracking_enabled(),
.temperature = IS_ENABLED(CONFIG_TEMP_TRACKING),
.log = nrf_cloud_is_text_logging_enabled(),
.dictionary_log = nrf_cloud_is_dict_logging_enabled()
};
struct nrf_cloud_svc_info service_info = {
.fota = &fota_info,
.ui = &ui_info
};
struct nrf_cloud_device_status device_status = {
/* Modem info is sent automatically since CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS
* is enabled, so it can be skipped here.
*/
.modem = NULL,
.svc = &service_info,
.conn_inf = NRF_CLOUD_INFO_NO_CHANGE
};

if (updated) {
return; /* It is not necessary to do this more than once per boot. */
}
LOG_DBG("Updating shadow");
#if defined(CONFIG_NRF_CLOUD_MQTT)
err = nrf_cloud_shadow_device_status_update(&device_status);
#elif defined(CONFIG_NRF_CLOUD_COAP)
err = nrf_cloud_coap_shadow_device_status_update(&device_status);
#endif

if (err) {
LOG_ERR("Failed to update device shadow, error: %d", err);
} else {
LOG_DBG("Updated shadow");
updated = true;
}
#endif /* !defined(CONFIG_NRF_CLOUD_COAP) || defined(CONFIG_COAP_SHADOW) */
}

/* External event handlers */

/* Handler for L4/connectivity events
Expand Down Expand Up @@ -446,8 +390,10 @@ static void cloud_event_handler(const struct nrf_cloud_evt *nrf_cloud_evt)
/* Handle achievement of readiness */
cloud_ready();

/* Update the device shadow */
update_shadow();
/* The nRF Cloud library will automatically update the
* device's shadow based on the build configuration.
* See config NRF_CLOUD_SEND_SHADOW_INFO for details.
*/

break;
case NRF_CLOUD_EVT_SENSOR_DATA_ACK:
Expand Down
27 changes: 2 additions & 25 deletions subsys/net/lib/nrf_cloud/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ rsource "Kconfig.nrf_cloud_log"

rsource "Kconfig.nrf_cloud_coap"

rsource "Kconfig.nrf_cloud_shadow_info"

config NRF_CLOUD_GATEWAY
bool "nRF Cloud Gateway"
help
Expand All @@ -47,31 +49,6 @@ config NRF_CLOUD_CHECK_CREDENTIALS
bool "Enable the ability to check if nRF Cloud credentials are present"
select MODEM_KEY_MGMT if NRF_MODEM_LIB

config NRF_CLOUD_SEND_DEVICE_STATUS
bool "Send device status on initial connection"
depends on NRF_CLOUD_MQTT || NRF_CLOUD_COAP
depends on MODEM_INFO
depends on MODEM_INFO_ADD_DEVICE
default y if NRF_CLOUD_FOTA
help
Send device status, containing hardware and firmware version information,
to nRF Cloud on initial connection after library initialization.

config NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK
bool "Include network status information with device status"
depends on NRF_CLOUD_SEND_DEVICE_STATUS
depends on MODEM_INFO_ADD_NETWORK

config NRF_CLOUD_SEND_DEVICE_STATUS_SIM
bool "Include SIM card information with device status"
depends on NRF_CLOUD_SEND_DEVICE_STATUS
depends on MODEM_INFO_ADD_SIM

config NRF_CLOUD_SEND_DEVICE_STATUS_CONN_INF
bool "Include connection information with device status"
depends on NRF_CLOUD_SEND_DEVICE_STATUS
default y

config NRF_CLOUD_DEVICE_STATUS_ENCODE_VOLTAGE
bool "Include the (battery) voltage when encoding device status"
depends on MODEM_INFO
Expand Down
32 changes: 32 additions & 0 deletions subsys/net/lib/nrf_cloud/Kconfig.nrf_cloud_fota
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ config NRF_CLOUD_FOTA_FULL_MODEM_UPDATE_BUF_SIZE
default 4096
endif # NRF_CLOUD_FOTA_FULL_MODEM_UPDATE

config NRF_CLOUD_FOTA_TRANSPORT_ENABLED
bool
default y if (NRF_CLOUD_REST || NRF_CLOUD_COAP || NRF_CLOUD_FOTA)
help
This symbol is y when a FOTA transport type is enabled in the configuration.

config NRF_CLOUD_FOTA_TYPE_APP_SUPPORTED
bool
default y if (BOOTLOADER_MCUBOOT && NRF_CLOUD_FOTA_TRANSPORT_ENABLED) 
help
This symbol is y when application FOTA is supported by the configuration.

config NRF_CLOUD_FOTA_TYPE_BOOT_SUPPORTED
bool
default y if (BOOTLOADER_MCUBOOT && BUILD_S1_VARIANT && SECURE_BOOT && \
NRF_CLOUD_FOTA_TRANSPORT_ENABLED)
help
This symbol is y when bootloader FOTA is supported by the configuration.

config NRF_CLOUD_FOTA_TYPE_MODEM_DELTA_SUPPORTED
bool
default y if (NRF_MODEM && NRF_CLOUD_FOTA_TRANSPORT_ENABLED)
help
This symbol is y when modem delta FOTA is supported by the configuration.

config NRF_CLOUD_FOTA_TYPE_MODEM_FULL_SUPPORTED
bool
default y if (NRF_MODEM && NRF_CLOUD_FOTA_FULL_MODEM_UPDATE && \
NRF_CLOUD_FOTA_TRANSPORT_ENABLED)
help
This symbol is y when full modem FOTA is supported by the configuration.

config NRF_CLOUD_FOTA_POLL
bool "Enable FOTA job polling helpers"
help
Expand Down
13 changes: 13 additions & 0 deletions subsys/net/lib/nrf_cloud/Kconfig.nrf_cloud_log
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ config NRF_CLOUD_LOG_BUF_SIZE
help
Set size in bytes for buffer for log output system before it flushes.

config NRF_CLOUD_LOG_TEXT_LOGGING_ENABLED
bool
default y if (NRF_CLOUD_LOG_BACKEND && LOG_BACKEND_NRF_CLOUD_OUTPUT_TEXT) || \
(NRF_CLOUD_LOG_DIRECT && !LOG_BACKEND_NRF_CLOUD_OUTPUT_DICTIONARY)
help
This symbol is y when nRF Cloud text-based logging is enabled in the configuration.

config NRF_CLOUD_LOG_DICTIONARY_LOGGING_ENABLED
bool
default y if (NRF_CLOUD_LOG_BACKEND && LOG_BACKEND_NRF_CLOUD_OUTPUT_DICTIONARY)
help
This symbol is y when nRF Cloud dictionary-based (binary) logging is enabled in the configuration.

module = NRF_CLOUD_LOG
module-str = nRF Cloud Log
source "subsys/logging/Kconfig.template.log_config"
106 changes: 106 additions & 0 deletions subsys/net/lib/nrf_cloud/Kconfig.nrf_cloud_shadow_info
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Select the info sections that will be automatically added to the device's
# shadow when connecting to nRF Cloud with MQTT or CoAP.
menu "Send shadow info sections on initial connect (MQTT/CoAP)"

if NRF_CLOUD_MQTT || NRF_CLOUD_COAP

config NRF_CLOUD_SEND_DEVICE_STATUS
bool "Send device status on initial connection"
depends on MODEM_INFO
depends on MODEM_INFO_ADD_DEVICE
default y if NRF_CLOUD_FOTA
help
Add "deviceInfo" section containing hardware and firmware version information.

config NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK
bool "Send network status information on initial connection"
depends on MODEM_INFO
depends on MODEM_INFO_ADD_NETWORK
help
Add "networkInfo" section containing network connection information.

config NRF_CLOUD_SEND_DEVICE_STATUS_SIM
bool "Send SIM card information on initial connection"
depends on MODEM_INFO
depends on MODEM_INFO_ADD_SIM
help
Add "simInfo" section containing SIM card information.

config NRF_CLOUD_SEND_DEVICE_STATUS_CONN_INF
bool "Send connection information on initial connection"
default y
help
Add "connectionInfo" section indication how the device is connecting to nRF Cloud.

config NRF_CLOUD_SEND_SERVICE_INFO_FOTA
bool "Send FOTA service info on initial connection"
help
Add supported FOTA types to the "serviceInfo" section.
If your application does not support certain FOTA types, this option should be disabled and the application should set its supported FOTA types in the shadow.
Supported types are based on Kconfig values:
NRF_CLOUD_FOTA_TYPE_APP_SUPPORTED
NRF_CLOUD_FOTA_TYPE_BOOT_SUPPORTED
NRF_CLOUD_FOTA_TYPE_MODEM_DELTA_SUPPORTED
NRF_CLOUD_FOTA_TYPE_MODEM_FULL_SUPPORTED

menuconfig NRF_CLOUD_SEND_SERVICE_INFO_UI
bool "Send UI service info initial connection"
help
Add supported UI types to the "serviceInfo" section.
The UI types control which cards are displayed on nRF Cloud in the device page.
Common types are enabled by default.

if NRF_CLOUD_SEND_SERVICE_INFO_UI

config NRF_CLOUD_ENABLE_SVC_INF_UI_MAP
bool "Enable map card on nRF Cloud"
default y

config NRF_CLOUD_ENABLE_SVC_INF_UI_RSRP
bool "Enable RSRP card on nRF Cloud"
default y if NRF_MODEM_LIB

config NRF_CLOUD_ENABLE_SVC_INF_UI_LOGS
bool "Enable log card on nRF Cloud"
default y if NRF_CLOUD_LOG_TEXT_LOGGING_ENABLED

config NRF_CLOUD_ENABLE_SVC_INF_UI_BIN_LOGS
bool "Enable binary (dictionary-based) log card on nRF Cloud"
default y if NRF_CLOUD_LOG_DICTIONARY_LOGGING_ENABLED

config NRF_CLOUD_ENABLE_SVC_INF_UI_TEMP
bool "Enable temperature card on nRF Cloud"

config NRF_CLOUD_ENABLE_SVC_INF_UI_HUMID
bool "Enable humidity card on nRF Cloud"

config NRF_CLOUD_ENABLE_SVC_INF_UI_AIR_PRESSURE
bool "Enable air pressure card on nRF Cloud"

config NRF_CLOUD_ENABLE_SVC_INF_UI_AIR_QUALITY
bool "Enable air quality card on nRF Cloud"

config NRF_CLOUD_ENABLE_SVC_INF_UI_ORIENTATION
bool "Enable orientation (flip) card on nRF Cloud"

endif # NRF_CLOUD_SEND_SERVICE_INFO_UI

endif # NRF_CLOUD_MQTT || NRF_CLOUD_COAP

config NRF_CLOUD_SEND_SHADOW_INFO
bool
default y if (NRF_CLOUD_SEND_DEVICE_STATUS || \
NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK || \
NRF_CLOUD_SEND_DEVICE_STATUS_SIM || \
NRF_CLOUD_SEND_DEVICE_STATUS_CONN_INF || \
NRF_CLOUD_SEND_SERVICE_INFO_FOTA || \
NRF_CLOUD_SEND_SERVICE_INFO_UI)
help
This symbol is y when at least one option to send an info section is enabled.

endmenu
Loading
Loading