@@ -36,6 +36,7 @@ LOG_MODULE_REGISTER(cloud_connection, CONFIG_MULTI_SERVICE_LOG_LEVEL);
36
36
#define CLOUD_READY BIT(2)
37
37
#define CLOUD_DISCONNECTED BIT(3)
38
38
#define DATE_TIME_KNOWN BIT(4)
39
+ #define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
39
40
static K_EVENT_DEFINE (cloud_events );
40
41
41
42
/* 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)
550
551
#endif /* CONFIG_NRF_CLOUD_MQTT */
551
552
552
553
/**
553
- * @brief Set up for the nRF Cloud connection (without connecting)
554
+ * @brief Set up for the nRF Cloud connection
554
555
*
555
556
* Sets up required event hooks and initializes the nrf_cloud library.
556
557
*
@@ -560,24 +561,6 @@ static int setup_cloud(void)
560
561
{
561
562
int err ;
562
563
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
-
581
564
/* Register to be notified when the modem has figured out the current time. */
582
565
date_time_register_handler (date_time_event_handler );
583
566
@@ -648,6 +631,13 @@ void cloud_connection_thread_fn(void)
648
631
{
649
632
long_led_pattern (LED_WAITING );
650
633
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
+
651
641
LOG_INF ("Enabling connectivity..." );
652
642
conn_mgr_all_if_connect (true);
653
643
0 commit comments