From 9a46911a497fe22ac87c59bb6b1d733c77f65bd8 Mon Sep 17 00:00:00 2001 From: Georges Oates_Larsen Date: Tue, 1 Aug 2023 14:27:54 -0700 Subject: [PATCH] samples: cellular: multi_service: Support Wi-Fi connectivity Adds overlay to use Wi-Fi conn_mgr layer instead of LTE conn_mgr layer. Also removes a couple remaining dependencies on the nrf9160 modem. IRIS-4800 Signed-off-by: Georges Oates_Larsen --- .../releases/release-notes-changelog.rst | 19 ++- .../overlay_nrf7002ek_wifi_no_lte.conf | 126 ++++++++++++++++++ .../src/cloud_connection.c | 3 +- .../src/fota_support.c | 2 + .../src/location_tracking.c | 20 ++- 5 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 samples/cellular/nrf_cloud_multi_service/overlay_nrf7002ek_wifi_no_lte.conf diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 6e26ac42f1bd..0d7cce23a864 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -323,13 +323,20 @@ Cellular samples (renamed from nRF9160 samples) * :ref:`nrf_cloud_multi_service` sample: * Renamed Cellular: nRF Cloud MQTT multi-service to Cellular: nRF Cloud multi-service. - * Added documentation for using the :ref:`lib_nrf_cloud_alert` and :ref:`lib_nrf_cloud_log` libraries. - * Changed the :file:`overlay_nrfcloud_logging.conf` file to enable JSON logs by default. - * The :c:struct:`nrf_cloud_obj` structure and associated functions are now used to encode and decode nRF Cloud data. - * Cleaned up and simplified connection logic. - * Switched from using the :ref:`lte_lc_readme` library directly to using Zephyr's ``conn_mgr`` and the :kconfig:option:`CONFIG_LTE_CONNECTIVITY` Kconfig option. + * Added: + + * Documentation for using the :ref:`lib_nrf_cloud_alert` and :ref:`lib_nrf_cloud_log` libraries. + * An overlay that allows the sample to be used with Wi-Fi instead of LTE. + * The :file:`overlay_coap.conf` file and made changes to the sample to enable the use of CoAP instead of MQTT to connect with nRF Cloud. + + * Updated: + + * The :file:`overlay_nrfcloud_logging.conf` file to enable JSON logs by default. + * The encoding and decoding of nRF Cloud data to use the :c:struct:`nrf_cloud_obj` structure and associated functions. + * The connection logic by cleaning and simplifying it. + * From using the :ref:`lte_lc_readme` library directly to using Zephyr's ``conn_mgr`` and the :kconfig:option:`CONFIG_LTE_CONNECTIVITY` Kconfig option. + * Removed the Kconfig options :kconfig:option:`CONFIG_LTE_INIT_RETRY_TIMEOUT_SECONDS` and :kconfig:option:`CLOUD_CONNECTION_REESTABLISH_DELAY_SECONDS` as they are no longer needed. - * Added the :file:`overlay_coap.conf` file and made changes to the sample to enable the use of CoAP instead of MQTT to connect with nRF Cloud. * :ref:`http_application_update_sample` sample: diff --git a/samples/cellular/nrf_cloud_multi_service/overlay_nrf7002ek_wifi_no_lte.conf b/samples/cellular/nrf_cloud_multi_service/overlay_nrf7002ek_wifi_no_lte.conf new file mode 100644 index 000000000000..95efac30a114 --- /dev/null +++ b/samples/cellular/nrf_cloud_multi_service/overlay_nrf7002ek_wifi_no_lte.conf @@ -0,0 +1,126 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Note that this overlay is not compatible with nrf9160! Use something such as the nrf5340 as the +# host microcontroller. + +## Disable Modem/LTE/nrf91-specific features +CONFIG_NRF_MODEM_LIB=n +CONFIG_MODEM_INFO=n +CONFIG_MODEM_INFO_ADD_NETWORK=n +CONFIG_AT_HOST_LIBRARY=n +CONFIG_LTE_LINK_CONTROL=n + +## Disable offloaded sockets (we are going to switch to the native networking stack) +CONFIG_NET_SOCKETS_OFFLOAD=n + +## Disable cloud features reliant on or specific to nrf91 modem features +CONFIG_NRF_CLOUD_AGPS=n +CONFIG_NRF_CLOUD_PGPS=n +CONFIG_NRF_CLOUD_PGPS_REQUEST_UPON_INIT=n +CONFIG_LOCATION_METHOD_GNSS=n +CONFIG_LOCATION_METHOD_CELLULAR=n + +## Disable FOTA to conserve memory +CONFIG_NRF_CLOUD_FOTA=n +CONFIG_BOOTLOADER_MCUBOOT=n +CONFIG_IMG_MANAGER=n +CONFIG_MCUBOOT_IMG_MANAGER=n + +## Disable LTE-event-driven date_time updates (the date_time library will still periodically +## refresh its timestamp, this setting only controls whether LTE-event-driven date_time updates +## are enabled) +CONFIG_DATE_TIME_AUTO_UPDATE=n + +## Disable LED patterns since enabling WiFi shield takes control of two LEDs +CONFIG_LED_INDICATION_DISABLED=y + +## Disable LTE conn_mgr bindings +CONFIG_LTE_CONNECTIVITY=n + +## These had to be disabled for LTE with conn_mgr, but there is no reason to disable them for +## wifi with conn_mgr, so re-enable them. +CONFIG_NET_IPV6_NBR_CACHE=y +CONFIG_NET_IPV6_MLD=y +CONFIG_DNS_RESOLVER=y + +## Enable Wi-Fi drivers, (and the native NET stack so that the location library can access them) +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y + +## Enable Wi-Fi conn_mgr bindings +CONFIG_L2_WIFI_CONNECTIVITY=y +CONFIG_NET_CONNECTION_MANAGER_STACK_SIZE=4096 + +## Enable WIFI_MGMT_EXT and WIFI_CREDENTIALS for simplified Wi-Fi connection setup +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_MGMT_EXT=y +CONFIG_WIFI_CREDENTIALS_BACKEND_SETTINGS=y + +## Use compile-time client ID for nRF Cloud +CONFIG_NRF_CLOUD_CLIENT_ID_SRC_COMPILE_TIME=y + +## Enable flash and NVS settings, required by WIFI_CREDENTIALS +CONFIG_SETTINGS=y +CONFIG_SETTINGS_NVS=y +CONFIG_NVS=y +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_MAP=y + +## Enable Wi-Fi networking and native networking stack +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y +CONFIG_NET_NATIVE=y +CONFIG_NRF_SECURITY=y +CONFIG_NET_SOCKETS_SOCKOPT_TLS=y +CONFIG_NET_CONTEXT_SNDTIMEO=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_WORKQ_STACK_SIZE=2048 +CONFIG_NET_DHCPV4=y + +## Configure native MBEDTLS to support nRF Cloud MQTT +CONFIG_MQTT_LIB_TLS=y +CONFIG_MBEDTLS=y +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_RSA_C=y +CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y +CONFIG_MBEDTLS_HEAP_SIZE=120000 + +## Enable Wi-Fi location tracking +CONFIG_LOCATION_TRACKING_WIFI=y +CONFIG_LOCATION_METHOD_WIFI=y +# Align this with CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT. +# Also see comments for CONFIG_HEAP_MEM_POOL_SIZE. +# We set this to 30 in this overlay (as opposed to 60 in the wifi-scan-only overlay) so that +# CONFIG_HEAP_MEM_POOL_SIZE can be small enough to leave at least 24kB of unused RAM in the final +# build, which is required by WPA_supp +CONFIG_NRF700X_SCAN_LIMIT=30 +CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT=30 + +## Enable shell and WIFI_CREDENTIALS shell +CONFIG_SHELL=y +CONFIG_WIFI_CREDENTIALS_SHELL=y +# Increased stack size needed for wifi_cred auto_connect command +CONFIG_SHELL_STACK_SIZE=4096 + +## Resource allocation tweaks needed to support Wi-Fi. +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096 +CONFIG_NRF_CLOUD_CONNECTION_POLL_THREAD_STACK_SIZE=8192 +CONFIG_APPLICATION_THREAD_STACK_SIZE=3072 +CONFIG_MESSAGE_THREAD_STACK_SIZE=3072 +CONFIG_DATE_TIME_THREAD_STACK_SIZE=2048 +CONFIG_NET_TX_STACK_SIZE=2048 +CONFIG_NET_RX_STACK_SIZE=2048 +CONFIG_POSIX_MAX_FDS=16 +CONFIG_NET_SOCKETS_POLL_MAX=8 +# Heap allocation should be changed when CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT +# and CONFIG_NRF700X_SCAN_LIMIT (which should be the same value) are changed. With the limit at 30, +# this could be set as low as 130000. Add 256 bytes for each additional scanning result, assuming +# sane SSID lengths. We set the heap much higher in case of long SSIDs. +CONFIG_HEAP_MEM_POOL_SIZE=130000 diff --git a/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c b/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c index 50c2db0af1ec..17a9d90c666a 100644 --- a/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c +++ b/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -274,6 +273,8 @@ static void l4_event_handler(struct net_mgmt_event_callback *cb, if (event == NET_EVENT_L4_CONNECTED) { LOG_INF("Network connectivity gained!"); + k_sleep(K_MSEC(1000)); + /* Set the network ready flag */ k_event_post(&cloud_events, NETWORK_READY); diff --git a/samples/cellular/nrf_cloud_multi_service/src/fota_support.c b/samples/cellular/nrf_cloud_multi_service/src/fota_support.c index f2af9100b071..539c94953c2b 100644 --- a/samples/cellular/nrf_cloud_multi_service/src/fota_support.c +++ b/samples/cellular/nrf_cloud_multi_service/src/fota_support.c @@ -19,9 +19,11 @@ void fota_reboot(const unsigned int delay_s, const bool error) { LOG_INF("Rebooting in %us%s", delay_s, error ? " due to error" : "..."); +#if defined(CONFIG_LTE_LINK_CONTROL) if (error) { (void)lte_lc_deinit(); } +#endif LOG_PANIC(); k_sleep(K_SECONDS(delay_s)); diff --git a/samples/cellular/nrf_cloud_multi_service/src/location_tracking.c b/samples/cellular/nrf_cloud_multi_service/src/location_tracking.c index d2b368dcb8fc..035c9befca36 100644 --- a/samples/cellular/nrf_cloud_multi_service/src/location_tracking.c +++ b/samples/cellular/nrf_cloud_multi_service/src/location_tracking.c @@ -47,6 +47,19 @@ static void location_event_handler(const struct location_event_data *event_data) } } +static void enable_modem_gnss(void) +{ + if (IS_ENABLED(CONFIG_LTE_LINK_CONTROL)) { + int err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_GNSS); + + if (err) { + LOG_ERR("Activating GNSS failed, error: %d. Continuing without GNSS", err); + } + } else { + LOG_WRN("CONFIG_LTE_LINK_CONTROL must be enabled in order to use GNSS"); + } +} + int start_location_tracking(location_update_cb_t handler_cb, int interval) { int err; @@ -57,10 +70,9 @@ int start_location_tracking(location_update_cb_t handler_cb, int interval) LOG_WRN("Date and time unknown. Location Services results may suffer"); } - /* Enable GNSS on the modem */ - err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_GNSS); - if (err) { - LOG_ERR("Activating GNSS failed, error: %d. Continuing without GNSS", err); + /* Enable GNSS on the modem if appropriate */ + if (IS_ENABLED(CONFIG_LOCATION_TRACKING_GNSS)) { + enable_modem_gnss(); } /* Update the location update handler. */