Skip to content

Commit 1cd95a3

Browse files
committed
Fix task notification
Signed-off-by: Luca Arato <[email protected]>
1 parent 4df73a2 commit 1cd95a3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

examples/edgehog_app/edgehog_partition_example.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# ESP-IDF Partition Table
2323
# Name, Type, SubType, Offset, Size, Flags
24+
nvs, data, nvs, 0x9000, 0x4000,
2425
otadata, data, ota, 0xd000, 0x2000,
2526
phy_init, data, phy, 0xf000, 0x1000,
2627
factory, app, factory, , 0x12c000,

examples/edgehog_app/main/src/example_task.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ static edgehog_device_handle_t edgehog_device;
4747
/**
4848
* @brief Initialize an Astarte device.
4949
*
50+
* @param notify_handle Task to be notified when the device gets connected.
5051
* @return The Astarte device instance handle.
5152
*/
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);
5354
/**
5455
* @brief Initialize an Edgehog device and starts the associated astarte device.
5556
*
@@ -93,7 +94,8 @@ static void astarte_disconnection_events_handler(astarte_device_disconnection_ev
9394

9495
void edgehog_example_task(void *ctx)
9596
{
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);
9799
assert(astarte_handle);
98100
edgehog_device_handle_t edgehog_device = edgehog_device_init(astarte_handle);
99101
assert(edgehog_device);
@@ -103,9 +105,10 @@ void edgehog_example_task(void *ctx)
103105
ESP_LOGE(TAG, "Failed starting the Astarte device.");
104106
return;
105107
}
106-
// Wait until the Astarte device is connected
108+
109+
// Wait until the Astarte device is connected and the current task gets notified
107110
(void) ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
108-
ESP_LOGI(TAG, "Astarte device started");
111+
ESP_LOGI(TAG, "Astarte device started and connected, starting edgehog device...");
109112

110113
// Start the Edgehog device
111114
edgehog_err_t edgehog_err = edgehog_device_start(edgehog_device);
@@ -125,7 +128,7 @@ void edgehog_example_task(void *ctx)
125128
* Static functions definitions
126129
***********************************************/
127130

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)
129132
{
130133
// Set up storage for the Astarte device
131134
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)
143146
.connection_event_callback = astarte_connection_events_handler,
144147
.disconnection_event_callback = astarte_disconnection_events_handler,
145148
.data_event_callback = astarte_data_events_handler,
149+
.callbacks_user_data = notify_handle,
146150
};
147151

148152
astarte_device_handle_t astarte_device = astarte_device_init(&astarte_device_cfg);
@@ -226,6 +230,8 @@ static void edgehog_event_handler(
226230
static void astarte_connection_events_handler(astarte_device_connection_event_t *event)
227231
{
228232
ESP_LOGI(TAG, "Astarte device connected, session_present: %d", event->session_present);
233+
// notifying the passed task
234+
xTaskNotifyGive(event->user_data);
229235
}
230236

231237
static void astarte_data_events_handler(astarte_device_data_event_t *event)

0 commit comments

Comments
 (0)