Skip to content

Commit

Permalink
Merge pull request #79 from sorru94/support-to-idf-5.0
Browse files Browse the repository at this point in the history
Support to idf 5.0
  • Loading branch information
harlem88 authored Apr 3, 2023
2 parents b6b43f5 + d5e9f30 commit 13d457d
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
strategy:
matrix:
idf-version:
- 4.3
- "4.3"
- "5.0.1"
build-system:
- idf
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ examples/edgehog_app/components/astarte-device-sdk-esp32
doc/out
/examples/edgehog_app/managed_components/
/examples/edgehog_app/dependencies.lock

# VS code config
.vscode/
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0] - Unreleased
### Added
- Add support to ESP-IDF v5.0.

## [0.5.2] - 2022-06-22

## [0.5.1] - 2022-06-01
Expand All @@ -15,4 +19,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.5.0] - 2022-03-22
### Added
- Initial Edgehog release
- Initial Edgehog release.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ endif ()
idf_component_register(SRCS "${edgehog_srcs}"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "private"
REQUIRES astarte-device-sdk-esp32 nvs_flash app_update esp_https_ota)
REQUIRES astarte-device-sdk-esp32 esp_timer nvs_flash app_update esp_https_ota esp_wifi spi_flash)
2 changes: 1 addition & 1 deletion examples/edgehog_app/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void event_handler(
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_BIT);
} else if (event_base == EDGEHOG_EVENTS) {
ESP_LOGI(TAG, "EDGEHOG EVENT RECEIVED %d", event_id);
ESP_LOGI(TAG, "EDGEHOG EVENT RECEIVED %" PRIi32 "", event_id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ dependencies:
# Required IDF version
idf: ">=4.1"
astarte-device-sdk-esp32:
version: "v1.0.2"
version: "v1.1.0"
git: https://github.com/astarte-platform/astarte-device-sdk-esp32.git
14 changes: 11 additions & 3 deletions private/edgehog_device_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
extern "C" {
#endif

#include <esp_idf_version.h>

#include "edgehog_device.h"
#include "edgehog_telemetry.h"
#if CONFIG_INDICATOR_GPIO_ENABLE
Expand Down Expand Up @@ -71,13 +73,19 @@ esp_err_t edgehog_device_nvs_open(
* @param edgehog_device A valid Edgehog device handle.
* @param namespace Namespace name.
* @param type One of nvs_type_t values.
* @param it Iterator used to enumerate all the entries found,or NULL if no entry satisfying
* criteria was found. Iterator obtained through this function has to be released using
* nvs_release_iterator when not used any more.
*
* @return Iterator used to enumerate all the entries found,or NULL if no entry satisfying criteria
* was found. Iterator obtained through this function has to be released using nvs_release_iterator
* when not used any more.
* @return ESP_OK if iterator was created successfully, an esp_err_t otherwise.
*/
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
esp_err_t edgehog_device_nvs_entry_find(edgehog_device_handle_t edgehog_device,
const char *namespace, nvs_type_t type, nvs_iterator_t *it);
#else
nvs_iterator_t edgehog_device_nvs_entry_find(
edgehog_device_handle_t edgehog_device, const char *namespace, nvs_type_t type);
#endif

/**
* @brief Telemetry periodic callback type.
Expand Down
8 changes: 8 additions & 0 deletions src/edgehog_base_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ const astarte_interface_t base_image_interface = { .name = "io.edgehog.deviceman

void edgehog_base_image_data_publish(edgehog_device_handle_t edgehog_device)
{
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
const esp_app_desc_t *desc = esp_app_get_description();
#else
const esp_app_desc_t *desc = esp_ota_get_app_description();
#endif
astarte_device_handle_t astarte_device = edgehog_device->astarte_device;

astarte_err_t ret = astarte_device_set_string_property(
Expand All @@ -64,7 +68,11 @@ void edgehog_base_image_data_publish(edgehog_device_handle_t edgehog_device)
}

char sha256_str[65];
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
esp_app_get_elf_sha256(sha256_str, 65);
#else
esp_ota_get_app_elf_sha256(sha256_str, 65);
#endif
ret = astarte_device_set_string_property(
astarte_device, base_image_interface.name, "/fingerprint", sha256_str);
if (ret != ASTARTE_OK) {
Expand Down
2 changes: 1 addition & 1 deletion src/edgehog_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ edgehog_err_t edgehog_command_event(astarte_device_data_event_t *event_request)
{
EDGEHOG_VALIDATE_INCOMING_DATA(TAG, event_request, "/request", BSON_TYPE_STRING);

size_t len;
uint32_t len;
const char *command = astarte_bson_value_to_string(event_request->bson_value, &len);

if (strcmp(command, "Reboot") == 0) {
Expand Down
11 changes: 11 additions & 0 deletions src/edgehog_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "edgehog_storage_usage.h"
#include "esp_system.h"
#include <astarte_bson_serializer.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include <esp_chip_info.h>
#endif
#include <esp_err.h>
#include <esp_heap_caps.h>
#include <esp_log.h>
Expand Down Expand Up @@ -541,11 +544,19 @@ esp_err_t edgehog_device_nvs_open(
return ESP_OK;
}

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
esp_err_t edgehog_device_nvs_entry_find(edgehog_device_handle_t edgehog_device,
const char *namespace, nvs_type_t type, nvs_iterator_t *it)
{
return nvs_entry_find(edgehog_device->partition_name, namespace, type, it);
}
#else
nvs_iterator_t edgehog_device_nvs_entry_find(
edgehog_device_handle_t edgehog_device, const char *namespace, nvs_type_t type)
{
return nvs_entry_find(edgehog_device->partition_name, namespace, type);
}
#endif

telemetry_periodic edgehog_device_get_telemetry_periodic(telemetry_type_t type)
{
Expand Down
26 changes: 22 additions & 4 deletions src/edgehog_ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <esp_partition.h>
#include <freertos/task.h>
#include <nvs.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include <spi_flash_mmap.h>
#endif

#define OTA_REQ_TIMEOUT_MS (60 * 1000)
#define MAX_OTA_RETRY 5
Expand Down Expand Up @@ -98,6 +101,10 @@ static esp_err_t http_ota_event_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_DISCONNECTED:
ESP_LOGD(TAG, "DISCONNECTED");
break;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
case HTTP_EVENT_REDIRECT:
break;
#endif
}
return ESP_OK;
}
Expand Down Expand Up @@ -154,7 +161,7 @@ edgehog_err_t edgehog_ota_event(
EDGEHOG_VALIDATE_INCOMING_DATA(TAG, event_request, "/request", BSON_TYPE_DOCUMENT);

uint8_t type;
size_t str_value_len;
uint32_t str_value_len;

const void *found = astarte_bson_key_lookup("uuid", event_request->bson_value, &type);
const char *request_uuid = astarte_bson_value_to_string(found, &str_value_len);
Expand Down Expand Up @@ -216,20 +223,31 @@ static edgehog_err_t do_ota(
nvs_commit(handle);

ESP_LOGI(TAG, "DOWNLOAD_AND_DEPLOY");
esp_http_client_config_t config = {
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
esp_http_client_config_t http_config = {
.url = ota_url,
.event_handler = http_ota_event_handler,
.timeout_ms = OTA_REQ_TIMEOUT_MS,
};
esp_https_ota_config_t ota_config = {
.http_config = &http_config,
};
#else
esp_http_client_config_t ota_config = {
.url = ota_url,
.event_handler = http_ota_event_handler,
.timeout_ms = OTA_REQ_TIMEOUT_MS,
};
#endif

uint8_t attempts = 0;
// FIXME: this function is blocking
esp_ret = esp_https_ota(&config);
esp_ret = esp_https_ota(&ota_config);
while (attempts < MAX_OTA_RETRY && esp_ret != ESP_OK) {
vTaskDelay(pdMS_TO_TICKS(attempts * 2000));
attempts++;
ESP_LOGW(TAG, "! OTA FAILED, ATTEMPT #%d !", attempts);
esp_ret = esp_https_ota(&config);
esp_ret = esp_https_ota(&ota_config);
}

ESP_LOGI(TAG, "RESULT %s", esp_err_to_name(esp_ret));
Expand Down
11 changes: 11 additions & 0 deletions src/edgehog_telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,20 @@ static void load_telemetry_from_nvs(edgehog_device_handle_t edgehog_device)
return;
}

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
nvs_iterator_t it;
result = edgehog_device_nvs_entry_find(edgehog_device, TELEMETRY_NAMESPACE, NVS_TYPE_I8, &it);
if (result != ESP_OK) {
ESP_LOGW(TAG, "Unable to find telemetry in nvs, error: %s", esp_err_to_name(result));
return;
}

while (nvs_entry_next(&it)) {
#else
for (nvs_iterator_t it
= edgehog_device_nvs_entry_find(edgehog_device, TELEMETRY_NAMESPACE, NVS_TYPE_I8);
it; it = nvs_entry_next(it)) {
#endif
nvs_entry_info_t enable_entry_info;
nvs_entry_info(it, &enable_entry_info);

Expand Down

0 comments on commit 13d457d

Please sign in to comment.