From cd638ed0f8d86cd56ac1c88fb0eb88d3c557c3d7 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 08:50:53 +0530 Subject: [PATCH 01/11] - Added Pico W (RP2040) Support --- examples/Demo/Demo.ino | 20 +++++++++++++++++--- library.json | 2 +- library.properties | 4 ++-- src/ElegantOTA.cpp | 37 ++++++++++++++++++++++++++++++++----- src/ElegantOTA.h | 19 ++++++++++++++++++- 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/examples/Demo/Demo.ino b/examples/Demo/Demo.ino index 526e410..1dfc433 100644 --- a/examples/Demo/Demo.ino +++ b/examples/Demo/Demo.ino @@ -10,7 +10,16 @@ Github: https://github.com/ayushsharma82/ElegantOTA WiKi: https://docs.elegantota.pro - Works with both ESP8266 & ESP32 + Works with following hardware: + - ESP8266 + - ESP32 + - RP2040 (with WiFi) (Example: Raspberry Pi Pico W) + + + Important note for RP2040 users: + - RP2040 requires LittleFS partition for the OTA updates to work. Without LittleFS partition, OTA updates will fail. + Make sure to select Tools > Flash Size > "2MB (Sketch 1MB, FS 1MB)" option. + - If using bare RP2040, it requires WiFi module like Pico W for ElegantOTA to work. ------------------------------- @@ -27,17 +36,22 @@ #include #include #include +#elif defined(TARGET_RP2040) + #include + #include #endif #include -const char* ssid = "........"; -const char* password = "........"; +const char* ssid = "201"; +const char* password = "frenzy8284"; #if defined(ESP8266) ESP8266WebServer server(80); #elif defined(ESP32) WebServer server(80); +#elif defined(TARGET_RP2040) + WebServer server(80); #endif unsigned long ota_progress_millis = 0; diff --git a/library.json b/library.json index f5657c8..066a474 100644 --- a/library.json +++ b/library.json @@ -17,5 +17,5 @@ ], "version": "3.0.0", "frameworks": "arduino", - "platforms": "espressif" + "platforms": ["espressif", "raspberrypi"] } diff --git a/library.properties b/library.properties index d7e9d0e..31a9d34 100644 --- a/library.properties +++ b/library.properties @@ -4,6 +4,6 @@ author=Ayush Sharma category=Communication maintainer=Ayush Sharma sentence=OTA updates made slick and simple for everyone! -paragraph=A user interface library which provides an interactive portal for your over-the-air updates for wireless microcontrollers. +paragraph=A OTA library which provides an interactive portal for your over-the-air updates for wireless microcontrollers. url=https://github.com/ayushsharma82/ElegantOTA -architectures=esp8266,esp32 +architectures=esp8266,esp32,rp2040 diff --git a/src/ElegantOTA.cpp b/src/ElegantOTA.cpp index 972ecbe..ebf31c4 100644 --- a/src/ElegantOTA.cpp +++ b/src/ElegantOTA.cpp @@ -11,6 +11,13 @@ void ElegantOTAClass::begin(ELEGANTOTA_WEBSERVER *server, const char * username, _authenticate = true; } + #if defined(TARGET_RP2040) + if (!__isPicoW) { + ELEGANTOTA_DEBUG_MSG("RP2040: Not a Pico W, skipping OTA setup\n"); + return; + } + #endif + #if ELEGANTOTA_USE_ASYNC_WEBSERVER == 1 _server->on("/update", HTTP_GET, [&](AsyncWebServerRequest *request){ if(_authenticate && !request->authenticate(_username, _password)){ @@ -93,7 +100,7 @@ void ElegantOTAClass::begin(ELEGANTOTA_WEBSERVER *server, const char * username, _update_error_str = str.c_str(); _update_error_str += "\n"; ELEGANTOTA_DEBUG_MSG(_update_error_str.c_str()); - } + } #endif return request->send((Update.hasError()) ? 400 : 200, "text/plain", (Update.hasError()) ? _update_error_str.c_str() : "OK"); @@ -142,9 +149,6 @@ void ElegantOTAClass::begin(ELEGANTOTA_WEBSERVER *server, const char * username, if (mode == OTA_MODE_FILESYSTEM) { close_all_fs(); } - if (mode == OTA_MODE_FILESYSTEM) { - close_all_fs(); - } Update.runAsync(true); if (!Update.begin(update_size, mode == OTA_MODE_FILESYSTEM ? U_FS : U_FLASH)) { ELEGANTOTA_DEBUG_MSG("Failed to start update process\n"); @@ -165,6 +169,24 @@ void ElegantOTAClass::begin(ELEGANTOTA_WEBSERVER *server, const char * username, _update_error_str += "\n"; ELEGANTOTA_DEBUG_MSG(_update_error_str.c_str()); } + #elif defined(TARGET_RP2040) + uint32_t update_size = 0; + // Gather FS Size + if (mode == OTA_MODE_FILESYSTEM) { + update_size = ((size_t)&_FS_end - (size_t)&_FS_start); + LittleFS.end(); + } else { + FSInfo64 i; + LittleFS.begin(); + LittleFS.info64(i); + update_size = i.totalBytes - i.usedBytes; + } + // Start update process + if (!Update.begin(update_size, mode == OTA_MODE_FILESYSTEM ? U_FS : U_FLASH)) { + ELEGANTOTA_DEBUG_MSG("Failed to start update process because there is not enough space\n"); + _update_error_str = "Not enough space"; + return _server->send(400, "text/plain", _update_error_str.c_str()); + } #endif return _server->send((Update.hasError()) ? 400 : 200, "text/plain", (Update.hasError()) ? _update_error_str.c_str() : "OK"); @@ -295,7 +317,12 @@ void ElegantOTAClass::loop() { // Check if 2 seconds have passed since _reboot_request_millis was set if (_reboot && millis() - _reboot_request_millis > 2000) { ELEGANTOTA_DEBUG_MSG("Rebooting...\n"); - ESP.restart(); + #if defined(ESP8266) || defined(ESP32) + ESP.reset(); + #elif defined(TARGET_RP2040) + rp2040.reboot(); + #endif + _reboot = false; } } diff --git a/src/ElegantOTA.h b/src/ElegantOTA.h index 950bc6f..96e9206 100644 --- a/src/ElegantOTA.h +++ b/src/ElegantOTA.h @@ -67,6 +67,24 @@ _____ _ _ ___ _____ _ #define ELEGANTOTA_WEBSERVER WebServer #endif #define HARDWARE "ESP32" +#elif defined(TARGET_RP2040) + #include "Arduino.h" + #include "FS.h" + #include "LittleFS.h" + #include "WiFiClient.h" + #include "WiFiServer.h" + #include "WebServer.h" + #include "WiFiUdp.h" + #include "StreamString.h" + #include "Updater.h" + #define HARDWARE "RP2040" + #define ELEGANTOTA_WEBSERVER WebServer + // Throw an error if async mode is enabled + #if ELEGANTOTA_USE_ASYNC_WEBSERVER == 1 + #error "Async mode is not supported on RP2040. Please set ELEGANTOTA_USE_ASYNC_WEBSERVER to 0." + #endif + extern uint8_t _FS_start; + extern uint8_t _FS_end; #endif enum OTA_Mode { @@ -74,7 +92,6 @@ enum OTA_Mode { OTA_MODE_FILESYSTEM = 1 }; - class ElegantOTAClass{ public: ElegantOTAClass(); From fe0b6d3ce6949cd887205be7979d7ea7ff89e183 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 08:55:09 +0530 Subject: [PATCH 02/11] - Skip Async Demo CI for RP2040 --- examples/AsyncDemo/.rp2040.test.skip | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/AsyncDemo/.rp2040.test.skip diff --git a/examples/AsyncDemo/.rp2040.test.skip b/examples/AsyncDemo/.rp2040.test.skip new file mode 100644 index 0000000..e69de29 From 6811b1aa85cf331c2688e9de45d084cb355bc803 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 08:58:22 +0530 Subject: [PATCH 03/11] - Fix ESP restart - Added RP2040 to test platforms --- .github/workflows/ci.yml | 2 +- src/ElegantOTA.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 419076e..c1c3dd5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,4 +82,4 @@ jobs: touch .esp8266.test.skip - name: Test Sync Demo - run: python3 ci/build_platform.py esp8266 esp32 \ No newline at end of file + run: python3 ci/build_platform.py esp8266 esp32 rp2040 \ No newline at end of file diff --git a/src/ElegantOTA.cpp b/src/ElegantOTA.cpp index ebf31c4..eac0723 100644 --- a/src/ElegantOTA.cpp +++ b/src/ElegantOTA.cpp @@ -318,7 +318,7 @@ void ElegantOTAClass::loop() { if (_reboot && millis() - _reboot_request_millis > 2000) { ELEGANTOTA_DEBUG_MSG("Rebooting...\n"); #if defined(ESP8266) || defined(ESP32) - ESP.reset(); + ESP.restart(); #elif defined(TARGET_RP2040) rp2040.reboot(); #endif From 52278c08cb7b3391c8d96e550cbb0e2793c9b5c6 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:04:15 +0530 Subject: [PATCH 04/11] - Fix CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1c3dd5..8a8b666 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,4 +82,4 @@ jobs: touch .esp8266.test.skip - name: Test Sync Demo - run: python3 ci/build_platform.py esp8266 esp32 rp2040 \ No newline at end of file + run: python3 ci/build_platform.py esp8266 esp32 rpipicow \ No newline at end of file From d51ed3f999e0c5dfe2d9fc5eaf6e6b6450923248 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:11:46 +0530 Subject: [PATCH 05/11] - Fix CI #2 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a8b666..ff18213 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,4 +82,4 @@ jobs: touch .esp8266.test.skip - name: Test Sync Demo - run: python3 ci/build_platform.py esp8266 esp32 rpipicow \ No newline at end of file + run: python3 ci/build_platform.py esp8266 esp32 raspberry_pi_pico_w \ No newline at end of file From b13d15f190dae963fde29ed1b6d37fd383299545 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:12:16 +0530 Subject: [PATCH 06/11] - Skip Rpi platforms --- .../AsyncDemo/{.rp2040.test.skip => .rp2040_platforms.test.skip} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/AsyncDemo/{.rp2040.test.skip => .rp2040_platforms.test.skip} (100%) diff --git a/examples/AsyncDemo/.rp2040.test.skip b/examples/AsyncDemo/.rp2040_platforms.test.skip similarity index 100% rename from examples/AsyncDemo/.rp2040.test.skip rename to examples/AsyncDemo/.rp2040_platforms.test.skip From a1dbbd8ac5a010ad27530bf853eeb03f46958200 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:14:19 +0530 Subject: [PATCH 07/11] - Fix CI #3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff18213..064503a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,4 +82,4 @@ jobs: touch .esp8266.test.skip - name: Test Sync Demo - run: python3 ci/build_platform.py esp8266 esp32 raspberry_pi_pico_w \ No newline at end of file + run: python3 ci/build_platform.py esp8266 esp32 pico_w_rp2040 \ No newline at end of file From 056dee5f87f45a3302fa220cb7672677ab0df102 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:15:11 +0530 Subject: [PATCH 08/11] - Fix CI #4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 064503a..4a04183 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,4 +82,4 @@ jobs: touch .esp8266.test.skip - name: Test Sync Demo - run: python3 ci/build_platform.py esp8266 esp32 pico_w_rp2040 \ No newline at end of file + run: python3 ci/build_platform.py esp8266 esp32 pico_rp2040 \ No newline at end of file From 922bbce8aaef72c73f855f0b81dc9f6540acf3cd Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:16:57 +0530 Subject: [PATCH 09/11] - Switch to PicoW in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a04183..2e26829 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,4 +82,4 @@ jobs: touch .esp8266.test.skip - name: Test Sync Demo - run: python3 ci/build_platform.py esp8266 esp32 pico_rp2040 \ No newline at end of file + run: python3 ci/build_platform.py esp8266 esp32 picow_rp2040 \ No newline at end of file From 0f608571237d178d215ad5dbfeb0674c2b91ac93 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:19:59 +0530 Subject: [PATCH 10/11] - Updated job names --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e26829..36ef124 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ on: - '/docs' jobs: - async_build: + Async_CI: runs-on: ubuntu-latest steps: - uses: actions/setup-python@v1 @@ -57,7 +57,7 @@ jobs: - name: Test Async Demo run: python3 ci/build_platform.py esp8266 esp32 - sync_build: + Sync_CI: runs-on: ubuntu-latest steps: - uses: actions/setup-python@v1 From eb8df5d11f2410bca8f6d3364d0e62ad4f2fc8a1 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 21 Sep 2023 09:21:16 +0530 Subject: [PATCH 11/11] - Skip PicoW from Async Demo --- .../{.rp2040_platforms.test.skip => .picow_rp2040.test.skip} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/AsyncDemo/{.rp2040_platforms.test.skip => .picow_rp2040.test.skip} (100%) diff --git a/examples/AsyncDemo/.rp2040_platforms.test.skip b/examples/AsyncDemo/.picow_rp2040.test.skip similarity index 100% rename from examples/AsyncDemo/.rp2040_platforms.test.skip rename to examples/AsyncDemo/.picow_rp2040.test.skip