diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 419076e..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 @@ -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 picow_rp2040 \ No newline at end of file diff --git a/examples/AsyncDemo/.picow_rp2040.test.skip b/examples/AsyncDemo/.picow_rp2040.test.skip new file mode 100644 index 0000000..e69de29 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..eac0723 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.restart(); + #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();