-
Notifications
You must be signed in to change notification settings - Fork 193
OTA over HTTPS (MEGH-6086) #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
f7646ba
60bb022
aff9701
78a0279
fedddb3
cd4e09c
94f020d
08c11cc
7b10423
beb93ff
12422d2
2fffb75
bb1b220
952c617
6cc26d0
9e8d35c
2f07c87
d4c5448
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); |
This file was deleted.
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 ".") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
|
@@ -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) | ||
{ | ||
shreyash-b marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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; | ||
}; | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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) | ||
{ | ||
shreyash-b marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.