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: add rp2040 support #31

Merged
merged 1 commit into from
Jun 20, 2024
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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
- core: esp8266:esp8266
board: esp8266:esp8266:huzzah
index_url: https://arduino.esp8266.com/stable/package_esp8266com_index.json

- name: package_rp2040_index.json
core: rp2040:rp2040
board: rp2040:rp2040:rpipicow
index_url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -55,6 +58,10 @@ jobs:
if: ${{ matrix.core == 'esp8266:esp8266' }}
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0

- name: Install AsyncTCP (RP2040)
if: ${{ matrix.core == 'rp2040:rp2040' }}
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/khoih-prog/AsyncTCP_RP2040W#v1.2.0

- name: Build CaptivePortal
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/CaptivePortal/CaptivePortal.ino"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Continuous Integration](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml/badge.svg)](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/mathieucarbou/library/ESP%20Async%20WebServer.svg)](https://registry.platformio.org/libraries/mathieucarbou/ESP%20Async%20WebServer)

Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266
Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.

This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) and includes all the concurrency fixes.
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# bundle exec jekyll serve --host=0.0.0.0

title: ESP Async WebServer
description: "Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266"
description: "Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040"
remote_theme: pages-themes/[email protected]
plugins:
- jekyll-remote-theme
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Continuous Integration](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml/badge.svg)](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/mathieucarbou/library/ESP%20Async%20WebServer.svg)](https://registry.platformio.org/libraries/mathieucarbou/ESP%20Async%20WebServer)

Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266
Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.

This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) and includes all the concurrency fixes.
Expand Down
13 changes: 8 additions & 5 deletions examples/CaptivePortal/CaptivePortal.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <DNSServer.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#if defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(TARGET_RP2040)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include "ESPAsyncWebServer.h"

Expand Down
13 changes: 8 additions & 5 deletions examples/Filters/Filters.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Reproduced issue https://github.com/mathieucarbou/ESPAsyncWebServer/issues/26

#include <DNSServer.h>
#ifdef ESP32
#include <AsyncTCP.h>
#include <WiFi.h>
#if defined(ESP32)
#include <AsyncTCP.h>
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(TARGET_RP2040)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include "ESPAsyncWebServer.h"

Expand Down
13 changes: 8 additions & 5 deletions examples/SimpleServer/SimpleServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
//

#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#if defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(TARGET_RP2040)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <ESPAsyncWebServer.h>

Expand Down
4 changes: 4 additions & 0 deletions examples/StreamFiles/StreamConcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class StreamConcat : public Stream {
return c != -1 ? c : _s2->read();
}

#if defined(TARGET_RP2040)
size_t readBytes(char* buffer, size_t length) {
#else
size_t readBytes(char* buffer, size_t length) override {
#endif
size_t count = _s1->readBytes(buffer, length);
return count > 0 ? count : _s2->readBytes(buffer, length);
}
Expand Down
21 changes: 16 additions & 5 deletions examples/StreamFiles/StreamFiles.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include <Arduino.h>
#include <DNSServer.h>
#ifdef ESP32
#include <AsyncTCP.h>
#include <WiFi.h>
#if defined(ESP32)
#include <AsyncTCP.h>
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#elif defined(TARGET_RP2040)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include "StreamConcat.h"
#include "StreamString.h"
Expand Down Expand Up @@ -42,7 +45,11 @@ void setup() {
StreamConcat stream1(&header, &body);

StreamString content;
#if defined(TARGET_RP2040)
content.printf("FreeHeap: %d", rp2040.getFreeHeap());
#else
content.printf("FreeHeap: %" PRIu32, ESP.getFreeHeap());
#endif
StreamConcat stream2 = StreamConcat(&stream1, &content);

File footer = LittleFS.open("/footer.html", "r");
Expand All @@ -67,7 +74,11 @@ void loop() {
// dnsServer.processNextRequest();

if (millis() - last > 2000) {
#if defined(TARGET_RP2040)
Serial.printf("FreeHeap: %d", rp2040.getFreeHeap());
#else
Serial.printf("FreeHeap: %" PRIu32, ESP.getFreeHeap());
#endif
last = millis();
}
}
4 changes: 4 additions & 0 deletions examples/StreamFiles/StreamString.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class StreamString : public Stream {
return c;
}

#if defined(TARGET_RP2040)
size_t readBytes(char* buffer, size_t length) {
#else
size_t readBytes(char* buffer, size_t length) override {
#endif
if (length > _buffer.length())
length = _buffer.length();
// Don't use _str.ToCharArray() because it inserts a terminator
Expand Down
11 changes: 9 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ESP Async WebServer",
"version": "2.10.8",
"description": "Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266. Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.",
"description": "Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040. Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.",
"keywords": "http,async,websocket,webserver",
"homepage": "https://github.com/mathieucarbou/ESPAsyncWebServer",
"repository": {
Expand All @@ -21,7 +21,8 @@
"frameworks": "arduino",
"platforms": [
"espressif32",
"espressif8266"
"espressif8266",
"raspberrypi"
],
"dependencies": [
{
Expand All @@ -39,6 +40,12 @@
{
"name": "Hash",
"platforms": "espressif8266"
},
{
"owner": "khoih-prog",
"name": "AsyncTCP_RP2040W",
"version": "^1.2.0",
"platforms": "raspberrypi"
}
],
"export": {
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name=ESP Async WebServer
version=2.10.8
author=Me-No-Dev
maintainer=Mathieu Carbou <[email protected]>
sentence=Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266
sentence=Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
paragraph=Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc
category=Other
url=https://github.com/mathieucarbou/ESPAsyncWebServer
architectures=esp8266,esp32
architectures=*
license=LGPL-3.0
12 changes: 12 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ board = huzzah
lib_deps =
bblanchon/ArduinoJson @ 7.0.4
esphome/ESPAsyncTCP-esphome @ 2.0.0

; PlatformIO support for Raspberry Pi Pico is not official
; https://github.com/platformio/platform-raspberrypi/pull/36
; https://github.com/earlephilhower/arduino-pico/blob/master/docs/platformio.rst
; board settings: https://github.com/earlephilhower/arduino-pico/blob/master/tools/json/rpipico.json
[env:rpipicow]
upload_protocol = picotool
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipicow
lib_deps =
bblanchon/ArduinoJson @ 7.0.4
khoih-prog/AsyncTCP_RP2040W @ 1.2.0
6 changes: 3 additions & 3 deletions src/AsyncEventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
#include "Arduino.h"
#include "AsyncEventSource.h"
#ifndef ESP8266
#if defined(ESP32)
#include <rom/ets_sys.h>
#endif

Expand Down Expand Up @@ -193,9 +193,9 @@ void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage)
//length() is not thread-safe, thus acquiring the lock before this call..
_lockmq.lock();
if(_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES){
#ifdef ESP8266
#if defined(ESP8266)
ets_printf(String(F("ERROR: Too many messages queued\n")).c_str());
#else
#elif defined(ESP32)
log_e("Too many messages queued: deleting message");
#endif
delete dataMessage;
Expand Down
25 changes: 15 additions & 10 deletions src/AsyncEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
#define ASYNCEVENTSOURCE_H_

#include <Arduino.h>
#ifdef ESP32
#include <AsyncTCP.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 32
#endif
#else
#include <ESPAsyncTCP.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 8
#endif
#if defined(ESP32)
#include <AsyncTCP.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 32
#endif
#elif defined(TARGET_RP2040)
#include <AsyncTCP_RP2040W.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 32
#endif
#elif defined(ESP8266)
#include <ESPAsyncTCP.h>
#ifndef SSE_MAX_QUEUED_MESSAGES
#define SSE_MAX_QUEUED_MESSAGES 8
#endif
#endif

#include <ESPAsyncWebServer.h>
Expand Down
32 changes: 18 additions & 14 deletions src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@

#include <libb64/cencode.h>

#ifndef ESP8266
#if ESP_IDF_VERSION_MAJOR < 5
#include "./port/SHA1Builder.h"
#else
#include <SHA1Builder.h>
#endif
#include <rom/ets_sys.h>
#else
#include <Hash.h>
#if defined(ESP32)
#if ESP_IDF_VERSION_MAJOR < 5
#include "./port/SHA1Builder.h"
#else
#include <SHA1Builder.h>
#endif
#include <rom/ets_sys.h>
#elif defined(TARGET_RP2040)
#include <Hash.h>
#elif defined(ESP8266)
#include <Hash.h>
#endif

#define MAX_PRINTF_LEN 64
Expand Down Expand Up @@ -455,17 +457,17 @@ void AsyncWebSocketClient::_queueMessage(AsyncWebSocketSharedBuffer buffer, uint
l.unlock();
if(closeWhenFull)
{
#ifdef ESP8266
#if defined(ESP8266)
ets_printf("AsyncWebSocketClient::_queueMessage: Too many messages queued: closing connection\n");
#else
#elif defined(ESP32)
log_e("Too many messages queued: closing connection");
#endif
_status = WS_DISCONNECTED;
if (_client) _client->close(true);
} else {
#ifdef ESP8266
#if defined(ESP8266)
ets_printf("AsyncWebSocketClient::_queueMessage: Too many messages queued: discarding new message\n");
#else
#elif defined(ESP32)
log_e("Too many messages queued: discarding new message");
#endif
}
Expand Down Expand Up @@ -1287,7 +1289,9 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
uint8_t hash[20];
char buffer[33];

#ifdef ESP8266
#if defined(ESP8266)
sha1(key + WS_STR_UUID, hash);
#elif defined(TARGET_RP2040)
sha1(key + WS_STR_UUID, hash);
#else
String k;
Expand Down
26 changes: 17 additions & 9 deletions src/AsyncWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@
#define ASYNCWEBSOCKET_H_

#include <Arduino.h>
#ifdef ESP32
#include <AsyncTCP.h>
#ifndef WS_MAX_QUEUED_MESSAGES
#define WS_MAX_QUEUED_MESSAGES 32
#endif
#if defined(ESP32)
#include <AsyncTCP.h>
#ifndef WS_MAX_QUEUED_MESSAGES
#define WS_MAX_QUEUED_MESSAGES 32
#endif
#elif defined(TARGET_RP2040)
#include <AsyncTCP_RP2040W.h>
#ifndef WS_MAX_QUEUED_MESSAGES
#define WS_MAX_QUEUED_MESSAGES 32
#endif
#elif defined(ESP8266)
#include <ESPAsyncTCP.h>
#ifndef WS_MAX_QUEUED_MESSAGES
#define WS_MAX_QUEUED_MESSAGES 8
#endif
#else
#include <ESPAsyncTCP.h>
#ifndef WS_MAX_QUEUED_MESSAGES
#define WS_MAX_QUEUED_MESSAGES 8
#endif
#error Platform not supported
#endif

#include <ESPAsyncWebServer.h>

#include "AsyncWebSynchronization.h"
Expand Down
Loading
Loading