Skip to content

Commit

Permalink
net: lib: nrf_cloud: Separate cloud info by state
Browse files Browse the repository at this point in the history
Some nRF Cloud connection information is available regardless
of whether the device has successfully connected, whereas
other information is only available post-connection.

Separate out the post-connection info into a new function, and
call it at the appropriate time in the nrf_cloud_multi_service
sample.

Jira: IRIS-9653

Signed-off-by: Pete Skeggs <[email protected]>
  • Loading branch information
plskeggs committed Sep 25, 2024
1 parent cf2cc23 commit 2e0719a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Cellular samples

* The :kconfig:option:`CONFIG_TEST_COUNTER_MULTIPLIER` Kconfig option to multiply the number of test counter messages sent, for testing purposes.
* A handler for new nRF Cloud event type ``NRF_CLOUD_EVT_RX_DATA_DISCON`` to stop sensors and location services.
* A call to the :c:func:`nrf_cloud_print_details` function and removed redundant logging.
* A call to the :c:func:`nrf_cloud_print_details` and :c:func:`nrf_cloud_print_cloud_details` functions and removed redundant logging.
* Board support files to enable Wi-Fi scanning for the Thingy:91 X.

* Updated:
Expand Down Expand Up @@ -782,8 +782,8 @@ Libraries for networking
* The function :c:func:`nrf_cloud_client_id_runtime_set` to set the device ID string if the :kconfig:option:`CONFIG_NRF_CLOUD_CLIENT_ID_SRC_RUNTIME` Kconfig option is enabled.
* The functions :c:func:`nrf_cloud_sec_tag_set` and :c:func:`nrf_cloud_sec_tag_get` to set and get the sec tag used for nRF Cloud credentials.
* A new nRF Cloud event type ``NRF_CLOUD_EVT_RX_DATA_DISCON`` which is generated when a device is deleted from nRF Cloud.
* The function :c:func:`nrf_cloud_print_details` to log common nRF Cloud connection information in a uniform way.
* The :kconfig:option:`CONFIG_NRF_CLOUD_VERBOSE_DETAILS` Kconfig option to enable the :c:func:`nrf_cloud_print_details` function to print all details instead of only the device ID.
* The functions :c:func:`nrf_cloud_print_details` and :c:func:`nrf_cloud_print_cloud_details` to log common nRF Cloud connection information in a uniform way.
* The :kconfig:option:`CONFIG_NRF_CLOUD_VERBOSE_DETAILS` Kconfig option to enable the above functions to print all details instead of only the device ID.

* Updated:

Expand Down
14 changes: 14 additions & 0 deletions include/net/nrf_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,20 @@ int nrf_cloud_uninit(void);
*/
int nrf_cloud_print_details(void);

/**
* @brief Print details about cloud connection after connected.
*
* Some information is only available after the device is connected.
* When using MQTT the stage and the tenant will be printed.
* Call this function after your cloud event handler receives the first
* NRF_CLOUD_EVT_RX_DATA_SHADOW event.
*
* When using CoAP and REST there is no further information to print.
*
* @return A negative value indicates an error.
*/
int nrf_cloud_print_cloud_details(void);

/**
* @brief Retrieve the IMEI.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static bool connect_cloud(void)
/* Clear the disconnected flag, no longer accurate. */
k_event_clear(&cloud_events, CLOUD_DISCONNECTED);

nrf_cloud_print_details();
(void)nrf_cloud_print_details();

#if defined(CONFIG_NRF_CLOUD_MQTT)
/* Connect to nRF Cloud -- Non-blocking. State updates are handled in callbacks. */
Expand Down Expand Up @@ -467,7 +467,7 @@ static void cloud_event_handler(const struct nrf_cloud_evt *nrf_cloud_evt)
* device's shadow based on the build configuration.
* See config NRF_CLOUD_SEND_SHADOW_INFO for details.
*/

(void)nrf_cloud_print_cloud_details();
break;
case NRF_CLOUD_EVT_SENSOR_DATA_ACK:
LOG_DBG("NRF_CLOUD_EVT_SENSOR_DATA_ACK");
Expand Down
30 changes: 16 additions & 14 deletions subsys/net/lib/nrf_cloud/src/nrf_cloud_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ int nrf_cloud_print_details(void)
err = nrf_cloud_get_imei(buf, sizeof(buf));
if (!err) {
LOG_INF("IMEI: %s", buf);
} else {
} else if (err != -ENOTSUP) {
LOG_ERR("Error requesting the IMEI: %d", err);
}
err = nrf_cloud_get_uuid(buf, sizeof(buf));
if (!err) {
LOG_INF("UUID: %s", buf);
} else {
} else if (err != -ENOTSUP) {
LOG_ERR("Error requesting the UUID: %d", err);
}
err = nrf_cloud_get_modem_fw(buf, sizeof(buf));
if (!err) {
LOG_INF("Modem FW: %s", buf);
} else {
} else if (err != -ENOTSUP) {
LOG_ERR("Error requesting the modem fw version: %d", err);
}

Expand All @@ -140,25 +140,27 @@ int nrf_cloud_print_details(void)
LOG_INF("Sec tag: %d", nrf_cloud_sec_tag_get());
LOG_INF("Host name: %s", host_name);

/* Tenant will not be known unless device is connected to cloud with MQTT. */
#endif /* CONFIG_NRF_CLOUD_VERBOSE_DETAILS */

return err;
}

int nrf_cloud_print_cloud_details(void)
{
int err = 0;
#if defined(CONFIG_NRF_CLOUD_VERBOSE_DETAILS)

#if defined(CONFIG_NRF_CLOUD_MQTT)
char stage[NRF_CLOUD_STAGE_ID_MAX_LEN];
char tenant[NRF_CLOUD_TENANT_ID_MAX_LEN];

err = nct_stage_get(stage, sizeof(stage));
if (!err) {
LOG_INF("Stage: %s", stage);
} else {
LOG_ERR("Error determining nRF Cloud stage: %d", err);
}
err = nct_tenant_id_get(tenant, sizeof(tenant));
if (!err) {
LOG_INF("Team ID: %s", tenant);
LOG_INF("Team ID: %s", tenant);
} else {
LOG_ERR("Error determining team ID: %d", err);
LOG_ERR("Error determining Team ID: %d", err);
}
#endif
#endif /* CONFIG_NRF_CLOUD_VERBOSE_DETAILS */

#endif
return err;
}

0 comments on commit 2e0719a

Please sign in to comment.