Skip to content

Commit 7b8828a

Browse files
committed
Support for new OTA interfaces
Signed-off-by: Simone Orru <simone.orru@secomind.com>
1 parent 4c509e8 commit 7b8828a

File tree

9 files changed

+500
-269
lines changed

9 files changed

+500
-269
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
matrix:
3333
idf-version:
34-
- "4.3"
34+
- "4.4.4"
3535
- "5.0.1"
3636
build-system:
3737
- idf

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [0.7.0] - Unreleased
88
### Added
99
- Add support to ESP-IDF v5.0.
10+
- Add support for `io.edgehog.devicemanager.OTAEvent` interface.
11+
- Add support for update/cancel operation in `io.edgehog.devicemanager.OTARequest` interface.
12+
13+
### Removed
14+
- Remove support for `io.edgehog.devicemanager.OTAResponse` interface.
1015

1116
### Fixed
1217
- Fix GPIO still active issue after execution of LedBehavior routine.

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Create a new `idf_component.yml` in the project root directory, as follows:
4040
## IDF Component Manager Manifest File
4141
dependencies:
4242
idf:
43-
version: ">=4.1.0"
43+
version: ">=4.4.4"
4444
edgehog-esp32-device:
4545
version: "*" # this is the latest commit on the main branch
4646
git: https://github.com/edgehog-device-manager/edgehog-esp32-device.git
@@ -56,6 +56,38 @@ dependencies:
5656
idf.py build
5757
```
5858

59+
## Component Free RTOS APIs usage
60+
61+
The Edgehog ESP32 Device interacts internally with the Free RTOS APIs. As such some factors
62+
should be taken into account when integrating this component in a larger system.
63+
64+
The following **tasks** are spawned directly by the Edgehog ESP32 Device:
65+
- `BLINK TASK`: Provides functionality for visual feedback using an on board LED.
66+
It is only spawned if `CONFIG_INDICATOR_GPIO_ENABLE` is set in the Edgehog ESP32 device
67+
configuration, will use `2048` words from the stack, and can be triggered by a publish from the
68+
Astarte cluster to the dedicated LED interface. This task has a fixed duration and will be deleted
69+
at timeout.
70+
- `OTA UPDATE TASK`: Provides functionality for OTA updates.
71+
It will use `4096` words from the stack, and can be triggered by a publish from the
72+
Astarte cluster to the dedicated OTA update interface. This task does not have a fixed duration, it
73+
will run untill a successful OTA update has been downloaded and flashed or the procedure failed.
74+
Note that the OTA update task could restart the device.
75+
76+
All of the tasks are spawned with the lowest priority and rely on the time slicing functionality
77+
of freertos to run concurrently with the main task.
78+
79+
Other than tasks, a certain number of **software timers** are also created to be used for telemetry.
80+
The actual number of timers that this component is going to use will depend on the
81+
telemetry configuration of your project. Each telemetry type will create a separate timer.
82+
Software timers run all in a single task instantiated by freertos. The stack size and priority for
83+
such task should be configured in the project using this component.
84+
This module has been tested using `2048` words for the stack size and a priority of `1` for the
85+
timer task.
86+
87+
In addition to what stated above, this component requires an Astarte ESP32 Device to be externally
88+
instantiated and provided in its configuration struct. The Astarte ESP32 Device interacts internally
89+
with the Free RTOS APIs and its resource usage should be evaluated separately.
90+
5991
## Resources
6092

6193
* [ESP32 Component Documentation](https://edgehog-device-manager.github.io/docs/snapshot/device-sdks/esp32/)

include/edgehog.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ typedef enum
4141
EDGEHOG_ERR = 1, /**< A generic error occurred. This is usually an internal error in the SDK */
4242
EDGEHOG_ERR_NETWORK = 2, /**< A generic network error occurred. */
4343
EDGEHOG_ERR_NVS = 3, /**< A generic error occurred when dealing with NVS */
44-
EDGEHOG_ERR_OTA_ALREADY_IN_PROGRESS = 4, /**< Attempted to perform OTA operation while there is another one already active*/
45-
EDGEHOG_ERR_OTA_FAILED = 5, /**< An error occurred during OTA procedure */
46-
EDGEHOG_ERR_OTA_DEPLOY = 6, /**< An error occurred during OTA Deploy procedure */
47-
EDGEHOG_ERR_OTA_WRONG_PARTITION = 7, /**< The OTA procedure boot on the wrong partition */
48-
EDGEHOG_ERR_TASK_CREATE = 8, /**< xTaskCreate was unable to spawn a new task */
49-
EDGEHOG_ERR_DEVICE_NOT_READY = 9, /**< Tried to perform an operation on a Device in a non-ready or initialized state */
44+
EDGEHOG_ERR_OTA_INVALID_REQUEST = 4, /**< Invalid OTA update request received */
45+
EDGEHOG_ERR_OTA_ALREADY_IN_PROGRESS = 5, /**< Attempted to perform OTA operation while there is another one already active*/
46+
EDGEHOG_ERR_OTA_INVALID_IMAGE = 6, /**< Invalid OTA image received */
47+
EDGEHOG_ERR_OTA_SYSTEM_ROLLBACK = 7, /**< The OTA procedure boot on the wrong partition */
48+
EDGEHOG_ERR_OTA_CANCELED = 8, /**< OTA update aborted by Edgehog half way during the procedure */
49+
EDGEHOG_ERR_OTA_INTERNAL = 9, /**< An error occurred during OTA procedure */
50+
EDGEHOG_ERR_TASK_CREATE = 10, /**< xTaskCreate was unable to spawn a new task */
51+
EDGEHOG_ERR_DEVICE_NOT_READY = 11, /**< Tried to perform an operation on a Device in a non-ready or initialized state */
5052
}edgehog_err_t;
5153

5254
// clang-format on

private/edgehog_ota.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,31 @@ extern "C" {
2828
#include "edgehog_device.h"
2929

3030
extern const astarte_interface_t ota_request_interface;
31-
extern const astarte_interface_t ota_response_interface;
31+
extern const astarte_interface_t ota_event_interface;
3232

3333
/**
3434
* @brief initialize Edgehog device OTA.
3535
*
3636
* @details This function initializes the OTA procedure and
3737
* if there is any pending OTA it completes it.
3838
*
39-
* @param edgehog_device A valid Edgehog device handle.
39+
* @param edgehog_dev A valid Edgehog device handle.
4040
*/
41-
42-
void edgehog_ota_init(edgehog_device_handle_t edgehog_device);
41+
void edgehog_ota_init(edgehog_device_handle_t edgehog_dev);
4342

4443
/**
4544
* @brief receive Edgehog device OTA.
4645
*
47-
* @details This function receives an OTA event request from Astarte,
48-
* internally call do_ota function which is blocking, the calling
49-
* task will be blocked until the OTA procedure completes.
46+
* @details This function receives an OTA event request from Astarte. This function may spawn a
47+
* new task to preform the OTA update.
5048
*
51-
* @param edgehog_device A valid Edgehog device handle.
49+
* @param edgehog_dev A valid Edgehog device handle.
5250
* @param event_request A valid Astarte device data event.
5351
*
5452
* @return EDGEHOG_OK if the OTA event is handled successfully, an edgehog_err_t otherwise.
5553
*/
56-
5754
edgehog_err_t edgehog_ota_event(
58-
edgehog_device_handle_t edgehog_device, astarte_device_data_event_t *event_request);
55+
edgehog_device_handle_t edgehog_dev, astarte_device_data_event_t *event_request);
5956

6057
#ifdef __cplusplus
6158
}

src/edgehog_device.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include <esp_timer.h>
4343
#include <esp_wifi.h>
4444
#include <esp_wifi_types.h>
45-
#include <freertos/FreeRTOS.h>
46-
#include <freertos/task.h>
4745
#include <string.h>
4846
#include <uuid.h>
4947

@@ -118,13 +116,9 @@ void edgehog_device_astarte_event_handler(
118116
}
119117

120118
if (strcmp(event->interface_name, ota_request_interface.name) == 0) {
121-
// Beware this function blocks the caller until OTA is completed.
122119
edgehog_err_t ota_result = edgehog_ota_event(edgehog_device, event);
123-
if (ota_result == EDGEHOG_OK) {
124-
ESP_LOGI(TAG, "OTA Deploy end successfully, device restart in 5 seconds");
125-
vTaskDelay(pdMS_TO_TICKS(5000));
126-
ESP_LOGI(TAG, "Device restart");
127-
esp_restart();
120+
if (ota_result != EDGEHOG_OK) {
121+
ESP_LOGE(TAG, "Unable to handle OTA update request");
128122
}
129123
} else if (strcmp(event->interface_name, commands_interface.name) == 0) {
130124
if (edgehog_command_event(event) != EDGEHOG_OK) {
@@ -233,7 +227,7 @@ esp_err_t add_interfaces(astarte_device_handle_t device)
233227
&wifi_scan_result_interface,
234228
&system_info_interface,
235229
&ota_request_interface,
236-
&ota_response_interface,
230+
&ota_event_interface,
237231
&storage_usage_interface,
238232
&battery_status_interface,
239233
&commands_interface,

src/edgehog_led.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static edgehog_err_t set_led_behavior(
153153
led_manager->current_config->default_behavior = led_manager->default_behavior;
154154
led_manager->current_config->terminated = false;
155155

156-
BaseType_t ret = xTaskCreate(blinkTaskCode, "NAME", STACK_SIZE, led_manager->current_config,
157-
tskIDLE_PRIORITY, &led_manager->task_handle);
156+
BaseType_t ret = xTaskCreate(blinkTaskCode, "BLINK TASK", STACK_SIZE,
157+
led_manager->current_config, tskIDLE_PRIORITY, &led_manager->task_handle);
158158

159159
if (ret != pdPASS) {
160160
free(led_manager->current_config);

0 commit comments

Comments
 (0)