@@ -47,9 +47,10 @@ static edgehog_device_handle_t edgehog_device;
47
47
/**
48
48
* @brief Initialize an Astarte device.
49
49
*
50
+ * @param notify_handle Task to be notified when the device gets connected.
50
51
* @return The Astarte device instance handle.
51
52
*/
52
- static astarte_device_handle_t astarte_device_sdk_init (void );
53
+ static astarte_device_handle_t astarte_device_sdk_init (TaskHandle_t notify_handle );
53
54
/**
54
55
* @brief Initialize an Edgehog device and starts the associated astarte device.
55
56
*
@@ -93,7 +94,8 @@ static void astarte_disconnection_events_handler(astarte_device_disconnection_ev
93
94
94
95
void edgehog_example_task (void * ctx )
95
96
{
96
- astarte_device_handle_t astarte_handle = astarte_device_sdk_init ();
97
+ TaskHandle_t current_task_handle = xTaskGetCurrentTaskHandle ();
98
+ astarte_device_handle_t astarte_handle = astarte_device_sdk_init (current_task_handle );
97
99
assert (astarte_handle );
98
100
edgehog_device_handle_t edgehog_device = edgehog_device_init (astarte_handle );
99
101
assert (edgehog_device );
@@ -103,9 +105,10 @@ void edgehog_example_task(void *ctx)
103
105
ESP_LOGE (TAG , "Failed starting the Astarte device." );
104
106
return ;
105
107
}
106
- // Wait until the Astarte device is connected
108
+
109
+ // Wait until the Astarte device is connected and the current task gets notified
107
110
(void ) ulTaskNotifyTake (pdTRUE , portMAX_DELAY );
108
- ESP_LOGI (TAG , "Astarte device started" );
111
+ ESP_LOGI (TAG , "Astarte device started and connected, starting edgehog device... " );
109
112
110
113
// Start the Edgehog device
111
114
edgehog_err_t edgehog_err = edgehog_device_start (edgehog_device );
@@ -125,7 +128,7 @@ void edgehog_example_task(void *ctx)
125
128
* Static functions definitions
126
129
***********************************************/
127
130
128
- static astarte_device_handle_t astarte_device_sdk_init (void )
131
+ static astarte_device_handle_t astarte_device_sdk_init (TaskHandle_t notify_handle )
129
132
{
130
133
// Set up storage for the Astarte device
131
134
if (astarte_credentials_use_nvs_storage (ASTARTE_PARTITION_NAME ) != ASTARTE_OK ) {
@@ -143,6 +146,7 @@ static astarte_device_handle_t astarte_device_sdk_init(void)
143
146
.connection_event_callback = astarte_connection_events_handler ,
144
147
.disconnection_event_callback = astarte_disconnection_events_handler ,
145
148
.data_event_callback = astarte_data_events_handler ,
149
+ .callbacks_user_data = notify_handle ,
146
150
};
147
151
148
152
astarte_device_handle_t astarte_device = astarte_device_init (& astarte_device_cfg );
@@ -226,6 +230,8 @@ static void edgehog_event_handler(
226
230
static void astarte_connection_events_handler (astarte_device_connection_event_t * event )
227
231
{
228
232
ESP_LOGI (TAG , "Astarte device connected, session_present: %d" , event -> session_present );
233
+ // notifying the passed task
234
+ xTaskNotifyGive (event -> user_data );
229
235
}
230
236
231
237
static void astarte_data_events_handler (astarte_device_data_event_t * event )
0 commit comments