-
Notifications
You must be signed in to change notification settings - Fork 7.8k
feat(hosted): Implement OTA for esp-hosted co-processors #12065
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
61f0329
feat(hosted): Implement OTA for esp-hosted co-processors
me-no-dev c084de9
feat(hosted): Add library to CMakeLists.txt
me-no-dev 0a950cc
feat(hosted): Limit CI to run the example only on P4
me-no-dev 5ebe76d
feat(hosted): Document inline the source code
me-no-dev a37aebb
feat(hosted): Add library to code owners
me-no-dev 011b4ed
ci(pre-commit): Apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libraries/ESP_HostedOTA/examples/ESP_HostedOTA/ESP_HostedOTA.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include "WiFi.h" | ||
| #include "ESP_HostedOTA.h" | ||
|
|
||
| const char *ssid = "your-ssid"; // Change this to your WiFi SSID | ||
| const char *password = "your-password"; // Change this to your WiFi password | ||
|
|
||
| void setup() { | ||
| Serial.begin(115200); | ||
|
|
||
| WiFi.STA.begin(); | ||
|
|
||
| Serial.println(); | ||
| Serial.println("******************************************************"); | ||
| Serial.print("Connecting to "); | ||
| Serial.println(ssid); | ||
|
|
||
| WiFi.STA.connect(ssid, password); | ||
|
|
||
| while (WiFi.STA.status() != WL_CONNECTED) { | ||
| delay(500); | ||
| Serial.print("."); | ||
| } | ||
| Serial.println(); | ||
|
|
||
| Serial.println("WiFi connected"); | ||
| Serial.print("IP address: "); | ||
| Serial.println(WiFi.STA.localIP()); | ||
|
|
||
| if (updateEspHostedSlave()) { | ||
| // Currently it's required to restart the host | ||
| ESP.restart(); | ||
| } | ||
| } | ||
|
|
||
| void loop() { | ||
| delay(1000); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ####################################### | ||
| # Syntax Coloring Map For ESP_HostedOTA | ||
| ####################################### | ||
|
|
||
| ####################################### | ||
| # Datatypes (KEYWORD1) | ||
| ####################################### | ||
|
|
||
| ####################################### | ||
| # Methods and Functions (KEYWORD2) | ||
| ####################################### | ||
|
|
||
| updateEspHostedSlave KEYWORD2 | ||
|
|
||
| ####################################### | ||
| # Constants (LITERAL1) | ||
| ####################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| name=ESP_HostedOTA | ||
| version=3.3.4 | ||
| author=me-no-dev | ||
| maintainer=me-no-dev | ||
| sentence=Library for updating the ESP-Hosted co-processor | ||
| paragraph=Supports ESP32 Arduino platforms. | ||
| category=Communication | ||
| url=https://github.com/espressif/arduino-esp32/ | ||
| architectures=esp32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #include "sdkconfig.h" | ||
| #if CONFIG_ESP_WIFI_REMOTE_ENABLED | ||
| #include "Arduino.h" | ||
| #include "esp32-hal-hosted.h" | ||
| #include "Network.h" | ||
| #include "HTTPClient.h" | ||
| #include "NetworkClientSecure.h" | ||
| #endif | ||
|
|
||
| bool updateEspHostedSlave() { | ||
| #if CONFIG_ESP_WIFI_REMOTE_ENABLED | ||
| bool updateSuccess = false; | ||
| if (!hostedIsInitialized()) { | ||
| Serial.println("ERROR: esp-hosted is not initialized. Did you call WiFi.STA.begin()?"); | ||
| return updateSuccess; | ||
| } | ||
| if (!hostedHasUpdate()) { | ||
| // esp-hosted is already the latest version | ||
| return updateSuccess; | ||
| } | ||
| if (!Network.isOnline()) { | ||
| Serial.println("ERROR: Network is not online! Did you call WiFi.STA.connect(ssid, password)?"); | ||
| return updateSuccess; | ||
| } | ||
| Serial.print("Updating esp-hosted co-processor from "); | ||
| Serial.println(hostedGetUpdateURL()); | ||
| NetworkClientSecure *client = new NetworkClientSecure(); | ||
| if (!client) { | ||
| Serial.println("ERROR: Could not allocate client!"); | ||
| return updateSuccess; | ||
| } | ||
| client->setInsecure(); | ||
| HTTPClient https; | ||
| int httpCode = 0; | ||
| if (!https.begin(*client, hostedGetUpdateURL())) { | ||
| Serial.println("ERROR: HTTP begin failed!"); | ||
| goto finish_ota; | ||
| } | ||
| httpCode = https.GET(); | ||
| if (httpCode == HTTP_CODE_OK) { | ||
| int len = https.getSize(); | ||
| if (len < 0) { | ||
| Serial.println("ERROR: Update size not received!"); | ||
| https.end(); | ||
| goto finish_ota; | ||
| } | ||
| NetworkClient *stream = https.getStreamPtr(); | ||
| if (!hostedBeginUpdate()) { | ||
| Serial.println("ERROR: esp-hosted update start failed!"); | ||
| https.end(); | ||
| goto finish_ota; | ||
| } | ||
me-no-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define HOSTED_OTA_BUF_SIZE 2048 | ||
| uint8_t * buff = (uint8_t*)malloc(HOSTED_OTA_BUF_SIZE); | ||
| if (!buff) { | ||
| Serial.println("ERROR: Could not allocate OTA buffer!"); | ||
me-no-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| https.end(); | ||
| goto finish_ota; | ||
| } | ||
| while (https.connected() && len > 0) { | ||
| size_t size = stream->available(); | ||
| if (size > 0) { | ||
| Serial.print("."); | ||
| if (size > HOSTED_OTA_BUF_SIZE) { | ||
| size = HOSTED_OTA_BUF_SIZE; | ||
| } | ||
| if (size > len) { | ||
| Serial.printf("\nERROR: Update received extra bytes: %u!", size - len); | ||
me-no-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| } | ||
| int readLen = stream->readBytes(buff, size); | ||
| len -= readLen; | ||
| if (!hostedWriteUpdate(buff, readLen)) { | ||
| Serial.println("\nERROR: esp-hosted update write failed!"); | ||
| break; | ||
| } | ||
me-no-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (len == 0) { | ||
| if (!hostedEndUpdate()) { | ||
| Serial.println("\nERROR: esp-hosted update end failed!"); | ||
| break; | ||
| } | ||
| if (!hostedActivateUpdate()) { | ||
| Serial.println("\nERROR: esp-hosted update activate failed!"); | ||
| break; | ||
| } | ||
| updateSuccess = true; | ||
| Serial.println("\nSUCCESS: esp-hosted co-processor updated!"); | ||
| break; | ||
| } | ||
| } | ||
| delay(1); | ||
| } | ||
| free(buff); | ||
| Serial.println(); | ||
| } | ||
|
|
||
| https.end(); | ||
| finish_ota: | ||
| delete client; | ||
| return updateSuccess; | ||
| #else | ||
| return false; | ||
| #endif | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <stdbool.h> | ||
|
|
||
| bool updateEspHostedSlave(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.