Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/esp_rainmaker/include/esp_rmaker_ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ typedef enum {

/** The OTA Handle to be used by the OTA callback */
typedef void *esp_rmaker_ota_handle_t;

/** Function Prototype for Reporting Intermediate OTA States
*
* This function is called to notify RainMaker dashbord of OTA Progress
Expand Down
6 changes: 3 additions & 3 deletions components/rmaker_ota_https/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ menu "ESP RainMaker HTTPS OTA Config"
int "Rollback Period"
default 90
help
The time period(in seconds) for checking if OTA is valid.
The time period for checking if OTA is valid.
If OTA is not marked valid in this timeframe, firmware is rolled back.

config OTA_HTTPS_APPLY_STACK_SIZE
int "Stack size(in kilobytes) of the task reponsible for calling the OTA callback"
int "Stack size(in bytes) of the task reponsible for calling the OTA callback"
default 3072
endmenu
endmenu
2 changes: 1 addition & 1 deletion components/rmaker_ota_https/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Since regular OTA rollback is based on MQTT connection(which isn't applicable in
---

**Note:** Since this component uses callbacks from generic RainMaker OTA component, callback specific settings(like project name, version verification) needs to be configured from *ESP RainMaker Config -> ESP RainMaker OTA Config* in ESP-IDF menuconfig.
**Note:** It is does not currently work with ESP Secure Cert.
**Note:** It is does not currently work with ESP Secure Cert.
3 changes: 2 additions & 1 deletion components/rmaker_ota_https/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
override_path: '../json_generator'
espressif/esp_schedule:
version: "~1.2.0"
override_path: '../esp_schedule/'
override_path: '../esp_schedule/'

20 changes: 13 additions & 7 deletions components/rmaker_ota_https/include/esp_rmaker_ota_https.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <esp_err.h>
#include <esp_rmaker_ota.h>

/** Enables and initializes RainMaker OTA using HTTP transport.
*
/** Enables and initializes RainMaker OTA using HTTP transport.
*
* @return ESP_OK if success, failure otherwise
*/
*/
esp_err_t esp_rmaker_ota_https_enable(esp_rmaker_ota_config_t *ota_config);

/** Checks if there is any ota available and applies the OTA if found
*
*
* @return ESP_OK if success, failure otherwise
*/
esp_err_t esp_rmaker_ota_https_fetch(void);

/** Marks the current OTA partition as valid
*
*
* @return ESP_OK if success, failure otherwise
*/
esp_err_t esp_rmaker_ota_https_mark_valid(void);

/** Marks the current OTA partition as invalid as reboots
*
*
* @return ESP_OK if success, failure otherwise
*/
esp_err_t esp_rmaker_ota_https_mark_invalid(void);
esp_err_t esp_rmaker_ota_https_mark_invalid(void);
20 changes: 6 additions & 14 deletions components/rmaker_ota_https/src/esp_rmaker_ota_https.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <json_parser.h>
#include <json_generator.h>
Expand Down Expand Up @@ -677,4 +669,4 @@ esp_err_t esp_rmaker_ota_https_enable(esp_rmaker_ota_config_t *ota_config)
g_ota_https_data = ota;
esp_rmaker_ota_https_manage_rollback(ota);
return ESP_OK;
}
}
20 changes: 6 additions & 14 deletions components/rmaker_ota_https/src/esp_rmaker_ota_https_internal.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

Expand All @@ -35,4 +27,4 @@ typedef struct {
/* TODO: find a way to avoid this value duplication */
#define OTA_HTTPS_NVS_PART_NAME "nvs"
#define OTA_HTTPS_NVS_NAMESPACE "rmaker_ota"
#define OTA_HTTPS_JOB_ID_NVS_NAME "rmaker_ota_id"
#define OTA_HTTPS_JOB_ID_NVS_NAME "rmaker_ota_id"
20 changes: 6 additions & 14 deletions components/rmaker_ota_https/src/rmaker_node_api_constants.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

Expand All @@ -30,4 +22,4 @@
#define NODE_API_FIELD_METADATA "metadata"
#define NODE_API_FIELD_FW_VERSION "fw_version"
#define NODE_API_FIELD_JOB_ID "ota_job_id"
#define NODE_API_FIELD_FILE_SIZE "file_size"
#define NODE_API_FIELD_FILE_SIZE "file_size"
12 changes: 0 additions & 12 deletions examples/ota_https/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion examples/ota_https/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Follow the ESP RainMaker Documentation [Get Started](https://rainmaker.espressif
- This example uses ESP RainMaker services for OTA using rmaker_ota_https component.
- It can be used as an reference for using ESP RainMaker as a device management framework in some other use case.
- It has no dependency on the RainMaker phone application. WiFi credentials need to be pre supplied in **"Example Configuration"** in *menuconfig* before running the example/
- Thereafter, OTA can be supplied from [RainMaker Dashboard](https://dashboard.rainmaker.espressif.com)
- Thereafter, OTA can be supplied from [RainMaker Dashboard](https://dashboard.rainmaker.espressif.com)
2 changes: 1 addition & 1 deletion examples/ota_https/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
idf_component_register(SRCS ./app_main.c
INCLUDE_DIRS ".")
INCLUDE_DIRS ".")
46 changes: 25 additions & 21 deletions examples/ota_https/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
#include <esp_log.h>
#include <esp_rmaker_factory.h>
#include <esp_rmaker_ota_https.h>
#include <app_reset.h>
#include <app_insights.h>

static const char *TAG = "app_mmain";
static const char *TAG = "app_main";

#define WIFI_SSID CONFIG_EXAMPLE_WIFI_SSID
#define WIFI_PASSWORD CONFIG_EXAMPLE_WIFI_PASSWORD
#define WIFI_RESET_BUTTON_TIMEOUT 3

static EventGroupHandle_t g_wifi_event_group;
#define WIFI_CONNECTED_BIT BIT0

static void event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
{
ESP_LOGW(TAG, "WiFi disconnected. Trying to connect.");
esp_wifi_connect();
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
}
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
ESP_LOGI(TAG, "WiFi connected, got ip:" IPSTR, IP2STR(&event->ip_info.ip));
xEventGroupSetBits(g_wifi_event_group, WIFI_CONNECTED_BIT);
}
Expand All @@ -46,9 +46,12 @@ esp_err_t wifi_init_connect(void)

esp_err_t err;
err = esp_event_loop_create_default();
if (err == ESP_ERR_INVALID_STATE){
if (err == ESP_ERR_INVALID_STATE)
{
ESP_LOGW(TAG, "Event loop creation failed. Continuing since it might be created elsewhere");
} else if (err != ESP_OK) {
}
else if (err != ESP_OK)
{
ESP_LOGE(TAG, "ESP Event Loop creation failed.");
return ESP_FAIL;
};
Expand All @@ -72,20 +75,19 @@ esp_err_t wifi_init_connect(void)
wifi_config_t wifi_config = {
.sta = {
.ssid = WIFI_SSID,
.password = WIFI_PASSWORD
},
.password = WIFI_PASSWORD},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_connect());

xEventGroupWaitBits(g_wifi_event_group,
WIFI_CONNECTED_BIT,
pdFALSE,
pdFALSE,
portMAX_DELAY);
xEventGroupWaitBits(g_wifi_event_group,
WIFI_CONNECTED_BIT,
pdFALSE,
pdFALSE,
portMAX_DELAY);

return ESP_OK;
}

Expand All @@ -95,22 +97,24 @@ void app_main()
ESP_ERROR_CHECK(err);

err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK(err);

/* Initialize factory parition for HTTPS OTA */
err = esp_rmaker_factory_init();
if (err != ESP_OK) {
if (err != ESP_OK)
{
ESP_LOGE(TAG, "Failed to initialize rmaker factory partition.");
}
ESP_ERROR_CHECK(err);

ESP_ERROR_CHECK(wifi_init_connect());

// Needs to be done after WiFi is connected.
/* Needs to be done after WiFi is connected. */
esp_rmaker_ota_https_enable(NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does https_enable needs to be done after Wi-Fi is connected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires internet connection for validating the OTA firmware. (see here)

esp_rmaker_ota_https_fetch();
}
}
2 changes: 1 addition & 1 deletion examples/ota_https/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120
CONFIG_ESP_RMAKER_USER_ID_CHECK=y

# Application Rollback
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y