Skip to content

Commit 7dd62e2

Browse files
pascal-nordicrlubos
authored andcommitted
samples: cellular: mss: Fix for sporadically connection failure
conn_mgr event callback registration was called after triggering the connection which sporadically lead to hang waiting for a valid connection. IRIS-10183 Signed-off-by: Pascal Hernandez <[email protected]>
1 parent ad738e5 commit 7dd62e2

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ Cellular samples
378378
* Support for environment evaluation using the ``link enveval`` command.
379379
* Support for NTN NB-IoT to the ``link sysmode`` and ``link edrx`` commands.
380380

381+
* :ref:`nrf_cloud_multi_service` sample:
382+
383+
* Fixed an issue where sporadically the application was stuck waiting for the device to connect to the internet.
384+
This was due to wrong :ref:`Connection Manager <zephyr:conn_mgr_overview>` initialization.
385+
381386
Cryptography samples
382387
--------------------
383388

samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ LOG_MODULE_REGISTER(cloud_connection, CONFIG_MULTI_SERVICE_LOG_LEVEL);
3636
#define CLOUD_READY BIT(2)
3737
#define CLOUD_DISCONNECTED BIT(3)
3838
#define DATE_TIME_KNOWN BIT(4)
39+
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
3940
static K_EVENT_DEFINE(cloud_events);
4041

4142
/* Atomic status flag tracking whether an initial association is in progress. */
@@ -550,7 +551,7 @@ static void cloud_event_handler(const struct nrf_cloud_evt *nrf_cloud_evt)
550551
#endif /* CONFIG_NRF_CLOUD_MQTT */
551552

552553
/**
553-
* @brief Set up for the nRF Cloud connection (without connecting)
554+
* @brief Set up for the nRF Cloud connection
554555
*
555556
* Sets up required event hooks and initializes the nrf_cloud library.
556557
*
@@ -560,24 +561,6 @@ static int setup_cloud(void)
560561
{
561562
int err;
562563

563-
/* Register to be notified of network availability changes.
564-
*
565-
* If the chosen connectivity layer becomes ready instantaneously, it is possible that
566-
* L4_CONNECTED will be fired before reaching this function, in which case we will miss
567-
* the notification.
568-
*
569-
* If that is a serious concern, use SYS_INIT with priority 0 (less than
570-
* CONFIG_NET_CONNECTION_MANAGER_MONITOR_PRIORITY) to register this hook before conn_mgr
571-
* initializes.
572-
*
573-
* In reality, connectivity layers such as LTE take some time to go online, so registering
574-
* the hook here is fine.
575-
*/
576-
net_mgmt_init_event_callback(
577-
&l4_callback, l4_event_handler, NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED
578-
);
579-
net_mgmt_add_event_callback(&l4_callback);
580-
581564
/* Register to be notified when the modem has figured out the current time. */
582565
date_time_register_handler(date_time_event_handler);
583566

@@ -648,6 +631,13 @@ void cloud_connection_thread_fn(void)
648631
{
649632
long_led_pattern(LED_WAITING);
650633

634+
/* Setup handler for Zephyr NET Connection Manager events. */
635+
net_mgmt_init_event_callback(&l4_callback, l4_event_handler, L4_EVENT_MASK);
636+
net_mgmt_add_event_callback(&l4_callback);
637+
638+
/* Enable the connection manager for all interfaces and allow them to connect. */
639+
conn_mgr_all_if_up(true);
640+
651641
LOG_INF("Enabling connectivity...");
652642
conn_mgr_all_if_connect(true);
653643

0 commit comments

Comments
 (0)