Skip to content
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

[Feat] Added RP2040 ( Pico W ) Support #122

Merged
merged 11 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
- '/docs'

jobs:
async_build:
Async_CI:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
Expand Down Expand Up @@ -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
Expand All @@ -82,4 +82,4 @@ jobs:
touch .esp8266.test.skip

- name: Test Sync Demo
run: python3 ci/build_platform.py esp8266 esp32
run: python3 ci/build_platform.py esp8266 esp32 picow_rp2040
Empty file.
20 changes: 17 additions & 3 deletions examples/Demo/Demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.

-------------------------------

Expand All @@ -27,17 +36,22 @@
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#elif defined(TARGET_RP2040)
#include <WiFi.h>
#include <WebServer.h>
#endif

#include <ElegantOTA.h>

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;
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
],
"version": "3.0.0",
"frameworks": "arduino",
"platforms": "espressif"
"platforms": ["espressif", "raspberrypi"]
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ author=Ayush Sharma
category=Communication
maintainer=Ayush Sharma <[email protected]>
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
37 changes: 32 additions & 5 deletions src/ElegantOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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;
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/ElegantOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,31 @@ _____ _ _ ___ _____ _
#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 {
OTA_MODE_FIRMWARE = 0,
OTA_MODE_FILESYSTEM = 1
};


class ElegantOTAClass{
public:
ElegantOTAClass();
Expand Down