4
.gitignore
vendored
4
.gitignore
vendored
@@ -24,3 +24,7 @@ updater/src/networkDevices/*.h
|
||||
/lib64
|
||||
/lib/python3*
|
||||
sdkconfig
|
||||
# NodeJS en pnpm
|
||||
.pnpm
|
||||
node_modules
|
||||
pnpm-lock.yaml
|
||||
@@ -125,6 +125,7 @@ In a browser navigate to the IP address assigned to the ESP32.
|
||||
- Restart on disconnect: Enable to restart the Nuki Hub when disconnected from the network.
|
||||
- Reconnect network on MQTT connection failure: Enable to force reconnection to the network when connection to the MQTT broker fails (after 15 tries).
|
||||
- Enable MQTT logging: Enable to fill the maintenance/log MQTT topic with debug log information.
|
||||
- Enable WebSerial logging : Enable to publish debug log information to `http://NUKIHUBIP:81/webserial`.
|
||||
- Check for Firmware Updates every 24h: Enable to allow the Nuki Hub to check the latest release of the Nuki Hub firmware on boot and every 24 hours. Requires the Nuki Hub to be able to connect to github.com. The latest version will be published to MQTT and will be visible on the main page of the Web Configurator.
|
||||
- Allow updating using MQTT: Enable to allow starting the Nuki Hub update process using MQTT. Will also enable the Home Assistant update functionality if auto discovery is enabled.
|
||||
- Disable some extraneous non-JSON topics: Enable to not publish non-JSON keypad and config MQTT topics.
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Please make sure to go through the recommendations before opening a bug report:**
|
||||
|
||||
[https://github.com/mathieucarbou/AsyncTCP?tab=readme-ov-file#important-recommendations](https://github.com/mathieucarbou/AsyncTCP?tab=readme-ov-file#important-recommendations)
|
||||
|
||||
**Description**
|
||||
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Board**
|
||||
|
||||
esp32dev, esp32s3, etc
|
||||
|
||||
**Ethernet adapter used ?**
|
||||
|
||||
If yes, please specify which one
|
||||
|
||||
**Stack trace**
|
||||
|
||||
Please provide the stack trace here taken with `monitor_filters = esp32_exception_decoder`.
|
||||
**Any issue opened with a non readable stack trace will be ignored because not helpful at all.**
|
||||
|
||||
As an alternative, you can use [https://maximeborges.github.io/esp-stacktrace-decoder/](https://maximeborges.github.io/esp-stacktrace-decoder/).
|
||||
|
||||
**Additional notes**
|
||||
|
||||
Add any other context about the problem here.
|
||||
10
lib/AsyncTCP/.github/ISSUE_TEMPLATE/question.md
vendored
10
lib/AsyncTCP/.github/ISSUE_TEMPLATE/question.md
vendored
@@ -1,10 +0,0 @@
|
||||
---
|
||||
name: Question
|
||||
about: Describe your question
|
||||
title: "[Q]"
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
10
lib/AsyncTCP/.github/dependabot.yml
vendored
10
lib/AsyncTCP/.github/dependabot.yml
vendored
@@ -1,10 +0,0 @@
|
||||
# Set update schedule for GitHub Actions
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every week
|
||||
interval: "weekly"
|
||||
31
lib/AsyncTCP/.github/stale.yml
vendored
31
lib/AsyncTCP/.github/stale.yml
vendored
@@ -1,31 +0,0 @@
|
||||
# Configuration for probot-stale - https://github.com/probot/stale
|
||||
|
||||
daysUntilStale: 60
|
||||
daysUntilClose: 14
|
||||
limitPerRun: 30
|
||||
staleLabel: stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
- "to be implemented"
|
||||
- "for reference"
|
||||
- "move to PR"
|
||||
- "enhancement"
|
||||
|
||||
only: issues
|
||||
onlyLabels: []
|
||||
exemptProjects: false
|
||||
exemptMilestones: false
|
||||
exemptAssignees: false
|
||||
|
||||
markComment: >
|
||||
[STALE_SET] This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed in 14 days if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
|
||||
unmarkComment: >
|
||||
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future.
|
||||
|
||||
closeComment: >
|
||||
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
|
||||
|
||||
52
lib/AsyncTCP/.github/workflows/push.yml
vendored
52
lib/AsyncTCP/.github/workflows/push.yml
vendored
@@ -1,52 +0,0 @@
|
||||
name: Async TCP CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-arduino:
|
||||
name: ${{ matrix.config }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config: [arduino-cli.yaml, arduino-cli-dev.yaml]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: arduino/setup-arduino-cli@v1
|
||||
- name: Download board
|
||||
run: |
|
||||
arduino-cli --config-file ${{ matrix.config }} core update-index
|
||||
arduino-cli --config-file ${{ matrix.config }} board listall
|
||||
arduino-cli --config-file ${{ matrix.config }} core install esp32:esp32
|
||||
- name: Compile Sketch
|
||||
run: arduino-cli --config-file ${{ matrix.config }} --library ./src/ compile --fqbn esp32:esp32:esp32 ./examples/ClientServer/Client/Client.ino
|
||||
- name: Compile Sketch with IPv6
|
||||
env:
|
||||
LWIP_IPV6: true
|
||||
run: arduino-cli --config-file ${{ matrix.config }} --library ./src/ compile --fqbn esp32:esp32:esp32 ./examples/ClientServer/Client/Client.ino
|
||||
|
||||
build-pio:
|
||||
name: ${{ matrix.board }} ${{ matrix.env }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
board: [esp32dev, esp32-s3-devkitc-1]
|
||||
env: [arduino-2, arduino-3]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.platformio
|
||||
~/.cache/pip
|
||||
key: ${{ matrix.env }}
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.x"
|
||||
- run: pip install platformio
|
||||
- run: sed -i -e 's/esp32dev/${{ matrix.board }}/g' platformio.ini
|
||||
- run: pio run -e ${{ matrix.env }}
|
||||
6
lib/AsyncTCP/.gitignore
vendored
6
lib/AsyncTCP/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
.DS_Store
|
||||
.lh
|
||||
/.pio
|
||||
/.vscode/*
|
||||
!/.vscode/settings.json
|
||||
/logs
|
||||
@@ -1,8 +1,8 @@
|
||||
# AsyncTCP
|
||||
|
||||
[](https://opensource.org/license/lgpl-3-0/)
|
||||
[](https://github.com/mathieucarbou/AsyncTCP/actions/workflows/push.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/Async%20TCP)
|
||||
[](https://github.com/mathieucarbou/AsyncTCP/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/AsyncTCP)
|
||||
|
||||
A fork of the [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) library by [@me-no-dev](https://github.com/me-no-dev) for [ESPHome](https://esphome.io).
|
||||
|
||||
@@ -21,10 +21,14 @@ The base classes on which everything else is built. They expose all possible sce
|
||||
- All improvements from [ESPHome fork](https://github.com/esphome/AsyncTCP)
|
||||
- Reverted back `library.properties` for Arduino IDE users
|
||||
- Arduino 3 / ESP-IDF 5 compatibility
|
||||
- Changed lib name: `AsyncTCP` -> `Async TCP`
|
||||
- Point to `mathieucarbou/Async TCP @ ^3.1.4`
|
||||
- IPv6 support
|
||||
|
||||
## Coordinates
|
||||
|
||||
```
|
||||
mathieucarbou/AsyncTCP @ ^3.2.4
|
||||
```
|
||||
|
||||
## Important recommendations
|
||||
|
||||
Most of the crashes are caused by improper configuration of the library for the project.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Async TCP",
|
||||
"version": "3.1.4",
|
||||
"name": "AsyncTCP",
|
||||
"version": "3.2.4",
|
||||
"description": "Asynchronous TCP Library for ESP32",
|
||||
"keywords": "async,tcp",
|
||||
"repository": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=Async TCP
|
||||
version=3.1.4
|
||||
name=AsyncTCP
|
||||
version=3.2.4
|
||||
author=Me-No-Dev
|
||||
maintainer=Mathieu Carbou <mathieu.carbou@gmail.com>
|
||||
sentence=Async TCP Library for ESP32
|
||||
|
||||
@@ -23,6 +23,26 @@ board = esp32dev
|
||||
[env:arduino-3]
|
||||
platform = espressif32
|
||||
platform_packages=
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2
|
||||
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.3
|
||||
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.3/esp32-arduino-libs-3.0.3.zip
|
||||
board = esp32dev
|
||||
|
||||
[env:pioarduino-esp32dev]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32dev
|
||||
|
||||
[env:pioarduino-esp32-s2]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32-s2-saola-1
|
||||
|
||||
[env:pioarduino-esp32-s3]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32-s3-devkitc-1
|
||||
|
||||
[env:pioarduino-esp32-c3]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32-c3-devkitc-02
|
||||
|
||||
[env:pioarduino-esp32-c6]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32-c6-devkitc-1
|
||||
|
||||
@@ -33,6 +33,12 @@ extern "C"{
|
||||
#include "esp_task_wdt.h"
|
||||
#endif
|
||||
|
||||
// Required for:
|
||||
// https://github.com/espressif/arduino-esp32/blob/3.0.3/libraries/Network/src/NetworkInterface.cpp#L37-L47
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
#include <NetworkInterface.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TCP/IP Event Task
|
||||
* */
|
||||
@@ -439,7 +445,7 @@ static esp_err_t _tcp_write(tcp_pcb * pcb, int8_t closed_slot, const char* data,
|
||||
static err_t _tcp_recved_api(struct tcpip_api_call_data *api_call_msg){
|
||||
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
|
||||
msg->err = ERR_CONN;
|
||||
if(msg->closed_slot == -1 || !_closed_slots[msg->closed_slot]) {
|
||||
if(msg->closed_slot != -1 && !_closed_slots[msg->closed_slot]) {
|
||||
msg->err = 0;
|
||||
tcp_recved(msg->pcb, msg->received);
|
||||
}
|
||||
@@ -723,8 +729,8 @@ bool AsyncClient::_connect(ip_addr_t addr, uint16_t port){
|
||||
tcp_recv(pcb, &_tcp_recv);
|
||||
tcp_sent(pcb, &_tcp_sent);
|
||||
tcp_poll(pcb, &_tcp_poll, 1);
|
||||
_tcp_connect(pcb, _closed_slot, &addr, port,(tcp_connected_fn)&_tcp_connected);
|
||||
return true;
|
||||
esp_err_t err =_tcp_connect(pcb, _closed_slot, &addr, port,(tcp_connected_fn)&_tcp_connected);
|
||||
return err == ESP_OK;
|
||||
}
|
||||
|
||||
bool AsyncClient::connect(const IPAddress& ip, uint16_t port){
|
||||
@@ -1006,7 +1012,7 @@ int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
|
||||
|
||||
int8_t AsyncClient::_poll(tcp_pcb* pcb){
|
||||
if(!_pcb){
|
||||
log_d("pcb is NULL");
|
||||
// log_d("pcb is NULL");
|
||||
return ERR_OK;
|
||||
}
|
||||
if(pcb != _pcb){
|
||||
@@ -1091,12 +1097,9 @@ size_t AsyncClient::write(const char* data) {
|
||||
|
||||
size_t AsyncClient::write(const char* data, size_t size, uint8_t apiflags) {
|
||||
size_t will_send = add(data, size, apiflags);
|
||||
if(!will_send) {
|
||||
if(!will_send || !send()) {
|
||||
return 0;
|
||||
}
|
||||
while (connected() && !send()) {
|
||||
taskYIELD();
|
||||
}
|
||||
return will_send;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#ifndef ASYNCTCP_H_
|
||||
#define ASYNCTCP_H_
|
||||
|
||||
#define ASYNCTCP_VERSION "3.1.4"
|
||||
#define ASYNCTCP_VERSION "3.2.4"
|
||||
#define ASYNCTCP_VERSION_MAJOR 3
|
||||
#define ASYNCTCP_VERSION_MINOR 1
|
||||
#define ASYNCTCP_VERSION_MINOR 2
|
||||
#define ASYNCTCP_VERSION_REVISION 4
|
||||
#define ASYNCTCP_FORK_mathieucarbou
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"type": "library", "name": "ESP Async WebServer", "version": "3.0.6", "spec": {"owner": "mathieucarbou", "id": 16603, "name": "ESP Async WebServer", "requirements": null, "uri": null}}
|
||||
17
lib/ESP Async WebServer/CMakeLists.txt
Normal file
17
lib/ESP Async WebServer/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
set(COMPONENT_SRCDIRS
|
||||
"src"
|
||||
)
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
"src"
|
||||
)
|
||||
|
||||
set(COMPONENT_REQUIRES
|
||||
"arduino-esp32"
|
||||
"AsyncTCP"
|
||||
)
|
||||
|
||||
register_component()
|
||||
|
||||
target_compile_definitions(${COMPONENT_TARGET} PUBLIC -DESP32)
|
||||
target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti)
|
||||
@@ -1,14 +1,28 @@
|
||||
# ESP Async WebServer
|
||||
# ESPAsyncWebServer
|
||||
|
||||
[](https://opensource.org/license/lgpl-3-0/)
|
||||
[](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/ESP%20Async%20WebServer)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/ESPAsyncWebServer)
|
||||
|
||||
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.
|
||||
|
||||
## Coordinate and dependencies:
|
||||
|
||||
**WARNING** The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations.
|
||||
|
||||
```
|
||||
mathieucarbou/ESPAsyncWebServer @ 3.1.2
|
||||
```
|
||||
|
||||
Dependency:
|
||||
|
||||
- **ESP32**: `mathieucarbou/AsyncTCP @ 3.2.4` (Arduino IDE: [https://github.com/mathieucarbou/AsyncTCP#v3.2.4](https://github.com/mathieucarbou/AsyncTCP/releases/tag/v3.2.0))
|
||||
- **ESP8266**: `esphome/ESPAsyncTCP-esphome @ 2.0.0` (Arduino IDE: [https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0](https://github.com/mathieucarbou/esphome-ESPAsyncTCP/releases/tag/v2.0.0))
|
||||
- **RP2040**: `khoih-prog/AsyncTCP_RP2040W @ 1.2.0` (Arduino IDE: [https://github.com/khoih-prog/AsyncTCP_RP2040W#v1.2.0](https://github.com/khoih-prog/AsyncTCP_RP2040W/releases/tag/v1.2.0))
|
||||
|
||||
## Changes in this fork
|
||||
|
||||
- [@ayushsharma82](https://github.com/ayushsharma82) and [@mathieucarbou](https://github.com/mathieucarbou): Add RP2040 support ([#31](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/31))
|
||||
@@ -22,11 +36,12 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Arduino 3 / ESP-IDF 5.1 compatibility
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Arduino Json 7 compatibility and backward compatible with 6 and 6 (changes in `AsyncJson.h`). The API to use Json has not changed. These are only internal changes.
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): CI
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Depends on `mathieucarbou/Async TCP @ ^3.1.4`
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Depends on `mathieucarbou/AsyncTCP @ 3.2.4`
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Deployed in PlatformIO registry and Arduino IDE library manager
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Firmware size optimization: remove mbedtls dependency (accounts for 33KB in firmware)
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Made DEFAULT_MAX_SSE_CLIENTS customizable
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Made DEFAULT_MAX_WS_CLIENTS customizable
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): MessagePack Support ([#62](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/62))
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Remove filename after inline in Content-Disposition header according to RFC2183
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Removed SPIFFSEditor to reduce library size and maintainance. SPIFF si also deprecated. If you need it, please copy the files from the original repository in your project. This fork focus on maintaining the server part and the SPIFFEditor is an application which has nothing to do inside a server library.
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Resurrected `AsyncWebSocketMessageBuffer` and `makeBuffer()` in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket.
|
||||
@@ -39,12 +54,6 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
|
||||
- [@vortigont](https://github.com/vortigont): Some websocket code cleanup ([#29](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/29))
|
||||
- [@vortigont](https://github.com/vortigont): Refactor code - replace DYI structs with STL objects ([#39](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/39))
|
||||
|
||||
## Dependencies:
|
||||
|
||||
- **ESP32**: `mathieucarbou/Async TCP @ ^3.1.4` (Arduino IDE: [https://github.com/mathieucarbou/AsyncTCP#v3.1.4](https://github.com/mathieucarbou/AsyncTCP/releases/tag/v3.1.4))
|
||||
- **ESP8266**: `esphome/ESPAsyncTCP-esphome @ 2.0.0` (Arduino IDE: [https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0](https://github.com/mathieucarbou/esphome-ESPAsyncTCP/releases/tag/v2.0.0))
|
||||
- **RP2040**: `khoih-prog/AsyncTCP_RP2040W @ 1.2.0` (Arduino IDE: [https://github.com/khoih-prog/AsyncTCP_RP2040W#v1.2.0](https://github.com/khoih-prog/AsyncTCP_RP2040W/releases/tag/v1.2.0))
|
||||
|
||||
## Documentation
|
||||
|
||||
Usage and API stays the same as the original library.
|
||||
|
||||
8
lib/ESP Async WebServer/docs/_config.yml
Normal file
8
lib/ESP Async WebServer/docs/_config.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
# bundle exec jekyll serve --host=0.0.0.0
|
||||
|
||||
title: ESPAsyncWebServer
|
||||
description: "Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040"
|
||||
remote_theme: pages-themes/cayman@v0.2.0
|
||||
plugins:
|
||||
- jekyll-remote-theme
|
||||
|
||||
126
lib/ESP Async WebServer/docs/index.md
Normal file
126
lib/ESP Async WebServer/docs/index.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# ESPAsyncWebServer
|
||||
|
||||
[](https://opensource.org/license/lgpl-3-0/)
|
||||
[](https://github.com/mathieucarbou/ESPAsyncWebServer/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/ESPAsyncWebServer)
|
||||
|
||||
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.
|
||||
|
||||
## Coordinate and dependencies:
|
||||
|
||||
**WARNING** The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations.
|
||||
|
||||
```
|
||||
mathieucarbou/ESPAsyncWebServer @ 3.1.2
|
||||
```
|
||||
|
||||
Dependency:
|
||||
|
||||
- **ESP32**: `mathieucarbou/AsyncTCP @ 3.2.4` (Arduino IDE: [https://github.com/mathieucarbou/AsyncTCP#v3.2.4](https://github.com/mathieucarbou/AsyncTCP/releases/tag/v3.2.0))
|
||||
- **ESP8266**: `esphome/ESPAsyncTCP-esphome @ 2.0.0` (Arduino IDE: [https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0](https://github.com/mathieucarbou/esphome-ESPAsyncTCP/releases/tag/v2.0.0))
|
||||
- **RP2040**: `khoih-prog/AsyncTCP_RP2040W @ 1.2.0` (Arduino IDE: [https://github.com/khoih-prog/AsyncTCP_RP2040W#v1.2.0](https://github.com/khoih-prog/AsyncTCP_RP2040W/releases/tag/v1.2.0))
|
||||
|
||||
## Changes in this fork
|
||||
|
||||
- [@ayushsharma82](https://github.com/ayushsharma82) and [@mathieucarbou](https://github.com/mathieucarbou): Add RP2040 support ([#31](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/31))
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): `SSE_MAX_QUEUED_MESSAGES` to control the maximum number of messages that can be queued for a SSE client
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): `write()` function public in `AsyncEventSource.h`
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): `WS_MAX_QUEUED_MESSAGES`: control the maximum number of messages that can be queued for a Websocket client
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Added `setAuthentication(const String& username, const String& password)`
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Added `setCloseClientOnQueueFull(bool)` which can be set on a client to either close the connection or discard messages but not close the connection when the queue is full
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Added `StreamConcat` example to show how to stream multiple files in one response
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Added all flavors of `binary()`, `text()`, `binaryAll()` and `textAll()` in `AsyncWebSocket`
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Arduino 3 / ESP-IDF 5.1 compatibility
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Arduino Json 7 compatibility and backward compatible with 6 and 6 (changes in `AsyncJson.h`). The API to use Json has not changed. These are only internal changes.
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): CI
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Depends on `mathieucarbou/AsyncTCP @ 3.2.4`
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Deployed in PlatformIO registry and Arduino IDE library manager
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Firmware size optimization: remove mbedtls dependency (accounts for 33KB in firmware)
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Made DEFAULT_MAX_SSE_CLIENTS customizable
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Made DEFAULT_MAX_WS_CLIENTS customizable
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): MessagePack Support ([#62](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/62))
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Remove filename after inline in Content-Disposition header according to RFC2183
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Removed SPIFFSEditor to reduce library size and maintainance. SPIFF si also deprecated. If you need it, please copy the files from the original repository in your project. This fork focus on maintaining the server part and the SPIFFEditor is an application which has nothing to do inside a server library.
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Resurrected `AsyncWebSocketMessageBuffer` and `makeBuffer()` in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket.
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Some code cleanup
|
||||
- [@mathieucarbou](https://github.com/mathieucarbou): Use `-D DEFAULT_MAX_WS_CLIENTS` to change the number of allows WebSocket clients and use `cleanupClients()` to help cleanup resources about dead clients
|
||||
- [@nilo85](https://github.com/nilo85): Add support for Auth & GET requests in AsyncCallbackJsonWebHandler ([#14](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/14))
|
||||
- [@p0p-x](https://github.com/p0p-x): ESP IDF Compatibility (added back CMakeLists.txt) ([#32](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/32))
|
||||
- [@tueddy](https://github.com/tueddy): Compile with Arduino 3 (ESP-IDF 5.1) ([#13](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/13))
|
||||
- [@vortigont](https://github.com/vortigont): Set real "Last-Modified" header based on file's LastWrite time ([#5](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/5))
|
||||
- [@vortigont](https://github.com/vortigont): Some websocket code cleanup ([#29](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/29))
|
||||
- [@vortigont](https://github.com/vortigont): Refactor code - replace DYI structs with STL objects ([#39](https://github.com/mathieucarbou/ESPAsyncWebServer/pull/39))
|
||||
|
||||
## Documentation
|
||||
|
||||
Usage and API stays the same as the original library.
|
||||
Please look at the original libraries for more examples and documentation.
|
||||
|
||||
- [https://github.com/me-no-dev/ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) (original library)
|
||||
- [https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) (fork of the original library)
|
||||
|
||||
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
|
||||
|
||||
The fork from `yubox-node-org` introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
|
||||
|
||||
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
|
||||
So you have the choice of which API to use.
|
||||
|
||||
Here are examples for serializing a Json document in a websocket message buffer:
|
||||
|
||||
```cpp
|
||||
void send(JsonDocument& doc) {
|
||||
const size_t len = measureJson(doc);
|
||||
|
||||
// original API from me-no-dev
|
||||
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
|
||||
assert(buffer); // up to you to keep or remove this
|
||||
serializeJson(doc, buffer->get(), len);
|
||||
_ws->textAll(buffer);
|
||||
}
|
||||
```
|
||||
|
||||
```cpp
|
||||
void send(JsonDocument& doc) {
|
||||
const size_t len = measureJson(doc);
|
||||
|
||||
// this fork (originally from yubox-node-org), uses another API with shared pointer
|
||||
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||
assert(buffer); // up to you to keep or remove this
|
||||
serializeJson(doc, buffer->data(), len);
|
||||
_ws->textAll(std::move(buffer));
|
||||
}
|
||||
```
|
||||
|
||||
I recommend to use the official API `AsyncWebSocketMessageBuffer` to retain further compatibility.
|
||||
|
||||
## Important recommendations
|
||||
|
||||
Most of the crashes are caused by improper configuration of the library for the project.
|
||||
Here are some recommendations to avoid them.
|
||||
|
||||
1. Set the running core to be on the same core of your application (usually core 1) `-D CONFIG_ASYNC_TCP_RUNNING_CORE=1`
|
||||
2. Set the stack size appropriately with `-D CONFIG_ASYNC_TCP_STACK_SIZE=16384`.
|
||||
The default value of `16384` might be too much for your project.
|
||||
You can look at the [MycilaTaskMonitor](https://oss.carbou.me/MycilaTaskMonitor) project to monitor the stack usage.
|
||||
3. You can change **if you know what you are doing** the task priority with `-D CONFIG_ASYNC_TCP_PRIORITY=10`.
|
||||
Default is `10`.
|
||||
4. You can increase the queue size with `-D CONFIG_ASYNC_TCP_QUEUE_SIZE=128`.
|
||||
Default is `64`.
|
||||
5. You can decrease the maximum ack time `-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=3000`.
|
||||
Default is `5000`.
|
||||
|
||||
I personally use the following configuration in my projects because my WS messages can be big (up to 4k).
|
||||
If you have smaller messages, you can increase `WS_MAX_QUEUED_MESSAGES` to 128.
|
||||
|
||||
```c++
|
||||
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=3000
|
||||
-D CONFIG_ASYNC_TCP_PRIORITY=10
|
||||
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||
-D WS_MAX_QUEUED_MESSAGES=64
|
||||
```
|
||||
@@ -16,12 +16,14 @@
|
||||
#include <WebServer.h>
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncJson.h>
|
||||
#include <AsyncMessagePack.h>
|
||||
|
||||
const char* ssid = "YOUR_SSID";
|
||||
const char* password = "YOUR_PASSWORD";
|
||||
AsyncWebServer server(80);
|
||||
|
||||
const char* PARAM_MESSAGE = "message";
|
||||
|
||||
@@ -29,18 +31,24 @@ void notFound(AsyncWebServerRequest* request) {
|
||||
request->send(404, "text/plain", "Not found");
|
||||
}
|
||||
|
||||
AsyncCallbackJsonWebHandler* jsonHandler = new AsyncCallbackJsonWebHandler("/json2");
|
||||
AsyncCallbackMessagePackWebHandler* msgPackHandler = new AsyncCallbackMessagePackWebHandler("/msgpack2");
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.printf("WiFi Failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
// WiFi.mode(WIFI_STA);
|
||||
// WiFi.begin("YOUR_SSID", "YOUR_PASSWORD");
|
||||
// if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
// Serial.printf("WiFi Failed!\n");
|
||||
// return;
|
||||
// }
|
||||
// Serial.print("IP Address: ");
|
||||
// Serial.println(WiFi.localIP());
|
||||
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAP("esp-captive");
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
request->send(200, "text/plain", "Hello, world");
|
||||
@@ -68,6 +76,55 @@ void setup() {
|
||||
request->send(200, "text/plain", "Hello, POST: " + message);
|
||||
});
|
||||
|
||||
// JSON
|
||||
|
||||
// receives JSON and sends JSON
|
||||
jsonHandler->onRequest([](AsyncWebServerRequest* request, JsonVariant& json) {
|
||||
JsonObject jsonObj = json.as<JsonObject>();
|
||||
// ...
|
||||
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||
JsonObject root = response->getRoot().to<JsonObject>();
|
||||
root["hello"] = "world";
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
// sends JSON
|
||||
server.on("/json1", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||
JsonObject root = response->getRoot().to<JsonObject>();
|
||||
root["hello"] = "world";
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
// MessagePack
|
||||
|
||||
// receives MessagePack and sends MessagePack
|
||||
msgPackHandler->onRequest([](AsyncWebServerRequest* request, JsonVariant& json) {
|
||||
JsonObject jsonObj = json.as<JsonObject>();
|
||||
// ...
|
||||
|
||||
AsyncMessagePackResponse* response = new AsyncMessagePackResponse();
|
||||
JsonObject root = response->getRoot().to<JsonObject>();
|
||||
root["hello"] = "world";
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
// sends MessagePack
|
||||
server.on("/msgpack1", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
AsyncMessagePackResponse* response = new AsyncMessagePackResponse();
|
||||
JsonObject root = response->getRoot().to<JsonObject>();
|
||||
root["hello"] = "world";
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
server.addHandler(jsonHandler);
|
||||
server.addHandler(msgPackHandler);
|
||||
|
||||
server.onNotFound(notFound);
|
||||
|
||||
server.begin();
|
||||
|
||||
107
lib/ESP Async WebServer/examples/issues/Issue14/Issue14.ino
Normal file
107
lib/ESP Async WebServer/examples/issues/Issue14/Issue14.ino
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <DNSServer.h>
|
||||
#ifdef ESP32
|
||||
#include <AsyncTCP.h>
|
||||
#include <WiFi.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#elif defined(TARGET_RP2040)
|
||||
#include <WebServer.h>
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
#include "ESPAsyncWebServer.h"
|
||||
|
||||
const char appWebPage[] PROGMEM = R"rawliteral(
|
||||
<body>
|
||||
<button id="button1" onclick="fetch('/button1');">Relay1</button>
|
||||
<script>
|
||||
const evtSource = new EventSource("/events");
|
||||
button1 = document.getElementById("button1");
|
||||
evtSource.addEventListener('state', (e) => {
|
||||
const data = JSON.parse(e.data);
|
||||
console.log('Event Source data: ', data);
|
||||
if (data.button1) {
|
||||
button1.style.backgroundColor = "green";
|
||||
}
|
||||
else {
|
||||
button1.style.backgroundColor = "red";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
)rawliteral";
|
||||
|
||||
AsyncWebServer server(80);
|
||||
AsyncEventSource events("/events");
|
||||
|
||||
const uint32_t interval = 1000;
|
||||
const int button1Pin = 4;
|
||||
|
||||
uint32_t lastSend = 0;
|
||||
|
||||
void prepareJson(String& buffer) {
|
||||
buffer.reserve(512);
|
||||
buffer.concat("{\"button1\":");
|
||||
buffer.concat(digitalRead(button1Pin) == LOW);
|
||||
buffer.concat(",\"1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij\":");
|
||||
buffer.concat(random(0, 999999999));
|
||||
buffer.concat("}");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
#if ARDUINO_USB_CDC_ON_BOOT
|
||||
Serial.setTxTimeoutMs(0);
|
||||
delay(100);
|
||||
#else
|
||||
while (!Serial)
|
||||
yield();
|
||||
#endif
|
||||
|
||||
randomSeed(micros());
|
||||
|
||||
pinMode(button1Pin, OUTPUT);
|
||||
digitalWrite(button1Pin, HIGH);
|
||||
|
||||
WiFi.softAP("esp-captive");
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
request->send(200, "text/html", appWebPage);
|
||||
});
|
||||
|
||||
server.on("/button1", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
request->send(200, "text/plain", "OK");
|
||||
digitalWrite(button1Pin, digitalRead(button1Pin) == LOW ? HIGH : LOW);
|
||||
|
||||
String buffer;
|
||||
prepareJson(buffer);
|
||||
ESP_LOGI("async_tcp", "Sending from handler...");
|
||||
events.send(buffer.c_str(), "state", millis());
|
||||
ESP_LOGI("async_tcp", "Sent from handler!");
|
||||
});
|
||||
|
||||
events.onConnect([](AsyncEventSourceClient* client) {
|
||||
String buffer;
|
||||
prepareJson(buffer);
|
||||
ESP_LOGI("async_tcp", "Sending from onConnect...");
|
||||
client->send(buffer.c_str(), "state", millis(), 5000);
|
||||
ESP_LOGI("async_tcp", "Sent from onConnect!");
|
||||
});
|
||||
|
||||
server.addHandler(&events);
|
||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (millis() - lastSend >= interval) {
|
||||
String buffer;
|
||||
prepareJson(buffer);
|
||||
ESP_LOGI("loop", "Sending...");
|
||||
events.send(buffer.c_str(), "state", millis());
|
||||
ESP_LOGI("loop", "Sent!");
|
||||
lastSend = millis();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ESP Async WebServer",
|
||||
"version": "3.0.6",
|
||||
"name": "ESPAsyncWebServer",
|
||||
"version": "3.1.2",
|
||||
"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",
|
||||
@@ -27,8 +27,8 @@
|
||||
"dependencies": [
|
||||
{
|
||||
"owner": "mathieucarbou",
|
||||
"name": "Async TCP",
|
||||
"version": "^3.1.4",
|
||||
"name": "AsyncTCP",
|
||||
"version": "^3.2.4",
|
||||
"platforms": "espressif32"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=ESP Async WebServer
|
||||
version=3.0.6
|
||||
name=ESPAsyncWebServer
|
||||
version=3.1.2
|
||||
author=Me-No-Dev
|
||||
maintainer=Mathieu Carbou <mathieu.carbou@gmail.com>
|
||||
sentence=Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
|
||||
|
||||
80
lib/ESP Async WebServer/platformio.ini
Normal file
80
lib/ESP Async WebServer/platformio.ini
Normal file
@@ -0,0 +1,80 @@
|
||||
[env]
|
||||
framework = arduino
|
||||
build_flags =
|
||||
-Wall -Wextra
|
||||
-D CONFIG_ARDUHAL_LOG_COLORS
|
||||
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
|
||||
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=3000
|
||||
-D CONFIG_ASYNC_TCP_PRIORITY=10
|
||||
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||
upload_protocol = esptool
|
||||
monitor_speed = 115200
|
||||
monitor_filters = esp32_exception_decoder, log2file
|
||||
|
||||
[platformio]
|
||||
lib_dir = .
|
||||
; src_dir = examples/CaptivePortal
|
||||
src_dir = examples/SimpleServer
|
||||
; src_dir = examples/StreamFiles
|
||||
; src_dir = examples/Filters
|
||||
; src_dir = examples/Draft
|
||||
; src_dir = examples/issues/Issue14
|
||||
|
||||
[env:arduino]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.1.0
|
||||
mathieucarbou/AsyncTCP @ 3.2.4
|
||||
|
||||
[env:arduino-2]
|
||||
platform = espressif32@6.7.0
|
||||
board = esp32dev
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.1.0
|
||||
mathieucarbou/AsyncTCP @ 3.2.4
|
||||
|
||||
[env:arduino-3]
|
||||
platform = espressif32
|
||||
platform_packages=
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.3
|
||||
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.3/esp32-arduino-libs-3.0.3.zip
|
||||
board = esp32dev
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.1.0
|
||||
mathieucarbou/AsyncTCP @ 3.2.4
|
||||
|
||||
[env:esp8266]
|
||||
platform = espressif8266
|
||||
board = huzzah
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.1.0
|
||||
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.1.0
|
||||
khoih-prog/AsyncTCP_RP2040W @ 1.2.0
|
||||
|
||||
[env:pioarduino-esp32dev]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32dev
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.1.0
|
||||
mathieucarbou/AsyncTCP @ 3.2.3
|
||||
|
||||
[env:pioarduino-c6]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.03/platform-espressif32.zip
|
||||
board = esp32-c6-devkitc-1
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.1.0
|
||||
mathieucarbou/AsyncTCP @ 3.2.4
|
||||
@@ -22,26 +22,29 @@
|
||||
#include <rom/ets_sys.h>
|
||||
#endif
|
||||
#include "AsyncEventSource.h"
|
||||
#include "literals.h"
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
static String generateEventMessage(const char* message, const char* event, uint32_t id, uint32_t reconnect) {
|
||||
String ev;
|
||||
|
||||
if (reconnect) {
|
||||
ev += F("retry: ");
|
||||
ev += T_retry_;
|
||||
ev += reconnect;
|
||||
ev += F("\r\n");
|
||||
ev += T_rn;
|
||||
}
|
||||
|
||||
if (id) {
|
||||
ev += F("id: ");
|
||||
ev += String(id);
|
||||
ev += F("\r\n");
|
||||
ev += T_id__;
|
||||
ev += id;
|
||||
ev += T_rn;
|
||||
}
|
||||
|
||||
if (event != NULL) {
|
||||
ev += F("event: ");
|
||||
ev += String(event);
|
||||
ev += F("\r\n");
|
||||
ev += T_event_;
|
||||
ev += event;
|
||||
ev += T_rn;
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
@@ -57,9 +60,9 @@ static String generateEventMessage(const char* message, const char* event, uint3
|
||||
if (ldata != NULL) {
|
||||
memcpy(ldata, lineStart, llen);
|
||||
ldata[llen] = 0;
|
||||
ev += F("data: ");
|
||||
ev += T_data_;
|
||||
ev += ldata;
|
||||
ev += F("\r\n\r\n");
|
||||
ev += T_rnrn;
|
||||
free(ldata);
|
||||
}
|
||||
lineStart = (char*)message + messageLen;
|
||||
@@ -92,14 +95,14 @@ static String generateEventMessage(const char* message, const char* event, uint3
|
||||
if (ldata != NULL) {
|
||||
memcpy(ldata, lineStart, llen);
|
||||
ldata[llen] = 0;
|
||||
ev += F("data: ");
|
||||
ev += T_data_;
|
||||
ev += ldata;
|
||||
ev += F("\r\n");
|
||||
ev += T_rn;
|
||||
free(ldata);
|
||||
}
|
||||
lineStart = nextLine;
|
||||
if (lineStart == ((char*)message + messageLen))
|
||||
ev += F("\r\n");
|
||||
ev += T_rn;
|
||||
}
|
||||
} while (lineStart < ((char*)message + messageLen));
|
||||
}
|
||||
@@ -158,8 +161,8 @@ AsyncEventSourceClient::AsyncEventSourceClient(AsyncWebServerRequest* request, A
|
||||
_client = request->client();
|
||||
_server = server;
|
||||
_lastId = 0;
|
||||
if (request->hasHeader(F("Last-Event-ID")))
|
||||
_lastId = atoi(request->getHeader(F("Last-Event-ID"))->value().c_str());
|
||||
if (request->hasHeader(T_Last_Event_ID))
|
||||
_lastId = atoi(request->getHeader(T_Last_Event_ID)->value().c_str());
|
||||
|
||||
_client->setRxTimeout(0);
|
||||
_client->onError(NULL, NULL);
|
||||
@@ -360,8 +363,8 @@ bool AsyncEventSource::canHandle(AsyncWebServerRequest* request) {
|
||||
if (request->method() != HTTP_GET || !request->url().equals(_url)) {
|
||||
return false;
|
||||
}
|
||||
request->addInterestingHeader(F("Last-Event-ID"));
|
||||
request->addInterestingHeader("Cookie");
|
||||
request->addInterestingHeader(T_Last_Event_ID);
|
||||
request->addInterestingHeader(T_Cookie);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -382,10 +385,10 @@ void AsyncEventSource::handleRequest(AsyncWebServerRequest* request) {
|
||||
AsyncEventSourceResponse::AsyncEventSourceResponse(AsyncEventSource* server) {
|
||||
_server = server;
|
||||
_code = 200;
|
||||
_contentType = F("text/event-stream");
|
||||
_contentType = T_text_event_stream;
|
||||
_sendContentLength = false;
|
||||
addHeader(F("Cache-Control"), F("no-cache"));
|
||||
addHeader(F("Connection"), F("keep-alive"));
|
||||
addHeader(T_Cache_Control, T_no_cache);
|
||||
addHeader(T_Connection, T_keep_alive);
|
||||
}
|
||||
|
||||
void AsyncEventSourceResponse::_respond(AsyncWebServerRequest* request) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/endpoint");
|
||||
handler->onRequest([](AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
JsonObject& jsonObj = json.as<JsonObject>();
|
||||
JsonObject jsonObj = json.as<JsonObject>();
|
||||
// ...
|
||||
});
|
||||
server.addHandler(handler);
|
||||
@@ -36,7 +36,8 @@
|
||||
#define ASYNC_JSON_H_
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Print.h>
|
||||
|
||||
#include "ChunkPrint.h"
|
||||
|
||||
#if ARDUINOJSON_VERSION_MAJOR == 6
|
||||
#ifndef DYNAMIC_JSON_DOCUMENT_SIZE
|
||||
@@ -50,33 +51,6 @@ constexpr const char* JSON_MIMETYPE = "application/json";
|
||||
* Json Response
|
||||
* */
|
||||
|
||||
class ChunkPrint : public Print {
|
||||
private:
|
||||
uint8_t* _destination;
|
||||
size_t _to_skip;
|
||||
size_t _to_write;
|
||||
size_t _pos;
|
||||
|
||||
public:
|
||||
ChunkPrint(uint8_t* destination, size_t from, size_t len)
|
||||
: _destination(destination), _to_skip(from), _to_write(len), _pos{0} {}
|
||||
virtual ~ChunkPrint() {}
|
||||
size_t write(uint8_t c) {
|
||||
if (_to_skip > 0) {
|
||||
_to_skip--;
|
||||
return 1;
|
||||
} else if (_to_write > 0) {
|
||||
_to_write--;
|
||||
_destination[_pos++] = c;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
size_t write(const uint8_t* buffer, size_t size) {
|
||||
return this->Print::write(buffer, size);
|
||||
}
|
||||
};
|
||||
|
||||
class AsyncJsonResponse : public AsyncAbstractResponse {
|
||||
protected:
|
||||
#if ARDUINOJSON_VERSION_MAJOR == 5
|
||||
@@ -199,10 +173,10 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
||||
|
||||
public:
|
||||
#if ARDUINOJSON_VERSION_MAJOR == 6
|
||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
|
||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest = nullptr, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
|
||||
: _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
|
||||
#else
|
||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest)
|
||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest = nullptr)
|
||||
: _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
|
||||
#endif
|
||||
|
||||
|
||||
145
lib/ESP Async WebServer/src/AsyncMessagePack.h
Normal file
145
lib/ESP Async WebServer/src/AsyncMessagePack.h
Normal file
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
server.on("/msg_pack", HTTP_ANY, [](AsyncWebServerRequest * request) {
|
||||
AsyncMessagePackResponse * response = new AsyncMessagePackResponse();
|
||||
JsonObject& root = response->getRoot();
|
||||
root["key1"] = "key number one";
|
||||
JsonObject& nested = root.createNestedObject("nested");
|
||||
nested["key1"] = "key number one";
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
--------------------
|
||||
|
||||
AsyncCallbackMessagePackWebHandler* handler = new AsyncCallbackMessagePackWebHandler("/msg_pack/endpoint");
|
||||
handler->onRequest([](AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
JsonObject jsonObj = json.as<JsonObject>();
|
||||
// ...
|
||||
});
|
||||
server.addHandler(handler);
|
||||
*/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
#include "ChunkPrint.h"
|
||||
#include "literals.h"
|
||||
|
||||
class AsyncMessagePackResponse : public AsyncAbstractResponse {
|
||||
protected:
|
||||
JsonDocument _jsonBuffer;
|
||||
JsonVariant _root;
|
||||
bool _isValid;
|
||||
|
||||
public:
|
||||
AsyncMessagePackResponse(bool isArray = false) : _isValid{false} {
|
||||
_code = 200;
|
||||
_contentType = asyncsrv::T_application_msgpack;
|
||||
if (isArray)
|
||||
_root = _jsonBuffer.add<JsonArray>();
|
||||
else
|
||||
_root = _jsonBuffer.add<JsonObject>();
|
||||
}
|
||||
|
||||
JsonVariant& getRoot() { return _root; }
|
||||
|
||||
bool _sourceValid() const { return _isValid; }
|
||||
|
||||
size_t setLength() {
|
||||
_contentLength = measureMsgPack(_root);
|
||||
if (_contentLength) {
|
||||
_isValid = true;
|
||||
}
|
||||
return _contentLength;
|
||||
}
|
||||
|
||||
size_t getSize() const { return _jsonBuffer.size(); }
|
||||
|
||||
size_t _fillBuffer(uint8_t* data, size_t len) {
|
||||
ChunkPrint dest(data, _sentLength, len);
|
||||
serializeMsgPack(_root, dest);
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
class AsyncCallbackMessagePackWebHandler : public AsyncWebHandler {
|
||||
public:
|
||||
typedef std::function<void(AsyncWebServerRequest* request, JsonVariant& json)> ArJsonRequestHandlerFunction;
|
||||
|
||||
protected:
|
||||
const String _uri;
|
||||
WebRequestMethodComposite _method;
|
||||
ArJsonRequestHandlerFunction _onRequest;
|
||||
size_t _contentLength;
|
||||
size_t _maxContentLength;
|
||||
|
||||
public:
|
||||
AsyncCallbackMessagePackWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest = nullptr)
|
||||
: _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
|
||||
|
||||
void setMethod(WebRequestMethodComposite method) { _method = method; }
|
||||
void setMaxContentLength(int maxContentLength) { _maxContentLength = maxContentLength; }
|
||||
void onRequest(ArJsonRequestHandlerFunction fn) { _onRequest = fn; }
|
||||
|
||||
virtual bool canHandle(AsyncWebServerRequest* request) override final {
|
||||
if (!_onRequest)
|
||||
return false;
|
||||
|
||||
WebRequestMethodComposite request_method = request->method();
|
||||
if (!(_method & request_method))
|
||||
return false;
|
||||
|
||||
if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/")))
|
||||
return false;
|
||||
|
||||
if (request_method != HTTP_GET && !request->contentType().equalsIgnoreCase(asyncsrv::T_application_msgpack))
|
||||
return false;
|
||||
|
||||
request->addInterestingHeader("ANY");
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void handleRequest(AsyncWebServerRequest* request) override final {
|
||||
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
if (_onRequest) {
|
||||
if (request->method() == HTTP_GET) {
|
||||
JsonVariant json;
|
||||
_onRequest(request, json);
|
||||
return;
|
||||
|
||||
} else if (request->_tempObject != NULL) {
|
||||
JsonDocument jsonBuffer;
|
||||
DeserializationError error = deserializeMsgPack(jsonBuffer, (uint8_t*)(request->_tempObject));
|
||||
|
||||
if (!error) {
|
||||
JsonVariant json = jsonBuffer.as<JsonVariant>();
|
||||
_onRequest(request, json);
|
||||
return;
|
||||
}
|
||||
}
|
||||
request->send(_contentLength > _maxContentLength ? 413 : 400);
|
||||
} else {
|
||||
request->send(500);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void handleUpload(__unused AsyncWebServerRequest* request, __unused const String& filename, __unused size_t index, __unused uint8_t* data, __unused size_t len, __unused bool final) override final {}
|
||||
|
||||
virtual void handleBody(AsyncWebServerRequest* request, uint8_t* data, size_t len, size_t index, size_t total) override final {
|
||||
if (_onRequest) {
|
||||
_contentLength = total;
|
||||
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) {
|
||||
request->_tempObject = malloc(total);
|
||||
}
|
||||
if (request->_tempObject != NULL) {
|
||||
memcpy((uint8_t*)(request->_tempObject) + index, data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isRequestHandlerTrivial() override final { return _onRequest ? false : true; }
|
||||
};
|
||||
@@ -38,6 +38,9 @@
|
||||
|
||||
#define MAX_PRINTF_LEN 64
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
|
||||
size_t webSocketSendFrameWindow(AsyncClient* client) {
|
||||
if (!client->canSend())
|
||||
return 0;
|
||||
@@ -613,7 +616,7 @@ size_t AsyncWebSocketClient::printf(const char* format, ...) {
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
size_t AsyncWebSocketClient::printf_P(PGM_P formatP, ...) {
|
||||
va_list arg;
|
||||
va_start(arg, formatP);
|
||||
@@ -680,7 +683,7 @@ void AsyncWebSocketClient::text(const String& message) {
|
||||
text(message.c_str(), message.length());
|
||||
}
|
||||
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
void AsyncWebSocketClient::text(const __FlashStringHelper* data) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
|
||||
@@ -699,7 +702,7 @@ void AsyncWebSocketClient::text(const __FlashStringHelper* data) {
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
|
||||
void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer* buffer) {
|
||||
if (buffer) {
|
||||
@@ -728,7 +731,7 @@ void AsyncWebSocketClient::binary(const String& message) {
|
||||
binary(message.c_str(), message.length());
|
||||
}
|
||||
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
void AsyncWebSocketClient::binary(const __FlashStringHelper* data, size_t len) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
char* message = (char*)malloc(len);
|
||||
@@ -739,6 +742,7 @@ void AsyncWebSocketClient::binary(const __FlashStringHelper* data, size_t len) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
IPAddress AsyncWebSocketClient::remoteIP() const {
|
||||
if (!_client)
|
||||
return IPAddress((uint32_t)0U);
|
||||
@@ -838,7 +842,8 @@ void AsyncWebSocket::text(uint32_t id, const char* message) {
|
||||
void AsyncWebSocket::text(uint32_t id, const String& message) {
|
||||
text(id, message.c_str(), message.length());
|
||||
}
|
||||
#ifndef ESP32
|
||||
|
||||
#ifdef ESP8266
|
||||
void AsyncWebSocket::text(uint32_t id, const __FlashStringHelper* data) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
|
||||
@@ -857,7 +862,8 @@ void AsyncWebSocket::text(uint32_t id, const __FlashStringHelper* data) {
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
|
||||
void AsyncWebSocket::text(uint32_t id, AsyncWebSocketMessageBuffer* buffer) {
|
||||
if (buffer) {
|
||||
text(id, std::move(buffer->_buffer));
|
||||
@@ -881,7 +887,7 @@ void AsyncWebSocket::textAll(const char* message) {
|
||||
void AsyncWebSocket::textAll(const String& message) {
|
||||
textAll(message.c_str(), message.length());
|
||||
}
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
void AsyncWebSocket::textAll(const __FlashStringHelper* data) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
|
||||
@@ -900,7 +906,7 @@ void AsyncWebSocket::textAll(const __FlashStringHelper* data) {
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
void AsyncWebSocket::textAll(AsyncWebSocketMessageBuffer* buffer) {
|
||||
if (buffer) {
|
||||
textAll(std::move(buffer->_buffer));
|
||||
@@ -927,7 +933,8 @@ void AsyncWebSocket::binary(uint32_t id, const char* message) {
|
||||
void AsyncWebSocket::binary(uint32_t id, const String& message) {
|
||||
binary(id, message.c_str(), message.length());
|
||||
}
|
||||
#ifndef ESP32
|
||||
|
||||
#ifdef ESP8266
|
||||
void AsyncWebSocket::binary(uint32_t id, const __FlashStringHelper* data, size_t len) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
char* message = (char*)malloc(len);
|
||||
@@ -937,7 +944,8 @@ void AsyncWebSocket::binary(uint32_t id, const __FlashStringHelper* data, size_t
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
|
||||
void AsyncWebSocket::binary(uint32_t id, AsyncWebSocketMessageBuffer* buffer) {
|
||||
if (buffer) {
|
||||
binary(id, std::move(buffer->_buffer));
|
||||
@@ -961,7 +969,8 @@ void AsyncWebSocket::binaryAll(const char* message) {
|
||||
void AsyncWebSocket::binaryAll(const String& message) {
|
||||
binaryAll(message.c_str(), message.length());
|
||||
}
|
||||
#ifndef ESP32
|
||||
|
||||
#ifdef ESP8266
|
||||
void AsyncWebSocket::binaryAll(const __FlashStringHelper* data, size_t len) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
char* message = (char*)malloc(len);
|
||||
@@ -971,7 +980,8 @@ void AsyncWebSocket::binaryAll(const __FlashStringHelper* data, size_t len) {
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
|
||||
void AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer* buffer) {
|
||||
if (buffer) {
|
||||
binaryAll(std::move(buffer->_buffer));
|
||||
@@ -1017,7 +1027,7 @@ size_t AsyncWebSocket::printfAll(const char* format, ...) {
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
size_t AsyncWebSocket::printf_P(uint32_t id, PGM_P formatP, ...) {
|
||||
AsyncWebSocketClient* c = client(id);
|
||||
if (c != NULL) {
|
||||
@@ -1108,7 +1118,7 @@ void AsyncWebSocket::handleRequest(AsyncWebServerRequest* request) {
|
||||
const AsyncWebHeader* version = request->getHeader(WS_STR_VERSION);
|
||||
if (version->value().toInt() != 13) {
|
||||
AsyncWebServerResponse* response = request->beginResponse(400);
|
||||
response->addHeader(WS_STR_VERSION, F("13"));
|
||||
response->addHeader(WS_STR_VERSION, T_13);
|
||||
request->send(response);
|
||||
return;
|
||||
}
|
||||
@@ -1173,7 +1183,7 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
|
||||
int len = base64_encode_block((const char*)hash, 20, buffer, &_state);
|
||||
len = base64_encode_blockend((buffer + len), &_state);
|
||||
addHeader(WS_STR_CONNECTION, WS_STR_UPGRADE);
|
||||
addHeader(WS_STR_UPGRADE, F("websocket"));
|
||||
addHeader(WS_STR_UPGRADE, T_WS);
|
||||
addHeader(WS_STR_ACCEPT, buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -306,19 +306,19 @@ class AsyncWebSocket : public AsyncWebHandler {
|
||||
void text(uint32_t id, const char* message, size_t len);
|
||||
void text(uint32_t id, const char* message);
|
||||
void text(uint32_t id, const String& message);
|
||||
#ifndef ESP32
|
||||
void text(uint32_t id, const __FlashStringHelper* message);
|
||||
#endif // ESP32
|
||||
void text(uint32_t id, AsyncWebSocketMessageBuffer* buffer);
|
||||
void text(uint32_t id, AsyncWebSocketSharedBuffer buffer);
|
||||
#ifdef ESP8266
|
||||
void text(uint32_t id, const __FlashStringHelper* message);
|
||||
#endif // ESP8266
|
||||
|
||||
void textAll(const uint8_t* message, size_t len);
|
||||
void textAll(const char* message, size_t len);
|
||||
void textAll(const char* message);
|
||||
void textAll(const String& message);
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
void textAll(const __FlashStringHelper* message);
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
void textAll(AsyncWebSocketMessageBuffer* buffer);
|
||||
void textAll(AsyncWebSocketSharedBuffer buffer);
|
||||
|
||||
@@ -326,9 +326,9 @@ class AsyncWebSocket : public AsyncWebHandler {
|
||||
void binary(uint32_t id, const char* message, size_t len);
|
||||
void binary(uint32_t id, const char* message);
|
||||
void binary(uint32_t id, const String& message);
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
void binary(uint32_t id, const __FlashStringHelper* message, size_t len);
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
void binary(uint32_t id, AsyncWebSocketMessageBuffer* buffer);
|
||||
void binary(uint32_t id, AsyncWebSocketSharedBuffer buffer);
|
||||
|
||||
@@ -336,16 +336,16 @@ class AsyncWebSocket : public AsyncWebHandler {
|
||||
void binaryAll(const char* message, size_t len);
|
||||
void binaryAll(const char* message);
|
||||
void binaryAll(const String& message);
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
void binaryAll(const __FlashStringHelper* message, size_t len);
|
||||
#endif // ESP32
|
||||
#endif // ESP8266
|
||||
void binaryAll(AsyncWebSocketMessageBuffer* buffer);
|
||||
void binaryAll(AsyncWebSocketSharedBuffer buffer);
|
||||
|
||||
size_t printf(uint32_t id, const char* format, ...) __attribute__((format(printf, 3, 4)));
|
||||
size_t printfAll(const char* format, ...) __attribute__((format(printf, 2, 3)));
|
||||
|
||||
#ifndef ESP32
|
||||
#ifdef ESP8266
|
||||
size_t printf_P(uint32_t id, PGM_P formatP, ...) __attribute__((format(printf, 3, 4)));
|
||||
size_t printfAll_P(PGM_P formatP, ...) __attribute__((format(printf, 2, 3)));
|
||||
#endif
|
||||
|
||||
32
lib/ESP Async WebServer/src/ChunkPrint.h
Normal file
32
lib/ESP Async WebServer/src/ChunkPrint.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef CHUNKPRINT_H
|
||||
#define CHUNKPRINT_H
|
||||
|
||||
#include <Print.h>
|
||||
|
||||
class ChunkPrint : public Print {
|
||||
private:
|
||||
uint8_t* _destination;
|
||||
size_t _to_skip;
|
||||
size_t _to_write;
|
||||
size_t _pos;
|
||||
|
||||
public:
|
||||
ChunkPrint(uint8_t* destination, size_t from, size_t len)
|
||||
: _destination(destination), _to_skip(from), _to_write(len), _pos{0} {}
|
||||
virtual ~ChunkPrint() {}
|
||||
size_t write(uint8_t c) {
|
||||
if (_to_skip > 0) {
|
||||
_to_skip--;
|
||||
return 1;
|
||||
} else if (_to_write > 0) {
|
||||
_to_write--;
|
||||
_destination[_pos++] = c;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
size_t write(const uint8_t* buffer, size_t size) {
|
||||
return this->Print::write(buffer, size);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
@@ -43,10 +43,12 @@
|
||||
#error Platform not supported
|
||||
#endif
|
||||
|
||||
#define ASYNCWEBSERVER_VERSION "3.0.6"
|
||||
#include "literals.h"
|
||||
|
||||
#define ASYNCWEBSERVER_VERSION "3.1.2"
|
||||
#define ASYNCWEBSERVER_VERSION_MAJOR 3
|
||||
#define ASYNCWEBSERVER_VERSION_MINOR 0
|
||||
#define ASYNCWEBSERVER_VERSION_REVISION 6
|
||||
#define ASYNCWEBSERVER_VERSION_MINOR 1
|
||||
#define ASYNCWEBSERVER_VERSION_REVISION 2
|
||||
#define ASYNCWEBSERVER_FORK_mathieucarbou
|
||||
|
||||
#ifdef ASYNCWEBSERVER_REGEX
|
||||
@@ -151,7 +153,7 @@ class AsyncWebHeader {
|
||||
|
||||
const String& name() const { return _name; }
|
||||
const String& value() const { return _value; }
|
||||
String toString() const { return _name + F(": ") + _value + F("\r\n"); }
|
||||
String toString() const { return _name + (char)0x3a + (char)0x20 /*": "*/ + _value + asyncsrv::T_rn; }
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -347,7 +349,9 @@ class AsyncWebServerRequest {
|
||||
|
||||
size_t params() const; // get arguments count
|
||||
bool hasParam(const String& name, bool post = false, bool file = false) const;
|
||||
bool hasParam(const __FlashStringHelper* data, bool post = false, bool file = false) const;
|
||||
#ifdef ESP8266
|
||||
bool hasParam(const __FlashStringHelper* data, bool post = false, bool file = false) const { return hasParam(String(data).c_str(), post, file); };
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get the Request parameter by name
|
||||
@@ -509,10 +513,13 @@ class AsyncWebServerResponse {
|
||||
size_t _ackedLength;
|
||||
size_t _writtenLength;
|
||||
WebResponseState _state;
|
||||
const char* _responseCodeToString(int code);
|
||||
|
||||
public:
|
||||
#ifndef ESP8266
|
||||
static const char* responseCodeToString(int code);
|
||||
#else
|
||||
static const __FlashStringHelper* responseCodeToString(int code);
|
||||
#endif
|
||||
|
||||
public:
|
||||
AsyncWebServerResponse();
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
// to please Arduino Lint
|
||||
#include "ESPAsyncWebServer.h"
|
||||
@@ -25,6 +25,9 @@
|
||||
#else
|
||||
#include "md5.h"
|
||||
#endif
|
||||
#include "literals.h"
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
// Basic Auth hash = base64("username:password")
|
||||
|
||||
@@ -133,16 +136,16 @@ String generateDigestHash(const char* username, const char* password, const char
|
||||
}
|
||||
|
||||
String requestDigestAuthentication(const char* realm) {
|
||||
String header = F("realm=\"");
|
||||
String header(T_realm__);
|
||||
if (realm == NULL)
|
||||
header.concat(F("asyncesp"));
|
||||
header.concat(T_asyncesp);
|
||||
else
|
||||
header.concat(realm);
|
||||
header.concat(F("\", qop=\"auth\", nonce=\""));
|
||||
header.concat(T_auth_nonce);
|
||||
header.concat(genRandomMD5());
|
||||
header.concat(F("\", opaque=\""));
|
||||
header.concat(T__opaque);
|
||||
header.concat(genRandomMD5());
|
||||
header += '"';
|
||||
header += (char)0x22; // '"'
|
||||
return header;
|
||||
}
|
||||
|
||||
@@ -173,7 +176,8 @@ bool checkDigestAuthentication(const char* header, const __FlashStringHelper* me
|
||||
String myNc;
|
||||
String myCnonce;
|
||||
|
||||
myHeader += F(", ");
|
||||
myHeader += (char)0x2c; // ','
|
||||
myHeader += (char)0x20; // ' '
|
||||
do {
|
||||
String avLine(myHeader.substring(0, nextBreak));
|
||||
avLine.trim();
|
||||
@@ -191,42 +195,42 @@ bool checkDigestAuthentication(const char* header, const __FlashStringHelper* me
|
||||
avLine = avLine.substring(1, avLine.length() - 1);
|
||||
}
|
||||
|
||||
if (varName.equals(F("username"))) {
|
||||
if (varName.equals(T_username)) {
|
||||
if (!avLine.equals(username)) {
|
||||
// os_printf("AUTH FAIL: username\n");
|
||||
return false;
|
||||
}
|
||||
myUsername = avLine;
|
||||
} else if (varName.equals(F("realm"))) {
|
||||
} else if (varName.equals(T_realm)) {
|
||||
if (realm != NULL && !avLine.equals(realm)) {
|
||||
// os_printf("AUTH FAIL: realm\n");
|
||||
return false;
|
||||
}
|
||||
myRealm = avLine;
|
||||
} else if (varName.equals(F("nonce"))) {
|
||||
} else if (varName.equals(T_nonce)) {
|
||||
if (nonce != NULL && !avLine.equals(nonce)) {
|
||||
// os_printf("AUTH FAIL: nonce\n");
|
||||
return false;
|
||||
}
|
||||
myNonce = avLine;
|
||||
} else if (varName.equals(F("opaque"))) {
|
||||
} else if (varName.equals(T_opaque)) {
|
||||
if (opaque != NULL && !avLine.equals(opaque)) {
|
||||
// os_printf("AUTH FAIL: opaque\n");
|
||||
return false;
|
||||
}
|
||||
} else if (varName.equals(F("uri"))) {
|
||||
} else if (varName.equals(T_uri)) {
|
||||
if (uri != NULL && !avLine.equals(uri)) {
|
||||
// os_printf("AUTH FAIL: uri\n");
|
||||
return false;
|
||||
}
|
||||
myUri = avLine;
|
||||
} else if (varName.equals(F("response"))) {
|
||||
} else if (varName.equals(T_response)) {
|
||||
myResponse = avLine;
|
||||
} else if (varName.equals(F("qop"))) {
|
||||
} else if (varName.equals(T_qop)) {
|
||||
myQop = avLine;
|
||||
} else if (varName.equals(F("nc"))) {
|
||||
} else if (varName.equals(T_nc)) {
|
||||
myNc = avLine;
|
||||
} else if (varName.equals(F("cnonce"))) {
|
||||
} else if (varName.equals(T_cnonce)) {
|
||||
myCnonce = avLine;
|
||||
}
|
||||
} while (nextBreak > 0);
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "WebHandlerImpl.h"
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
|
||||
AsyncStaticWebHandler::AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control)
|
||||
: _fs(fs), _uri(uri), _path(path), _default_file(F("index.htm")), _cache_control(cache_control), _last_modified(), _callback(nullptr) {
|
||||
// Ensure leading '/'
|
||||
@@ -222,22 +225,22 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest* request) {
|
||||
} else {
|
||||
etag = String(request->_tempFile.size());
|
||||
}
|
||||
if (_last_modified.length() && _last_modified == request->header(F("If-Modified-Since"))) {
|
||||
if (_last_modified.length() && _last_modified == request->header(T_IMS)) {
|
||||
request->_tempFile.close();
|
||||
request->send(304); // Not modified
|
||||
} else if (_cache_control.length() && request->hasHeader(F("If-None-Match")) && request->header(F("If-None-Match")).equals(etag)) {
|
||||
} else if (_cache_control.length() && request->hasHeader(T_INM) && request->header(T_INM).equals(etag)) {
|
||||
request->_tempFile.close();
|
||||
AsyncWebServerResponse* response = new AsyncBasicResponse(304); // Not modified
|
||||
response->addHeader(F("Cache-Control"), _cache_control);
|
||||
response->addHeader(F("ETag"), etag);
|
||||
response->addHeader(T_Cache_Control, _cache_control);
|
||||
response->addHeader(T_ETag, etag);
|
||||
request->send(response);
|
||||
} else {
|
||||
AsyncWebServerResponse* response = new AsyncFileResponse(request->_tempFile, filename, String(), false, _callback);
|
||||
if (_last_modified.length())
|
||||
response->addHeader(F("Last-Modified"), _last_modified);
|
||||
response->addHeader(T_Last_Modified, _last_modified);
|
||||
if (_cache_control.length()) {
|
||||
response->addHeader(F("Cache-Control"), _cache_control);
|
||||
response->addHeader(F("ETag"), etag);
|
||||
response->addHeader(T_Cache_Control, _cache_control);
|
||||
response->addHeader(T_ETag, etag);
|
||||
}
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "WebAuthentication.h"
|
||||
#include "WebResponseImpl.h"
|
||||
|
||||
#ifndef ESP8266
|
||||
#define os_strlen strlen
|
||||
#endif
|
||||
#include "literals.h"
|
||||
#include <cstring>
|
||||
|
||||
#define __is_param_char(c) ((c) && ((c) != '{') && ((c) != '[') && ((c) != '&') && ((c) != '='))
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
enum { PARSE_REQ_START,
|
||||
PARSE_REQ_HEADERS,
|
||||
PARSE_REQ_BODY,
|
||||
@@ -113,9 +113,9 @@ void AsyncWebServerRequest::_onData(void* buf, size_t len) {
|
||||
_parsedLength += len;
|
||||
} else {
|
||||
if (_parsedLength == 0) {
|
||||
if (_contentType.startsWith(F("application/x-www-form-urlencoded"))) {
|
||||
if (_contentType.startsWith(T_app_xform_urlencoded)) {
|
||||
_isPlainPost = true;
|
||||
} else if (_contentType == F("text/plain") && __is_param_char(((char*)buf)[0])) {
|
||||
} else if (_contentType == T_text_plain && __is_param_char(((char*)buf)[0])) {
|
||||
size_t i = 0;
|
||||
while (i < len && __is_param_char(((char*)buf)[i++]))
|
||||
;
|
||||
@@ -153,7 +153,7 @@ void AsyncWebServerRequest::_onData(void* buf, size_t len) {
|
||||
}
|
||||
|
||||
void AsyncWebServerRequest::_removeNotInterestingHeaders() {
|
||||
if (std::any_of(std::begin(_interestingHeaders), std::end(_interestingHeaders), [](const String& str) { return str.equalsIgnoreCase(F("ANY")); }))
|
||||
if (std::any_of(std::begin(_interestingHeaders), std::end(_interestingHeaders), [](const String& str) { return str.equalsIgnoreCase(T_ANY); }))
|
||||
return; // nothing to do
|
||||
|
||||
for (auto iter = std::begin(_headers); iter != std::end(_headers);) {
|
||||
@@ -246,19 +246,19 @@ bool AsyncWebServerRequest::_parseReqHead() {
|
||||
String u = _temp.substring(m.length() + 1, index);
|
||||
_temp = _temp.substring(index + 1);
|
||||
|
||||
if (m == F("GET")) {
|
||||
if (m == T_GET) {
|
||||
_method = HTTP_GET;
|
||||
} else if (m == F("POST")) {
|
||||
} else if (m == T_POST) {
|
||||
_method = HTTP_POST;
|
||||
} else if (m == F("DELETE")) {
|
||||
} else if (m == T_DELETE) {
|
||||
_method = HTTP_DELETE;
|
||||
} else if (m == F("PUT")) {
|
||||
} else if (m == T_PUT) {
|
||||
_method = HTTP_PUT;
|
||||
} else if (m == F("PATCH")) {
|
||||
} else if (m == T_PATCH) {
|
||||
_method = HTTP_PATCH;
|
||||
} else if (m == F("HEAD")) {
|
||||
} else if (m == T_HEAD) {
|
||||
_method = HTTP_HEAD;
|
||||
} else if (m == F("OPTIONS")) {
|
||||
} else if (m == T_OPTIONS) {
|
||||
_method = HTTP_OPTIONS;
|
||||
}
|
||||
|
||||
@@ -271,67 +271,51 @@ bool AsyncWebServerRequest::_parseReqHead() {
|
||||
_url = urlDecode(u);
|
||||
_addGetParams(g);
|
||||
|
||||
if (!_temp.startsWith(F("HTTP/1.0")))
|
||||
if (!_temp.startsWith(T_HTTP_1_0))
|
||||
_version = 1;
|
||||
|
||||
_temp = String();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool strContains(const String& src, const String& find, bool mindcase = true) {
|
||||
int pos = 0, i = 0;
|
||||
const int slen = src.length();
|
||||
const int flen = find.length();
|
||||
|
||||
if (slen < flen)
|
||||
return false;
|
||||
while (pos <= (slen - flen)) {
|
||||
for (i = 0; i < flen; i++) {
|
||||
if (mindcase) {
|
||||
if (src[pos + i] != find[i])
|
||||
i = flen + 1; // no match
|
||||
} else if (tolower(src[pos + i]) != tolower(find[i])) {
|
||||
i = flen + 1; // no match
|
||||
}
|
||||
}
|
||||
if (i == flen)
|
||||
return true;
|
||||
pos++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AsyncWebServerRequest::_parseReqHeader() {
|
||||
int index = _temp.indexOf(':');
|
||||
if (index) {
|
||||
String name = _temp.substring(0, index);
|
||||
String value = _temp.substring(index + 2);
|
||||
if (name.equalsIgnoreCase("Host")) {
|
||||
String name(_temp.substring(0, index));
|
||||
String value(_temp.substring(index + 2));
|
||||
if (name.equalsIgnoreCase(T_Host)) {
|
||||
_host = value;
|
||||
} else if (name.equalsIgnoreCase(F("Content-Type"))) {
|
||||
} else if (name.equalsIgnoreCase(T_Content_Type)) {
|
||||
_contentType = value.substring(0, value.indexOf(';'));
|
||||
if (value.startsWith(F("multipart/"))) {
|
||||
if (value.startsWith(T_MULTIPART_)) {
|
||||
_boundary = value.substring(value.indexOf('=') + 1);
|
||||
_boundary.replace(String('"'), String());
|
||||
_isMultipart = true;
|
||||
}
|
||||
} else if (name.equalsIgnoreCase(F("Content-Length"))) {
|
||||
} else if (name.equalsIgnoreCase(T_Content_Length)) {
|
||||
_contentLength = atoi(value.c_str());
|
||||
} else if (name.equalsIgnoreCase(F("Expect")) && value == F("100-continue")) {
|
||||
} else if (name.equalsIgnoreCase(T_EXPECT) && value == T_100_CONTINUE) {
|
||||
_expectingContinue = true;
|
||||
} else if (name.equalsIgnoreCase(F("Authorization"))) {
|
||||
if (value.length() > 5 && value.substring(0, 5).equalsIgnoreCase(F("Basic"))) {
|
||||
} else if (name.equalsIgnoreCase(T_AUTH)) {
|
||||
if (value.length() > 5 && value.substring(0, 5).equalsIgnoreCase(T_BASIC)) {
|
||||
_authorization = value.substring(6);
|
||||
} else if (value.length() > 6 && value.substring(0, 6).equalsIgnoreCase(F("Digest"))) {
|
||||
} else if (value.length() > 6 && value.substring(0, 6).equalsIgnoreCase(T_DIGEST)) {
|
||||
_isDigest = true;
|
||||
_authorization = value.substring(7);
|
||||
}
|
||||
} else {
|
||||
if (name.equalsIgnoreCase(F("Upgrade")) && value.equalsIgnoreCase(F("websocket"))) {
|
||||
if (name.equalsIgnoreCase(T_UPGRADE) && value.equalsIgnoreCase(T_WS)) {
|
||||
// WebSocket request can be uniquely identified by header: [Upgrade: websocket]
|
||||
_reqconntype = RCT_WS;
|
||||
} else {
|
||||
if (name.equalsIgnoreCase(F("Accept")) && strContains(value, F("text/event-stream"), false)) {
|
||||
} else if (name.equalsIgnoreCase(T_ACCEPT)){
|
||||
String lowcase(value);
|
||||
lowcase.toLowerCase();
|
||||
#ifndef ESP8266
|
||||
const char* substr = std::strstr(lowcase.c_str(), T_text_event_stream);
|
||||
#else
|
||||
const char* substr = std::strstr(lowcase.c_str(), String(T_text_event_stream).c_str());
|
||||
#endif
|
||||
if (substr != NULL) {
|
||||
// WebEvent request can be uniquely identified by header: [Accept: text/event-stream]
|
||||
_reqconntype = RCT_EVENT;
|
||||
}
|
||||
@@ -339,7 +323,12 @@ bool AsyncWebServerRequest::_parseReqHeader() {
|
||||
}
|
||||
_headers.emplace_back(name, value);
|
||||
}
|
||||
#ifndef TARGET_RP2040
|
||||
_temp.clear();
|
||||
#else
|
||||
// Ancient PRI core does not have String::clear() method 8-()
|
||||
_temp = String();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -347,14 +336,20 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data) {
|
||||
if (data && (char)data != '&')
|
||||
_temp += (char)data;
|
||||
if (!data || (char)data == '&' || _parsedLength == _contentLength) {
|
||||
String name = F("body");
|
||||
String value = _temp;
|
||||
if (!_temp.startsWith(String('{')) && !_temp.startsWith(String('[')) && _temp.indexOf('=') > 0) {
|
||||
String name(T_BODY);
|
||||
String value(_temp);
|
||||
if (!(_temp.charAt(0) == '{') && !(_temp.charAt(0) == '[') && _temp.indexOf('=') > 0) {
|
||||
name = _temp.substring(0, _temp.indexOf('='));
|
||||
value = _temp.substring(_temp.indexOf('=') + 1);
|
||||
}
|
||||
_params.emplace_back(urlDecode(name), urlDecode(value), true);
|
||||
_temp = String();
|
||||
|
||||
#ifndef TARGET_RP2040
|
||||
_temp.clear();
|
||||
#else
|
||||
// Ancient PRI core does not have String::clear() method 8-()
|
||||
_temp = String();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,17 +425,17 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last) {
|
||||
_temp += (char)data;
|
||||
if ((char)data == '\n') {
|
||||
if (_temp.length()) {
|
||||
if (_temp.length() > 12 && _temp.substring(0, 12).equalsIgnoreCase(F("Content-Type"))) {
|
||||
if (_temp.length() > 12 && _temp.substring(0, 12).equalsIgnoreCase(T_Content_Type)) {
|
||||
_itemType = _temp.substring(14);
|
||||
_itemIsFile = true;
|
||||
} else if (_temp.length() > 19 && _temp.substring(0, 19).equalsIgnoreCase(F("Content-Disposition"))) {
|
||||
} else if (_temp.length() > 19 && _temp.substring(0, 19).equalsIgnoreCase(T_Content_Disposition)) {
|
||||
_temp = _temp.substring(_temp.indexOf(';') + 2);
|
||||
while (_temp.indexOf(';') > 0) {
|
||||
String name = _temp.substring(0, _temp.indexOf('='));
|
||||
String nameVal = _temp.substring(_temp.indexOf('=') + 2, _temp.indexOf(';') - 1);
|
||||
if (name == F("name")) {
|
||||
if (name == T_name) {
|
||||
_itemName = nameVal;
|
||||
} else if (name == F("filename")) {
|
||||
} else if (name == T_filename) {
|
||||
_itemFilename = nameVal;
|
||||
_itemIsFile = true;
|
||||
}
|
||||
@@ -448,9 +443,9 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last) {
|
||||
}
|
||||
String name = _temp.substring(0, _temp.indexOf('='));
|
||||
String nameVal = _temp.substring(_temp.indexOf('=') + 2, _temp.length() - 1);
|
||||
if (name == F("name")) {
|
||||
if (name == T_name) {
|
||||
_itemName = nameVal;
|
||||
} else if (name == F("filename")) {
|
||||
} else if (name == T_filename) {
|
||||
_itemFilename = nameVal;
|
||||
_itemIsFile = true;
|
||||
}
|
||||
@@ -590,7 +585,7 @@ void AsyncWebServerRequest::_parseLine() {
|
||||
_server->_attachHandler(this);
|
||||
_removeNotInterestingHeaders();
|
||||
if (_expectingContinue) {
|
||||
String response = F("HTTP/1.1 100 Continue\r\n\r\n");
|
||||
String response(T_HTTP_100_CONT);
|
||||
_client->write(response.c_str(), response.length());
|
||||
}
|
||||
// check handler for authentication
|
||||
@@ -668,10 +663,6 @@ bool AsyncWebServerRequest::hasParam(const String& name, bool post, bool file) c
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AsyncWebServerRequest::hasParam(const __FlashStringHelper* data, bool post, bool file) const {
|
||||
return hasParam(String(data).c_str(), post, file);
|
||||
}
|
||||
|
||||
const AsyncWebParameter* AsyncWebServerRequest::getParam(const char* name, bool post, bool file) const {
|
||||
for (const auto& p : _params) {
|
||||
if (p.name() == name && p.isPost() == post && p.isFile() == file) {
|
||||
@@ -711,7 +702,7 @@ AsyncWebServerResponse* AsyncWebServerRequest::beginResponse(int code, const Str
|
||||
}
|
||||
|
||||
AsyncWebServerResponse* AsyncWebServerRequest::beginResponse(FS& fs, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback) {
|
||||
if (fs.exists(path) || (!download && fs.exists(path + F(".gz"))))
|
||||
if (fs.exists(path) || (!download && fs.exists(path + T__gz)))
|
||||
return new AsyncFileResponse(fs, path, contentType, download, callback);
|
||||
return NULL;
|
||||
}
|
||||
@@ -770,7 +761,7 @@ void AsyncWebServerRequest::send(int code, const String& contentType, PGM_P cont
|
||||
}
|
||||
|
||||
void AsyncWebServerRequest::send(FS& fs, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback) {
|
||||
if (fs.exists(path) || (!download && fs.exists(path + F(".gz")))) {
|
||||
if (fs.exists(path) || (!download && fs.exists(path + T__gz))) {
|
||||
send(beginResponse(fs, path, contentType, download, callback));
|
||||
} else
|
||||
send(404);
|
||||
@@ -797,7 +788,7 @@ void AsyncWebServerRequest::sendChunked(const String& contentType, AwsResponseFi
|
||||
|
||||
void AsyncWebServerRequest::redirect(const char* url) {
|
||||
AsyncWebServerResponse* response = beginResponse(302);
|
||||
response->addHeader(F("Location"), url);
|
||||
response->addHeader(T_LOCATION, url);
|
||||
send(response);
|
||||
}
|
||||
|
||||
@@ -838,16 +829,16 @@ bool AsyncWebServerRequest::authenticate(const char* hash) {
|
||||
void AsyncWebServerRequest::requestAuthentication(const char* realm, bool isDigest) {
|
||||
AsyncWebServerResponse* r = beginResponse(401);
|
||||
if (!isDigest && realm == NULL) {
|
||||
r->addHeader(F("WWW-Authenticate"), F("Basic realm=\"Login Required\""));
|
||||
r->addHeader(T_WWW_AUTH, T_BASIC_REALM_LOGIN_REQ);
|
||||
} else if (!isDigest) {
|
||||
String header = F("Basic realm=\"");
|
||||
String header(T_BASIC_REALM);
|
||||
header.concat(realm);
|
||||
header += '"';
|
||||
r->addHeader(F("WWW-Authenticate"), header);
|
||||
r->addHeader(T_WWW_AUTH, header);
|
||||
} else {
|
||||
String header = F("Digest ");
|
||||
String header(T_DIGEST_);
|
||||
header.concat(requestDigestAuthentication(realm));
|
||||
r->addHeader(F("WWW-Authenticate"), header);
|
||||
r->addHeader(T_WWW_AUTH, header);
|
||||
}
|
||||
send(r);
|
||||
}
|
||||
@@ -941,80 +932,80 @@ String AsyncWebServerRequest::urlDecode(const String& text) const {
|
||||
#ifndef ESP8266
|
||||
const char* AsyncWebServerRequest::methodToString() const {
|
||||
if (_method == HTTP_ANY)
|
||||
return "ANY";
|
||||
return T_ANY;
|
||||
if (_method & HTTP_GET)
|
||||
return "GET";
|
||||
return T_GET;
|
||||
if (_method & HTTP_POST)
|
||||
return "POST";
|
||||
return T_POST;
|
||||
if (_method & HTTP_DELETE)
|
||||
return "DELETE";
|
||||
return T_DELETE;
|
||||
if (_method & HTTP_PUT)
|
||||
return "PUT";
|
||||
return T_PUT;
|
||||
if (_method & HTTP_PATCH)
|
||||
return "PATCH";
|
||||
return T_PATCH;
|
||||
if (_method & HTTP_HEAD)
|
||||
return "HEAD";
|
||||
return T_HEAD;
|
||||
if (_method & HTTP_OPTIONS)
|
||||
return "OPTIONS";
|
||||
return "UNKNOWN";
|
||||
return T_OPTIONS;
|
||||
return T_UNKNOWN;
|
||||
}
|
||||
#else // ESP8266
|
||||
const __FlashStringHelper* AsyncWebServerRequest::methodToString() const {
|
||||
if (_method == HTTP_ANY)
|
||||
return FPSTR(T_ANY);
|
||||
if (_method & HTTP_GET)
|
||||
return FPSTR(T_GET);
|
||||
if (_method & HTTP_POST)
|
||||
return FPSTR(T_POST);
|
||||
if (_method & HTTP_DELETE)
|
||||
return FPSTR(T_DELETE);
|
||||
if (_method & HTTP_PUT)
|
||||
return FPSTR(T_PUT);
|
||||
if (_method & HTTP_PATCH)
|
||||
return FPSTR(T_PATCH);
|
||||
if (_method & HTTP_HEAD)
|
||||
return FPSTR(T_HEAD);
|
||||
if (_method & HTTP_OPTIONS)
|
||||
return FPSTR(T_OPTIONS);
|
||||
return FPSTR(T_UNKNOWN);
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
||||
#ifndef ESP8266
|
||||
const char* AsyncWebServerRequest::requestedConnTypeToString() const {
|
||||
switch (_reqconntype) {
|
||||
case RCT_NOT_USED:
|
||||
return "RCT_NOT_USED";
|
||||
return T_RCT_NOT_USED;
|
||||
case RCT_DEFAULT:
|
||||
return "RCT_DEFAULT";
|
||||
return T_RCT_DEFAULT;
|
||||
case RCT_HTTP:
|
||||
return "RCT_HTTP";
|
||||
return T_RCT_HTTP;
|
||||
case RCT_WS:
|
||||
return "RCT_WS";
|
||||
return T_RCT_WS;
|
||||
case RCT_EVENT:
|
||||
return "RCT_EVENT";
|
||||
return T_RCT_EVENT;
|
||||
default:
|
||||
return "ERROR";
|
||||
return T_ERROR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ESP8266
|
||||
const __FlashStringHelper* AsyncWebServerRequest::methodToString() const {
|
||||
if (_method == HTTP_ANY)
|
||||
return F("ANY");
|
||||
else if (_method & HTTP_GET)
|
||||
return F("GET");
|
||||
else if (_method & HTTP_POST)
|
||||
return F("POST");
|
||||
else if (_method & HTTP_DELETE)
|
||||
return F("DELETE");
|
||||
else if (_method & HTTP_PUT)
|
||||
return F("PUT");
|
||||
else if (_method & HTTP_PATCH)
|
||||
return F("PATCH");
|
||||
else if (_method & HTTP_HEAD)
|
||||
return F("HEAD");
|
||||
else if (_method & HTTP_OPTIONS)
|
||||
return F("OPTIONS");
|
||||
return F("UNKNOWN");
|
||||
}
|
||||
|
||||
#else // ESP8266
|
||||
const __FlashStringHelper* AsyncWebServerRequest::requestedConnTypeToString() const {
|
||||
switch (_reqconntype) {
|
||||
case RCT_NOT_USED:
|
||||
return F("RCT_NOT_USED");
|
||||
return FPSTR(T_RCT_NOT_USED);
|
||||
case RCT_DEFAULT:
|
||||
return F("RCT_DEFAULT");
|
||||
return FPSTR(T_RCT_DEFAULT);
|
||||
case RCT_HTTP:
|
||||
return F("RCT_HTTP");
|
||||
return FPSTR(T_RCT_HTTP);
|
||||
case RCT_WS:
|
||||
return F("RCT_WS");
|
||||
return FPSTR(T_RCT_WS);
|
||||
case RCT_EVENT:
|
||||
return F("RCT_EVENT");
|
||||
return FPSTR(T_RCT_EVENT);
|
||||
default:
|
||||
return F("ERROR");
|
||||
return FPSTR(T_ERROR);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // ESP8266
|
||||
|
||||
bool AsyncWebServerRequest::isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2, RequestedConnectionType erct3) {
|
||||
bool res = false;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "WebResponseImpl.h"
|
||||
#include "cbuf.h"
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
// Since ESP8266 does not link memchr by default, here's its implementation.
|
||||
void* memchr(void* ptr, int ch, size_t count) {
|
||||
unsigned char* p = static_cast<unsigned char*>(ptr);
|
||||
@@ -33,97 +35,185 @@ void* memchr(void* ptr, int ch, size_t count) {
|
||||
|
||||
/*
|
||||
* Abstract Response
|
||||
* */
|
||||
const char* AsyncWebServerResponse::_responseCodeToString(int code) {
|
||||
return reinterpret_cast<const char*>(responseCodeToString(code));
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
const __FlashStringHelper* AsyncWebServerResponse::responseCodeToString(int code) {
|
||||
#ifndef ESP8266
|
||||
const char* AsyncWebServerResponse::responseCodeToString(int code) {
|
||||
switch (code) {
|
||||
case 100:
|
||||
return F("Continue");
|
||||
return T_HTTP_CODE_100;
|
||||
case 101:
|
||||
return F("Switching Protocols");
|
||||
return T_HTTP_CODE_101;
|
||||
case 200:
|
||||
return F("OK");
|
||||
return T_HTTP_CODE_200;
|
||||
case 201:
|
||||
return F("Created");
|
||||
return T_HTTP_CODE_201;
|
||||
case 202:
|
||||
return F("Accepted");
|
||||
return T_HTTP_CODE_202;
|
||||
case 203:
|
||||
return F("Non-Authoritative Information");
|
||||
return T_HTTP_CODE_203;
|
||||
case 204:
|
||||
return F("No Content");
|
||||
return T_HTTP_CODE_204;
|
||||
case 205:
|
||||
return F("Reset Content");
|
||||
return T_HTTP_CODE_205;
|
||||
case 206:
|
||||
return F("Partial Content");
|
||||
return T_HTTP_CODE_206;
|
||||
case 300:
|
||||
return F("Multiple Choices");
|
||||
return T_HTTP_CODE_300;
|
||||
case 301:
|
||||
return F("Moved Permanently");
|
||||
return T_HTTP_CODE_301;
|
||||
case 302:
|
||||
return F("Found");
|
||||
return T_HTTP_CODE_302;
|
||||
case 303:
|
||||
return F("See Other");
|
||||
return T_HTTP_CODE_303;
|
||||
case 304:
|
||||
return F("Not Modified");
|
||||
return T_HTTP_CODE_304;
|
||||
case 305:
|
||||
return F("Use Proxy");
|
||||
return T_HTTP_CODE_305;
|
||||
case 307:
|
||||
return F("Temporary Redirect");
|
||||
return T_HTTP_CODE_307;
|
||||
case 400:
|
||||
return F("Bad Request");
|
||||
return T_HTTP_CODE_400;
|
||||
case 401:
|
||||
return F("Unauthorized");
|
||||
return T_HTTP_CODE_401;
|
||||
case 402:
|
||||
return F("Payment Required");
|
||||
return T_HTTP_CODE_402;
|
||||
case 403:
|
||||
return F("Forbidden");
|
||||
return T_HTTP_CODE_403;
|
||||
case 404:
|
||||
return F("Not Found");
|
||||
return T_HTTP_CODE_404;
|
||||
case 405:
|
||||
return F("Method Not Allowed");
|
||||
return T_HTTP_CODE_405;
|
||||
case 406:
|
||||
return F("Not Acceptable");
|
||||
return T_HTTP_CODE_406;
|
||||
case 407:
|
||||
return F("Proxy Authentication Required");
|
||||
return T_HTTP_CODE_407;
|
||||
case 408:
|
||||
return F("Request Time-out");
|
||||
return T_HTTP_CODE_408;
|
||||
case 409:
|
||||
return F("Conflict");
|
||||
return T_HTTP_CODE_409;
|
||||
case 410:
|
||||
return F("Gone");
|
||||
return T_HTTP_CODE_410;
|
||||
case 411:
|
||||
return F("Length Required");
|
||||
return T_HTTP_CODE_411;
|
||||
case 412:
|
||||
return F("Precondition Failed");
|
||||
return T_HTTP_CODE_412;
|
||||
case 413:
|
||||
return F("Request Entity Too Large");
|
||||
return T_HTTP_CODE_413;
|
||||
case 414:
|
||||
return F("Request-URI Too Large");
|
||||
return T_HTTP_CODE_414;
|
||||
case 415:
|
||||
return F("Unsupported Media Type");
|
||||
return T_HTTP_CODE_415;
|
||||
case 416:
|
||||
return F("Requested range not satisfiable");
|
||||
return T_HTTP_CODE_416;
|
||||
case 417:
|
||||
return F("Expectation Failed");
|
||||
return T_HTTP_CODE_417;
|
||||
case 500:
|
||||
return F("Internal Server Error");
|
||||
return T_HTTP_CODE_500;
|
||||
case 501:
|
||||
return F("Not Implemented");
|
||||
return T_HTTP_CODE_501;
|
||||
case 502:
|
||||
return F("Bad Gateway");
|
||||
return T_HTTP_CODE_502;
|
||||
case 503:
|
||||
return F("Service Unavailable");
|
||||
return T_HTTP_CODE_503;
|
||||
case 504:
|
||||
return F("Gateway Time-out");
|
||||
return T_HTTP_CODE_504;
|
||||
case 505:
|
||||
return F("HTTP Version not supported");
|
||||
return T_HTTP_CODE_505;
|
||||
default:
|
||||
return F("");
|
||||
return T_HTTP_CODE_ANY;
|
||||
}
|
||||
}
|
||||
#else // ESP8266
|
||||
const __FlashStringHelper* AsyncWebServerResponse::responseCodeToString(int code)
|
||||
{
|
||||
switch (code) {
|
||||
case 100:
|
||||
return FPSTR(T_HTTP_CODE_100);
|
||||
case 101:
|
||||
return FPSTR(T_HTTP_CODE_101);
|
||||
case 200:
|
||||
return FPSTR(T_HTTP_CODE_200);
|
||||
case 201:
|
||||
return FPSTR(T_HTTP_CODE_201);
|
||||
case 202:
|
||||
return FPSTR(T_HTTP_CODE_202);
|
||||
case 203:
|
||||
return FPSTR(T_HTTP_CODE_203);
|
||||
case 204:
|
||||
return FPSTR(T_HTTP_CODE_204);
|
||||
case 205:
|
||||
return FPSTR(T_HTTP_CODE_205);
|
||||
case 206:
|
||||
return FPSTR(T_HTTP_CODE_206);
|
||||
case 300:
|
||||
return FPSTR(T_HTTP_CODE_300);
|
||||
case 301:
|
||||
return FPSTR(T_HTTP_CODE_301);
|
||||
case 302:
|
||||
return FPSTR(T_HTTP_CODE_302);
|
||||
case 303:
|
||||
return FPSTR(T_HTTP_CODE_303);
|
||||
case 304:
|
||||
return FPSTR(T_HTTP_CODE_304);
|
||||
case 305:
|
||||
return FPSTR(T_HTTP_CODE_305);
|
||||
case 307:
|
||||
return FPSTR(T_HTTP_CODE_307);
|
||||
case 400:
|
||||
return FPSTR(T_HTTP_CODE_400);
|
||||
case 401:
|
||||
return FPSTR(T_HTTP_CODE_401);
|
||||
case 402:
|
||||
return FPSTR(T_HTTP_CODE_402);
|
||||
case 403:
|
||||
return FPSTR(T_HTTP_CODE_403);
|
||||
case 404:
|
||||
return FPSTR(T_HTTP_CODE_404);
|
||||
case 405:
|
||||
return FPSTR(T_HTTP_CODE_405);
|
||||
case 406:
|
||||
return FPSTR(T_HTTP_CODE_406);
|
||||
case 407:
|
||||
return FPSTR(T_HTTP_CODE_407);
|
||||
case 408:
|
||||
return FPSTR(T_HTTP_CODE_408);
|
||||
case 409:
|
||||
return FPSTR(T_HTTP_CODE_409);
|
||||
case 410:
|
||||
return FPSTR(T_HTTP_CODE_410);
|
||||
case 411:
|
||||
return FPSTR(T_HTTP_CODE_411);
|
||||
case 412:
|
||||
return FPSTR(T_HTTP_CODE_412);
|
||||
case 413:
|
||||
return FPSTR(T_HTTP_CODE_413);
|
||||
case 414:
|
||||
return FPSTR(T_HTTP_CODE_414);
|
||||
case 415:
|
||||
return FPSTR(T_HTTP_CODE_415);
|
||||
case 416:
|
||||
return FPSTR(T_HTTP_CODE_416);
|
||||
case 417:
|
||||
return FPSTR(T_HTTP_CODE_417);
|
||||
case 500:
|
||||
return FPSTR(T_HTTP_CODE_500);
|
||||
case 501:
|
||||
return FPSTR(T_HTTP_CODE_501);
|
||||
case 502:
|
||||
return FPSTR(T_HTTP_CODE_502);
|
||||
case 503:
|
||||
return FPSTR(T_HTTP_CODE_503);
|
||||
case 504:
|
||||
return FPSTR(T_HTTP_CODE_504);
|
||||
case 505:
|
||||
return FPSTR(T_HTTP_CODE_505);
|
||||
default:
|
||||
return FPSTR(T_HTTP_CODE_ANY);
|
||||
}
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
||||
AsyncWebServerResponse::AsyncWebServerResponse()
|
||||
: _code(0), _contentType(), _contentLength(0), _sendContentLength(true), _chunked(false), _headLength(0), _sentLength(0), _ackedLength(0), _writtenLength(0), _state(RESPONSE_SETUP) {
|
||||
@@ -155,15 +245,19 @@ void AsyncWebServerResponse::addHeader(const String& name, const String& value)
|
||||
|
||||
String AsyncWebServerResponse::_assembleHead(uint8_t version) {
|
||||
if (version) {
|
||||
addHeader(F("Accept-Ranges"), F("none"));
|
||||
addHeader(T_Accept_Ranges, T_none);
|
||||
if (_chunked)
|
||||
addHeader(F("Transfer-Encoding"), F("chunked"));
|
||||
addHeader(Transfer_Encoding, T_chunked);
|
||||
}
|
||||
String out = String();
|
||||
String out;
|
||||
int bufSize = 300;
|
||||
char buf[bufSize];
|
||||
|
||||
snprintf_P(buf, bufSize, PSTR("HTTP/1.%d %d %s\r\n"), version, _code, _responseCodeToString(_code));
|
||||
#ifndef ESP8266
|
||||
snprintf(buf, bufSize, "HTTP/1.%d %d %s\r\n", version, _code, responseCodeToString(_code));
|
||||
#else
|
||||
snprintf_P(buf, bufSize, PSTR("HTTP/1.%d %d %s\r\n"), version, _code, String(responseCodeToString(_code)).c_str());
|
||||
#endif
|
||||
out.concat(buf);
|
||||
|
||||
if (_sendContentLength) {
|
||||
@@ -181,7 +275,7 @@ String AsyncWebServerResponse::_assembleHead(uint8_t version) {
|
||||
}
|
||||
_headers.clear();
|
||||
|
||||
out.concat(F("\r\n"));
|
||||
out.concat(T_rn);
|
||||
_headLength = out.length();
|
||||
return out;
|
||||
}
|
||||
@@ -211,9 +305,9 @@ AsyncBasicResponse::AsyncBasicResponse(int code, const String& contentType, cons
|
||||
if (_content.length()) {
|
||||
_contentLength = _content.length();
|
||||
if (!_contentType.length())
|
||||
_contentType = F("text/plain");
|
||||
_contentType = T_text_plain;
|
||||
}
|
||||
addHeader(F("Connection"), F("close"));
|
||||
addHeader(T_Connection, T_close);
|
||||
}
|
||||
|
||||
void AsyncBasicResponse::_respond(AsyncWebServerRequest* request) {
|
||||
@@ -291,7 +385,7 @@ AsyncAbstractResponse::AsyncAbstractResponse(AwsTemplateProcessor callback) : _c
|
||||
}
|
||||
|
||||
void AsyncAbstractResponse::_respond(AsyncWebServerRequest* request) {
|
||||
addHeader(F("Connection"), F("close"));
|
||||
addHeader(T_Connection, T_close);
|
||||
_head = _assembleHead(request->version());
|
||||
_state = RESPONSE_HEADERS;
|
||||
_ack(request, 0, 0);
|
||||
@@ -514,48 +608,52 @@ AsyncFileResponse::~AsyncFileResponse() {
|
||||
}
|
||||
|
||||
void AsyncFileResponse::_setContentType(const String& path) {
|
||||
#if HAVE_EXTERN_GET_CONTENT_TYPE_FUNCTION
|
||||
extern const __FlashStringHelper* getContentType(const String& path);
|
||||
#if HAVE_EXTERN_GET_Content_Type_FUNCTION
|
||||
#ifndef ESP8266
|
||||
extern const char* getContentType(const String& path);
|
||||
#else
|
||||
extern const __FlashStringHelper* getContentType(const String& path);
|
||||
#endif
|
||||
_contentType = getContentType(path);
|
||||
#else
|
||||
if (path.endsWith(F(".html")))
|
||||
_contentType = F("text/html");
|
||||
else if (path.endsWith(F(".htm")))
|
||||
_contentType = F("text/html");
|
||||
else if (path.endsWith(F(".css")))
|
||||
_contentType = F("text/css");
|
||||
else if (path.endsWith(F(".json")))
|
||||
_contentType = F("application/json");
|
||||
else if (path.endsWith(F(".js")))
|
||||
_contentType = F("application/javascript");
|
||||
else if (path.endsWith(F(".png")))
|
||||
_contentType = F("image/png");
|
||||
else if (path.endsWith(F(".gif")))
|
||||
_contentType = F("image/gif");
|
||||
else if (path.endsWith(F(".jpg")))
|
||||
_contentType = F("image/jpeg");
|
||||
else if (path.endsWith(F(".ico")))
|
||||
_contentType = F("image/x-icon");
|
||||
else if (path.endsWith(F(".svg")))
|
||||
_contentType = F("image/svg+xml");
|
||||
else if (path.endsWith(F(".eot")))
|
||||
_contentType = F("font/eot");
|
||||
else if (path.endsWith(F(".woff")))
|
||||
_contentType = F("font/woff");
|
||||
else if (path.endsWith(F(".woff2")))
|
||||
_contentType = F("font/woff2");
|
||||
else if (path.endsWith(F(".ttf")))
|
||||
_contentType = F("font/ttf");
|
||||
else if (path.endsWith(F(".xml")))
|
||||
_contentType = F("text/xml");
|
||||
else if (path.endsWith(F(".pdf")))
|
||||
_contentType = F("application/pdf");
|
||||
else if (path.endsWith(F(".zip")))
|
||||
_contentType = F("application/zip");
|
||||
else if (path.endsWith(F(".gz")))
|
||||
_contentType = F("application/x-gzip");
|
||||
if (path.endsWith(T__html))
|
||||
_contentType = T_text_html;
|
||||
else if (path.endsWith(T__htm))
|
||||
_contentType = T_text_html;
|
||||
else if (path.endsWith(T__css))
|
||||
_contentType = T_text_css;
|
||||
else if (path.endsWith(T__json))
|
||||
_contentType = T_application_json;
|
||||
else if (path.endsWith(T__js))
|
||||
_contentType = T_application_javascript;
|
||||
else if (path.endsWith(T__png))
|
||||
_contentType = T_image_png;
|
||||
else if (path.endsWith(T__gif))
|
||||
_contentType = T_image_gif;
|
||||
else if (path.endsWith(T__jpg))
|
||||
_contentType = T_image_jpeg;
|
||||
else if (path.endsWith(T__ico))
|
||||
_contentType = T_image_x_icon;
|
||||
else if (path.endsWith(T__svg))
|
||||
_contentType = T_image_svg_xml;
|
||||
else if (path.endsWith(T__eot))
|
||||
_contentType = T_font_eot;
|
||||
else if (path.endsWith(T__woff))
|
||||
_contentType = T_font_woff;
|
||||
else if (path.endsWith(T__woff2))
|
||||
_contentType = T_font_woff2;
|
||||
else if (path.endsWith(T__ttf))
|
||||
_contentType = T_font_ttf;
|
||||
else if (path.endsWith(T__xml))
|
||||
_contentType = T_text_xml;
|
||||
else if (path.endsWith(T__pdf))
|
||||
_contentType = T_application_pdf;
|
||||
else if (path.endsWith(T__zip))
|
||||
_contentType = T_application_zip;
|
||||
else if (path.endsWith(T__gz))
|
||||
_contentType = T_application_x_gzip;
|
||||
else
|
||||
_contentType = F("text/plain");
|
||||
_contentType = T_text_plain;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -563,9 +661,9 @@ AsyncFileResponse::AsyncFileResponse(FS& fs, const String& path, const String& c
|
||||
_code = 200;
|
||||
_path = path;
|
||||
|
||||
if (!download && !fs.exists(_path) && fs.exists(_path + F(".gz"))) {
|
||||
_path = _path + F(".gz");
|
||||
addHeader(F("Content-Encoding"), F("gzip"));
|
||||
if (!download && !fs.exists(_path) && fs.exists(_path + T__gz)) {
|
||||
_path = _path + T__gz;
|
||||
addHeader(T_Content_Encoding, T_gzip);
|
||||
_callback = nullptr; // Unable to process zipped templates
|
||||
_sendContentLength = true;
|
||||
_chunked = false;
|
||||
@@ -590,15 +688,15 @@ AsyncFileResponse::AsyncFileResponse(FS& fs, const String& path, const String& c
|
||||
// set filename and force rendering
|
||||
snprintf_P(buf, sizeof(buf), PSTR("inline"));
|
||||
}
|
||||
addHeader(F("Content-Disposition"), buf);
|
||||
addHeader(T_Content_Disposition, buf);
|
||||
}
|
||||
|
||||
AsyncFileResponse::AsyncFileResponse(File content, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback) : AsyncAbstractResponse(callback) {
|
||||
_code = 200;
|
||||
_path = path;
|
||||
|
||||
if (!download && String(content.name()).endsWith(F(".gz")) && !path.endsWith(F(".gz"))) {
|
||||
addHeader(F("Content-Encoding"), F("gzip"));
|
||||
if (!download && String(content.name()).endsWith(T__gz) && !path.endsWith(T__gz)) {
|
||||
addHeader(T_Content_Encoding, T_gzip);
|
||||
_callback = nullptr; // Unable to process gzipped templates
|
||||
_sendContentLength = true;
|
||||
_chunked = false;
|
||||
@@ -621,7 +719,7 @@ AsyncFileResponse::AsyncFileResponse(File content, const String& path, const Str
|
||||
} else {
|
||||
snprintf_P(buf, sizeof(buf), PSTR("inline"));
|
||||
}
|
||||
addHeader(F("Content-Disposition"), buf);
|
||||
addHeader(T_Content_Disposition, buf);
|
||||
}
|
||||
|
||||
size_t AsyncFileResponse::_fillBuffer(uint8_t* data, size_t len) {
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "ESPAsyncWebServer.h"
|
||||
#include "WebHandlerImpl.h"
|
||||
|
||||
using namespace asyncsrv;
|
||||
|
||||
bool ON_STA_FILTER(AsyncWebServerRequest* request) {
|
||||
return WiFi.localIP() == request->client()->localIP();
|
||||
}
|
||||
@@ -145,7 +147,7 @@ void AsyncWebServer::_attachHandler(AsyncWebServerRequest* request) {
|
||||
}
|
||||
}
|
||||
|
||||
request->addInterestingHeader(F("ANY"));
|
||||
request->addInterestingHeader(T_ANY);
|
||||
request->setHandler(_catchAllHandler);
|
||||
}
|
||||
|
||||
|
||||
343
lib/ESP Async WebServer/src/literals.h
Normal file
343
lib/ESP Async WebServer/src/literals.h
Normal file
@@ -0,0 +1,343 @@
|
||||
#pragma once
|
||||
|
||||
namespace asyncsrv {
|
||||
|
||||
#ifndef ESP8622
|
||||
static constexpr const char* T_100_CONTINUE = "100-continue";
|
||||
static constexpr const char* T_ACCEPT = "Accept";
|
||||
static constexpr const char* T_Accept_Ranges = "Accept-Ranges";
|
||||
static constexpr const char* T_app_xform_urlencoded = "application/x-www-form-urlencoded";
|
||||
static constexpr const char* T_AUTH = "Authorization";
|
||||
static constexpr const char* T_BASIC = "Basic";
|
||||
static constexpr const char* T_BASIC_REALM = "Basic realm=\"";
|
||||
static constexpr const char* T_BASIC_REALM_LOGIN_REQ = "Basic realm=\"Login Required\"";
|
||||
static constexpr const char* T_BODY = "body";
|
||||
static constexpr const char* T_Cache_Control = "Cache-Control";
|
||||
static constexpr const char* T_chunked = "chunked";
|
||||
static constexpr const char* T_close = "close";
|
||||
static constexpr const char* T_Connection = "Connection";
|
||||
static constexpr const char* T_Content_Disposition = "Content-Disposition";
|
||||
static constexpr const char* T_Content_Encoding = "Content-Encoding";
|
||||
static constexpr const char* T_Content_Length = "Content-Length";
|
||||
static constexpr const char* T_Content_Type = "Content-Type";
|
||||
static constexpr const char* T_Cookie = "Cookie";
|
||||
static constexpr const char* T_DIGEST = "Digest";
|
||||
static constexpr const char* T_DIGEST_ = "Digest ";
|
||||
static constexpr const char* T_ETag = "ETag";
|
||||
static constexpr const char* T_EXPECT = "Expect";
|
||||
static constexpr const char* T_HTTP_1_0 = "HTTP/1.0";
|
||||
static constexpr const char* T_HTTP_100_CONT = "HTTP/1.1 100 Continue\r\n\r\n";
|
||||
static constexpr const char* T_IMS = "If-Modified-Since";
|
||||
static constexpr const char* T_INM = "If-None-Match";
|
||||
static constexpr const char* T_keep_alive = "keep-alive";
|
||||
static constexpr const char* T_Last_Event_ID = "Last-Event-ID";
|
||||
static constexpr const char* T_Last_Modified = "Last-Modified";
|
||||
static constexpr const char* T_LOCATION = "Location";
|
||||
static constexpr const char* T_MULTIPART_ = "multipart/";
|
||||
static constexpr const char* T_no_cache = "no-cache";
|
||||
static constexpr const char* T_none = "none";
|
||||
static constexpr const char* T_UPGRADE = "Upgrade";
|
||||
static constexpr const char* T_WS = "websocket";
|
||||
static constexpr const char* T_WWW_AUTH = "WWW-Authenticate";
|
||||
static constexpr const char* Transfer_Encoding = "Transfer-Encoding";
|
||||
|
||||
// HTTP Methods
|
||||
static constexpr const char* T_ANY = "ANY";
|
||||
static constexpr const char* T_GET = "GET";
|
||||
static constexpr const char* T_POST = "POST";
|
||||
static constexpr const char* T_PUT = "PUT";
|
||||
static constexpr const char* T_DELETE = "DELETE";
|
||||
static constexpr const char* T_PATCH = "PATCH";
|
||||
static constexpr const char* T_HEAD = "HEAD";
|
||||
static constexpr const char* T_OPTIONS = "OPTIONS";
|
||||
static constexpr const char* T_UNKNOWN = "UNKNOWN";
|
||||
|
||||
// Req content types
|
||||
static constexpr const char* T_RCT_NOT_USED = "RCT_NOT_USED";
|
||||
static constexpr const char* T_RCT_DEFAULT = "RCT_DEFAULT";
|
||||
static constexpr const char* T_RCT_HTTP = "RCT_HTTP";
|
||||
static constexpr const char* T_RCT_WS = "RCT_WS";
|
||||
static constexpr const char* T_RCT_EVENT = "RCT_EVENT";
|
||||
static constexpr const char* T_ERROR = "ERROR";
|
||||
|
||||
// extentions & MIME-Types
|
||||
static constexpr const char* T__css = ".css";
|
||||
static constexpr const char* T__eot = ".eot";
|
||||
static constexpr const char* T__gif = ".gif";
|
||||
static constexpr const char* T__gz = ".gz";
|
||||
static constexpr const char* T__htm = ".htm";
|
||||
static constexpr const char* T__html = ".html";
|
||||
static constexpr const char* T__ico = ".ico";
|
||||
static constexpr const char* T__jpg = ".jpg";
|
||||
static constexpr const char* T__js = ".js";
|
||||
static constexpr const char* T__json = ".json";
|
||||
static constexpr const char* T__pdf = ".pdf";
|
||||
static constexpr const char* T__png = ".png";
|
||||
static constexpr const char* T__svg = ".svg";
|
||||
static constexpr const char* T__ttf = ".ttf";
|
||||
static constexpr const char* T__woff = ".woff";
|
||||
static constexpr const char* T__woff2 = ".woff2";
|
||||
static constexpr const char* T__xml = ".xml";
|
||||
static constexpr const char* T__zip = ".zip";
|
||||
static constexpr const char* T_application_javascript = "application/javascript";
|
||||
static constexpr const char* T_application_json = "application/json";
|
||||
static constexpr const char* T_application_msgpack = "application/msgpack";
|
||||
static constexpr const char* T_application_pdf = "application/pdf";
|
||||
static constexpr const char* T_application_x_gzip = "application/x-gzip";
|
||||
static constexpr const char* T_application_zip = "application/zip";
|
||||
static constexpr const char* T_font_eot = "font/eot";
|
||||
static constexpr const char* T_font_ttf = "font/ttf";
|
||||
static constexpr const char* T_font_woff = "font/woff";
|
||||
static constexpr const char* T_font_woff2 = "font/woff2";
|
||||
static constexpr const char* T_image_gif = "image/gif";
|
||||
static constexpr const char* T_image_jpeg = "image/jpeg";
|
||||
static constexpr const char* T_image_png = "image/png";
|
||||
static constexpr const char* T_image_svg_xml = "image/svg+xml";
|
||||
static constexpr const char* T_image_x_icon = "image/x-icon";
|
||||
static constexpr const char* T_text_css = "text/css";
|
||||
static constexpr const char* T_text_event_stream = "text/event-stream";
|
||||
static constexpr const char* T_text_html = "text/html";
|
||||
static constexpr const char* T_text_plain = "text/plain";
|
||||
static constexpr const char* T_text_xml = "text/xml";
|
||||
|
||||
// Responce codes
|
||||
static constexpr const char* T_HTTP_CODE_100 = "Continue";
|
||||
static constexpr const char* T_HTTP_CODE_101 = "Switching Protocols";
|
||||
static constexpr const char* T_HTTP_CODE_200 = "OK";
|
||||
static constexpr const char* T_HTTP_CODE_201 = "Created";
|
||||
static constexpr const char* T_HTTP_CODE_202 = "Accepted";
|
||||
static constexpr const char* T_HTTP_CODE_203 = "Non-Authoritative Information";
|
||||
static constexpr const char* T_HTTP_CODE_204 = "No Content";
|
||||
static constexpr const char* T_HTTP_CODE_205 = "Reset Content";
|
||||
static constexpr const char* T_HTTP_CODE_206 = "Partial Content";
|
||||
static constexpr const char* T_HTTP_CODE_300 = "Multiple Choices";
|
||||
static constexpr const char* T_HTTP_CODE_301 = "Moved Permanently";
|
||||
static constexpr const char* T_HTTP_CODE_302 = "Found";
|
||||
static constexpr const char* T_HTTP_CODE_303 = "See Other";
|
||||
static constexpr const char* T_HTTP_CODE_304 = "Not Modified";
|
||||
static constexpr const char* T_HTTP_CODE_305 = "Use Proxy";
|
||||
static constexpr const char* T_HTTP_CODE_307 = "Temporary Redirect";
|
||||
static constexpr const char* T_HTTP_CODE_400 = "Bad Request";
|
||||
static constexpr const char* T_HTTP_CODE_401 = "Unauthorized";
|
||||
static constexpr const char* T_HTTP_CODE_402 = "Payment Required";
|
||||
static constexpr const char* T_HTTP_CODE_403 = "Forbidden";
|
||||
static constexpr const char* T_HTTP_CODE_404 = "Not Found";
|
||||
static constexpr const char* T_HTTP_CODE_405 = "Method Not Allowed";
|
||||
static constexpr const char* T_HTTP_CODE_406 = "Not Acceptable";
|
||||
static constexpr const char* T_HTTP_CODE_407 = "Proxy Authentication Required";
|
||||
static constexpr const char* T_HTTP_CODE_408 = "Request Time-out";
|
||||
static constexpr const char* T_HTTP_CODE_409 = "Conflict";
|
||||
static constexpr const char* T_HTTP_CODE_410 = "Gone";
|
||||
static constexpr const char* T_HTTP_CODE_411 = "Length Required";
|
||||
static constexpr const char* T_HTTP_CODE_412 = "Precondition Failed";
|
||||
static constexpr const char* T_HTTP_CODE_413 = "Request Entity Too Large";
|
||||
static constexpr const char* T_HTTP_CODE_414 = "Request-URI Too Large";
|
||||
static constexpr const char* T_HTTP_CODE_415 = "Unsupported Media Type";
|
||||
static constexpr const char* T_HTTP_CODE_416 = "Requested range not satisfiable";
|
||||
static constexpr const char* T_HTTP_CODE_417 = "Expectation Failed";
|
||||
static constexpr const char* T_HTTP_CODE_500 = "Internal Server Error";
|
||||
static constexpr const char* T_HTTP_CODE_501 = "Not Implemented";
|
||||
static constexpr const char* T_HTTP_CODE_502 = "Bad Gateway";
|
||||
static constexpr const char* T_HTTP_CODE_503 = "Service Unavailable";
|
||||
static constexpr const char* T_HTTP_CODE_504 = "Gateway Time-out";
|
||||
static constexpr const char* T_HTTP_CODE_505 = "HTTP Version not supported";
|
||||
static constexpr const char* T_HTTP_CODE_ANY = "Unknown code";
|
||||
|
||||
// other
|
||||
static constexpr const char* T__opaque = "\", opaque=\"";
|
||||
static constexpr const char* T_13 = "13";
|
||||
static constexpr const char* T_asyncesp = "asyncesp";
|
||||
static constexpr const char* T_auth_nonce = "\", qop=\"auth\", nonce=\"";
|
||||
static constexpr const char* T_cnonce = "cnonce";
|
||||
static constexpr const char* T_data_ = "data: ";
|
||||
static constexpr const char* T_event_ = "event: ";
|
||||
static constexpr const char* T_filename = "filename";
|
||||
static constexpr const char* T_gzip = "gzip";
|
||||
static constexpr const char* T_Host = "Host";
|
||||
static constexpr const char* T_id__ = "id: ";
|
||||
static constexpr const char* T_name = "name";
|
||||
static constexpr const char* T_nc = "nc";
|
||||
static constexpr const char* T_nonce = "nonce";
|
||||
static constexpr const char* T_opaque = "opaque";
|
||||
static constexpr const char* T_qop = "qop";
|
||||
static constexpr const char* T_realm = "realm";
|
||||
static constexpr const char* T_realm__ = "realm=\"";
|
||||
static constexpr const char* T_response = "response";
|
||||
static constexpr const char* T_retry_ = "retry: ";
|
||||
static constexpr const char* T_rn = "\r\n";
|
||||
static constexpr const char* T_rnrn = "\r\n\r\n";
|
||||
static constexpr const char* T_uri = "uri";
|
||||
static constexpr const char* T_username = "username";
|
||||
|
||||
|
||||
#else // ESP8622
|
||||
|
||||
static const char T_100_CONTINUE[] PROGMEM = "100-continue";
|
||||
static const char T_ACCEPT[] PROGMEM = "Accept";
|
||||
static const char T_Accept_Ranges[] PROGMEM = "Accept-Ranges";
|
||||
static const char T_app_xform_urlencoded[] PROGMEM = "application/x-www-form-urlencoded";
|
||||
static const char T_AUTH[] PROGMEM = "Authorization";
|
||||
static const char T_BASIC[] PROGMEM = "Basic";
|
||||
static const char T_BASIC_REALM[] PROGMEM = "Basic realm=\"";
|
||||
static const char T_BASIC_REALM_LOGIN_REQ[] PROGMEM = "Basic realm=\"Login Required\"";
|
||||
static const char T_BODY[] PROGMEM = "body";
|
||||
static const char T_Cache_Control[] PROGMEM = "Cache-Control";
|
||||
static const char T_chunked[] PROGMEM = "chunked";
|
||||
static const char T_close[] PROGMEM = "close";
|
||||
static const char T_Connection[] PROGMEM = "Connection";
|
||||
static const char T_Content_Disposition[] PROGMEM = "Content-Disposition";
|
||||
static const char T_Content_Encoding[] PROGMEM = "Content-Encoding";
|
||||
static const char T_Content_Length[] PROGMEM = "Content-Length";
|
||||
static const char T_Content_Type[] PROGMEM = "Content-Type";
|
||||
static const char T_Cookie[] PROGMEM = "Cookie";
|
||||
static const char T_DIGEST[] PROGMEM = "Digest";
|
||||
static const char T_DIGEST_[] PROGMEM = "Digest ";
|
||||
static const char T_ETag[] PROGMEM = "ETag";
|
||||
static const char T_EXPECT[] PROGMEM = "Expect";
|
||||
static const char T_HTTP_1_0[] PROGMEM = "HTTP/1.0";
|
||||
static const char T_HTTP_100_CONT[] PROGMEM = "HTTP/1.1 100 Continue\r\n\r\n";
|
||||
static const char T_IMS[] PROGMEM = "If-Modified-Since";
|
||||
static const char T_INM[] PROGMEM = "If-None-Match";
|
||||
static const char T_keep_alive[] PROGMEM = "keep-alive";
|
||||
static const char T_Last_Event_ID[] PROGMEM = "Last-Event-ID";
|
||||
static const char T_Last_Modified[] PROGMEM = "Last-Modified";
|
||||
static const char T_LOCATION[] PROGMEM = "Location";
|
||||
static const char T_MULTIPART_[] PROGMEM = "multipart/";
|
||||
static const char T_no_cache[] PROGMEM = "no-cache";
|
||||
static const char T_none[] PROGMEM = "none";
|
||||
static const char T_UPGRADE[] PROGMEM = "Upgrade";
|
||||
static const char T_WS[] PROGMEM = "websocket";
|
||||
static const char T_WWW_AUTH[] PROGMEM = "WWW-Authenticate";
|
||||
static const char Transfer_Encoding[] PROGMEM = "Transfer-Encoding";
|
||||
|
||||
// HTTP Methods
|
||||
static const char T_ANY[] PROGMEM = "ANY";
|
||||
static const char T_GET[] PROGMEM = "GET";
|
||||
static const char T_POST[] PROGMEM = "POST";
|
||||
static const char T_PUT[] PROGMEM = "PUT";
|
||||
static const char T_DELETE[] PROGMEM = "DELETE";
|
||||
static const char T_PATCH[] PROGMEM = "PATCH";
|
||||
static const char T_HEAD[] PROGMEM = "HEAD";
|
||||
static const char T_OPTIONS[] PROGMEM = "OPTIONS";
|
||||
static const char T_UNKNOWN[] PROGMEM = "UNKNOWN";
|
||||
|
||||
// Req content types
|
||||
static const char T_RCT_NOT_USED[] PROGMEM = "RCT_NOT_USED";
|
||||
static const char T_RCT_DEFAULT[] PROGMEM = "RCT_DEFAULT";
|
||||
static const char T_RCT_HTTP[] PROGMEM = "RCT_HTTP";
|
||||
static const char T_RCT_WS[] PROGMEM = "RCT_WS";
|
||||
static const char T_RCT_EVENT[] PROGMEM = "RCT_EVENT";
|
||||
static const char T_ERROR[] PROGMEM = "ERROR";
|
||||
|
||||
// extentions & MIME-Types
|
||||
static const char T__css[] PROGMEM = ".css";
|
||||
static const char T__eot[] PROGMEM = ".eot";
|
||||
static const char T__gif[] PROGMEM = ".gif";
|
||||
static const char T__gz[] PROGMEM = ".gz";
|
||||
static const char T__htm[] PROGMEM = ".htm";
|
||||
static const char T__html[] PROGMEM = ".html";
|
||||
static const char T__ico[] PROGMEM = ".ico";
|
||||
static const char T__jpg[] PROGMEM = ".jpg";
|
||||
static const char T__js[] PROGMEM = ".js";
|
||||
static const char T__json[] PROGMEM = ".json";
|
||||
static const char T__pdf[] PROGMEM = ".pdf";
|
||||
static const char T__png[] PROGMEM = ".png";
|
||||
static const char T__svg[] PROGMEM = ".svg";
|
||||
static const char T__ttf[] PROGMEM = ".ttf";
|
||||
static const char T__woff[] PROGMEM = ".woff";
|
||||
static const char T__woff2[] PROGMEM = ".woff2";
|
||||
static const char T__xml[] PROGMEM = ".xml";
|
||||
static const char T__zip[] PROGMEM = ".zip";
|
||||
static const char T_application_javascript[] PROGMEM = "application/javascript";
|
||||
static const char T_application_json[] PROGMEM = "application/json";
|
||||
static const char T_application_msgpack[] PROGMEM = "application/msgpack";
|
||||
static const char T_application_pdf[] PROGMEM = "application/pdf";
|
||||
static const char T_application_x_gzip[] PROGMEM = "application/x-gzip";
|
||||
static const char T_application_zip[] PROGMEM = "application/zip";
|
||||
static const char T_font_eot[] PROGMEM = "font/eot";
|
||||
static const char T_font_ttf[] PROGMEM = "font/ttf";
|
||||
static const char T_font_woff[] PROGMEM = "font/woff";
|
||||
static const char T_font_woff2[] PROGMEM = "font/woff2";
|
||||
static const char T_image_gif[] PROGMEM = "image/gif";
|
||||
static const char T_image_jpeg[] PROGMEM = "image/jpeg";
|
||||
static const char T_image_png[] PROGMEM = "image/png";
|
||||
static const char T_image_svg_xml[] PROGMEM = "image/svg+xml";
|
||||
static const char T_image_x_icon[] PROGMEM = "image/x-icon";
|
||||
static const char T_text_css[] PROGMEM = "text/css";
|
||||
static const char T_text_event_stream[] PROGMEM = "text/event-stream";
|
||||
static const char T_text_html[] PROGMEM = "text/html";
|
||||
static const char T_text_plain[] PROGMEM = "text/plain";
|
||||
static const char T_text_xml[] PROGMEM = "text/xml";
|
||||
|
||||
// Responce codes
|
||||
static const char T_HTTP_CODE_100[] PROGMEM = "Continue";
|
||||
static const char T_HTTP_CODE_101[] PROGMEM = "Switching Protocols";
|
||||
static const char T_HTTP_CODE_200[] PROGMEM = "OK";
|
||||
static const char T_HTTP_CODE_201[] PROGMEM = "Created";
|
||||
static const char T_HTTP_CODE_202[] PROGMEM = "Accepted";
|
||||
static const char T_HTTP_CODE_203[] PROGMEM = "Non-Authoritative Information";
|
||||
static const char T_HTTP_CODE_204[] PROGMEM = "No Content";
|
||||
static const char T_HTTP_CODE_205[] PROGMEM = "Reset Content";
|
||||
static const char T_HTTP_CODE_206[] PROGMEM = "Partial Content";
|
||||
static const char T_HTTP_CODE_300[] PROGMEM = "Multiple Choices";
|
||||
static const char T_HTTP_CODE_301[] PROGMEM = "Moved Permanently";
|
||||
static const char T_HTTP_CODE_302[] PROGMEM = "Found";
|
||||
static const char T_HTTP_CODE_303[] PROGMEM = "See Other";
|
||||
static const char T_HTTP_CODE_304[] PROGMEM = "Not Modified";
|
||||
static const char T_HTTP_CODE_305[] PROGMEM = "Use Proxy";
|
||||
static const char T_HTTP_CODE_307[] PROGMEM = "Temporary Redirect";
|
||||
static const char T_HTTP_CODE_400[] PROGMEM = "Bad Request";
|
||||
static const char T_HTTP_CODE_401[] PROGMEM = "Unauthorized";
|
||||
static const char T_HTTP_CODE_402[] PROGMEM = "Payment Required";
|
||||
static const char T_HTTP_CODE_403[] PROGMEM = "Forbidden";
|
||||
static const char T_HTTP_CODE_404[] PROGMEM = "Not Found";
|
||||
static const char T_HTTP_CODE_405[] PROGMEM = "Method Not Allowed";
|
||||
static const char T_HTTP_CODE_406[] PROGMEM = "Not Acceptable";
|
||||
static const char T_HTTP_CODE_407[] PROGMEM = "Proxy Authentication Required";
|
||||
static const char T_HTTP_CODE_408[] PROGMEM = "Request Time-out";
|
||||
static const char T_HTTP_CODE_409[] PROGMEM = "Conflict";
|
||||
static const char T_HTTP_CODE_410[] PROGMEM = "Gone";
|
||||
static const char T_HTTP_CODE_411[] PROGMEM = "Length Required";
|
||||
static const char T_HTTP_CODE_412[] PROGMEM = "Precondition Failed";
|
||||
static const char T_HTTP_CODE_413[] PROGMEM = "Request Entity Too Large";
|
||||
static const char T_HTTP_CODE_414[] PROGMEM = "Request-URI Too Large";
|
||||
static const char T_HTTP_CODE_415[] PROGMEM = "Unsupported Media Type";
|
||||
static const char T_HTTP_CODE_416[] PROGMEM = "Requested range not satisfiable";
|
||||
static const char T_HTTP_CODE_417[] PROGMEM = "Expectation Failed";
|
||||
static const char T_HTTP_CODE_500[] PROGMEM = "Internal Server Error";
|
||||
static const char T_HTTP_CODE_501[] PROGMEM = "Not Implemented";
|
||||
static const char T_HTTP_CODE_502[] PROGMEM = "Bad Gateway";
|
||||
static const char T_HTTP_CODE_503[] PROGMEM = "Service Unavailable";
|
||||
static const char T_HTTP_CODE_504[] PROGMEM = "Gateway Time-out";
|
||||
static const char T_HTTP_CODE_505[] PROGMEM = "HTTP Version not supported";
|
||||
static const char T_HTTP_CODE_ANY[] PROGMEM = "Unknown code";
|
||||
|
||||
// other
|
||||
static const char T__opaque[] PROGMEM = "\", opaque=\"";
|
||||
static const char T_13[] PROGMEM = "13";
|
||||
static const char T_asyncesp[] PROGMEM = "asyncesp";
|
||||
static const char T_auth_nonce[] PROGMEM = "\", qop=\"auth\", nonce=\"";
|
||||
static const char T_cnonce[] PROGMEM = "cnonce";
|
||||
static const char T_data_[] PROGMEM = "data: ";
|
||||
static const char T_event_[] PROGMEM = "event: ";
|
||||
static const char T_filename[] PROGMEM = "filename";
|
||||
static const char T_gzip[] PROGMEM = "gzip";
|
||||
static const char T_Host[] PROGMEM = "Host";
|
||||
static const char T_id__[] PROGMEM = "id: ";
|
||||
static const char T_name[] PROGMEM = "name";
|
||||
static const char T_nc[] PROGMEM = "nc";
|
||||
static const char T_nonce[] PROGMEM = "nonce";
|
||||
static const char T_opaque[] PROGMEM = "opaque";
|
||||
static const char T_qop[] PROGMEM = "qop";
|
||||
static const char T_realm[] PROGMEM = "realm";
|
||||
static const char T_realm__[] PROGMEM = "realm=\"";
|
||||
static const char T_response[] PROGMEM = "response";
|
||||
static const char T_retry_[] PROGMEM = "retry: ";
|
||||
static const char T_rn[] PROGMEM = "\r\n";
|
||||
static const char T_rnrn[] PROGMEM = "\r\n\r\n";
|
||||
static const char T_uri[] PROGMEM = "uri";
|
||||
static const char T_username[] PROGMEM = "username";
|
||||
|
||||
#endif // ESP8622
|
||||
|
||||
} // namespace asyncsrv {}
|
||||
@@ -73,8 +73,10 @@ void MqttLogger::sendBuffer()
|
||||
{
|
||||
if (this->bufferCnt > 0)
|
||||
{
|
||||
bool doSerial = this->mode==MqttLoggerMode::SerialOnly || this->mode==MqttLoggerMode::MqttAndSerial;
|
||||
if (this->mode!=MqttLoggerMode::SerialOnly && this->client != NULL && this->client->connected())
|
||||
bool doSerial = this->mode==MqttLoggerMode::SerialOnly || this->mode==MqttLoggerMode::MqttAndSerial || this->mode==MqttLoggerMode::MqttAndSerialAndWeb || this->mode==MqttLoggerMode::SerialAndWeb;
|
||||
bool doWebSerial = this->mode==MqttLoggerMode::MqttAndSerialAndWeb || this->mode==MqttLoggerMode::SerialAndWeb;
|
||||
|
||||
if (this->mode!=MqttLoggerMode::SerialOnly && this->mode!=MqttLoggerMode::SerialAndWeb && this->client != NULL && this->client->connected())
|
||||
{
|
||||
this->client->publish(topic, 0, true, this->buffer, this->bufferCnt);
|
||||
} else if (this->mode == MqttLoggerMode::MqttAndSerialFallback)
|
||||
@@ -86,6 +88,11 @@ void MqttLogger::sendBuffer()
|
||||
Serial.write(this->buffer, this->bufferCnt);
|
||||
Serial.println();
|
||||
}
|
||||
if (doWebSerial)
|
||||
{
|
||||
WebSerial.write(this->buffer, this->bufferCnt);
|
||||
WebSerial.println();
|
||||
}
|
||||
this->bufferCnt=0;
|
||||
}
|
||||
this->bufferEnd=this->buffer;
|
||||
@@ -113,4 +120,12 @@ size_t MqttLogger::write(uint8_t character)
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t MqttLogger::write(const uint8_t *buffer, size_t size) {
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
n += write(*buffer++);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
MqttLogger - offer print() interface like Serial but by publishing to a given mqtt topic.
|
||||
MqttLogger - offer print() interface like Serial but by publishing to a given mqtt topic.
|
||||
Uses Serial as a fallback when no mqtt connection is available.
|
||||
|
||||
Claus Denk
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <Print.h>
|
||||
#include <espMqttClient.h>
|
||||
#include "MycilaWebSerial.h"
|
||||
|
||||
#define MQTT_MAX_PACKET_SIZE 1024
|
||||
|
||||
@@ -20,6 +21,8 @@ enum MqttLoggerMode {
|
||||
SerialOnly = 1,
|
||||
MqttOnly = 2,
|
||||
MqttAndSerial = 3,
|
||||
MqttAndSerialAndWeb = 4,
|
||||
SerialAndWeb = 5,
|
||||
};
|
||||
|
||||
class MqttLogger : public Print
|
||||
@@ -42,10 +45,11 @@ public:
|
||||
void setTopic(const char* topic);
|
||||
void setMode(MqttLoggerMode mode);
|
||||
void setRetained(boolean retained);
|
||||
|
||||
|
||||
virtual size_t write(uint8_t);
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
using Print::write;
|
||||
|
||||
|
||||
uint16_t getBufferSize();
|
||||
boolean setBufferSize(uint16_t size);
|
||||
};
|
||||
|
||||
10
lib/MycilaWebSerial/LICENSE
Normal file
10
lib/MycilaWebSerial/LICENSE
Normal file
@@ -0,0 +1,10 @@
|
||||
The MIT License (MIT)
|
||||
---------------------
|
||||
|
||||
Copyright © 2023-2024, Mathieu Carbou
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,14 +1,14 @@
|
||||
# WebSerialLite
|
||||
# MycilaWebSerial
|
||||
|
||||
[](https://opensource.org/license/gpl-3-0/)
|
||||
[](https://github.com/mathieucarbou/WebSerialLite/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/WebSerialLite)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://github.com/mathieucarbou/MycilaWebSerial/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/MycilaWebSerial)
|
||||
|
||||
WebSerial is a Serial Monitor for ESP32 that can be accessed remotely via a web browser. Webpage is stored in program memory of the microcontroller.
|
||||
MycilaWebSerial is a Serial Monitor for ESP32 that can be accessed remotely via a web browser. Webpage is stored in program memory of the microcontroller.
|
||||
|
||||
This fork is based on [asjdf/WebSerialLite](https://github.com/asjdf/WebSerialLite).
|
||||
This library is based on the UI from [asjdf/WebSerialLite](https://github.com/asjdf/WebSerialLite) (and this part falls under GPL v3).
|
||||
|
||||
## Changes in this fork
|
||||
## Changes
|
||||
|
||||
- Simplified callbacks
|
||||
- Fixed UI
|
||||
8
lib/MycilaWebSerial/docs/_config.yml
Normal file
8
lib/MycilaWebSerial/docs/_config.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
# bundle exec jekyll serve --host=0.0.0.0
|
||||
|
||||
title: MycilaWebSerial
|
||||
description: "MycilaWebSerial is a Serial Monitor for ESP32 that can be accessed remotely via a web browser."
|
||||
remote_theme: pages-themes/cayman@v0.2.0
|
||||
plugins:
|
||||
- jekyll-remote-theme
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# WebSerialLite
|
||||
# MycilaWebSerial
|
||||
|
||||
[](https://opensource.org/license/gpl-3-0/)
|
||||
[](https://github.com/mathieucarbou/WebSerialLite/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/WebSerialLite)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://github.com/mathieucarbou/MycilaWebSerial/actions/workflows/ci.yml)
|
||||
[](https://registry.platformio.org/libraries/mathieucarbou/MycilaWebSerial)
|
||||
|
||||
WebSerial is a Serial Monitor for ESP32 that can be accessed remotely via a web browser. Webpage is stored in program memory of the microcontroller.
|
||||
MycilaWebSerial is a Serial Monitor for ESP32 that can be accessed remotely via a web browser. Webpage is stored in program memory of the microcontroller.
|
||||
|
||||
This fork is based on [asjdf/WebSerialLite](https://github.com/asjdf/WebSerialLite).
|
||||
This library is based on the UI from [asjdf/WebSerialLite](https://github.com/asjdf/WebSerialLite) (and this part falls under GPL v3).
|
||||
|
||||
## Changes in this fork
|
||||
## Changes
|
||||
|
||||
- Simplified callbacks
|
||||
- Fixed UI
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <DNSServer.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WString.h>
|
||||
#include <WebSerial.h>
|
||||
#include <MycilaWebSerial.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <DNSServer.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WString.h>
|
||||
#include <WebSerial.h>
|
||||
#include <MycilaWebSerial.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
40
lib/MycilaWebSerial/library.json
Normal file
40
lib/MycilaWebSerial/library.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "MycilaWebSerial",
|
||||
"version": "6.3.0",
|
||||
"keywords": "MycilaWebSerial, serial, monitor, ESP8266, ESP32, webpage, websocket, wireless",
|
||||
"description": "MycilaWebSerial is a webpage based Serial Monitor to log, monitor, or debug your code remotely.",
|
||||
"homepage": "https://github.com/mathieucarbou/MycilaWebSerial",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathieucarbou/MycilaWebSerial.git"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mathieu Carbou",
|
||||
"email": "mathieu.carbou@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["espressif8266", "espressif32"],
|
||||
"headers": ["MycilaWebSerial.h"],
|
||||
"dependencies": [
|
||||
{
|
||||
"owner": "mathieucarbou",
|
||||
"name": "ESPAsyncWebServer",
|
||||
"version": "^3.1.2",
|
||||
"platforms": ["espressif8266", "espressif32"]
|
||||
}
|
||||
],
|
||||
"export": {
|
||||
"include": [
|
||||
"examples",
|
||||
"src",
|
||||
"library.json",
|
||||
"library.properties",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
}
|
||||
10
lib/MycilaWebSerial/library.properties
Normal file
10
lib/MycilaWebSerial/library.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
name=MycilaWebSerial
|
||||
version=6.3.0
|
||||
author=Mathieu Carbou <mathieu.carbou@gmail.com>
|
||||
category=Communication
|
||||
maintainer=Mathieu Carbou <mathieu.carbou@gmail.com>
|
||||
sentence=A Web based Serial Monitor for ESP8266 & ESP32 to debug your code remotely.
|
||||
paragraph=MycilaWebSerial is a webpage based Serial Monitor to log, monitor, or debug your code remotely.
|
||||
url=https://github.com/mathieucarbou/MycilaWebSerial
|
||||
architectures=esp8266,esp32
|
||||
license=MIT
|
||||
@@ -8,7 +8,7 @@ build_flags =
|
||||
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||
-D WS_MAX_QUEUED_MESSAGES=128
|
||||
lib_deps =
|
||||
mathieucarbou/ESP Async WebServer @ 3.0.6
|
||||
mathieucarbou/ESPAsyncWebServer @ 3.1.2
|
||||
upload_protocol = esptool
|
||||
monitor_speed = 115200
|
||||
monitor_filters = esp32_exception_decoder, log2file
|
||||
@@ -25,18 +25,18 @@ platform = espressif32
|
||||
board = esp32dev
|
||||
|
||||
[env:arduino-2]
|
||||
platform = espressif32@6.7.0
|
||||
platform = espressif32@6.8.1
|
||||
board = esp32dev
|
||||
|
||||
[env:arduino-3]
|
||||
platform = espressif32
|
||||
platform_packages=
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2
|
||||
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.4
|
||||
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.4/esp32-arduino-libs-3.0.4.zip
|
||||
board = esp32dev
|
||||
|
||||
[env:esp8266]
|
||||
platform = espressif8266
|
||||
board = huzzah
|
||||
lib_deps =
|
||||
mathieucarbou/ESP Async WebServer @ 3.0.6
|
||||
mathieucarbou/ESPAsyncWebServer @ 3.1.2
|
||||
@@ -1,6 +1,6 @@
|
||||
# Frontend
|
||||
|
||||
The `index.html` is the only page of WebSerialLite and you can modify the page yourself and regenerate it.
|
||||
The `index.html` is the only page of MycilaWebSerial and you can modify the page yourself and regenerate it.
|
||||
|
||||
In addition, I am also very happy that you can participate in fixing the bugs of the library or enhancing the functions of the library.
|
||||
|
||||
@@ -49,17 +49,17 @@ function addLineBreaks(buffer) {
|
||||
const GZIPPED_INDEX = await gzipAsync(indexHtmlMinify, { numiterations: 15 });
|
||||
|
||||
const FILE =
|
||||
`#ifndef _webserial_webapge_h
|
||||
#define _webserial_webpage_h
|
||||
`
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
const uint32_t WEBSERIAL_HTML_SIZE = ${GZIPPED_INDEX.length};
|
||||
const uint8_t WEBSERIAL_HTML[] PROGMEM = {
|
||||
${ addLineBreaks(GZIPPED_INDEX) }
|
||||
};
|
||||
#endif
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.resolve(__dirname, SAVE_PATH+'/WebSerialWebPage.h'), FILE);
|
||||
console.log(`[finalize.js] Compressed Bundle into WebSerialWebPage.h header file | Total Size: ${(GZIPPED_INDEX.length / 1024).toFixed(2) }KB`)
|
||||
fs.writeFileSync(path.resolve(__dirname, SAVE_PATH+'/MycilaWebSerialPage.h'), FILE);
|
||||
console.log(`[finalize.js] Compressed Bundle into MycilaWebSerialPage.h header file | Total Size: ${(GZIPPED_INDEX.length / 1024).toFixed(2) }KB`)
|
||||
}catch(err){
|
||||
return console.error(err);
|
||||
}
|
||||
@@ -199,12 +199,12 @@
|
||||
</button>
|
||||
</div>
|
||||
<textarea class="w-full rounded" title="record" id="record" cols="30" rows="40" disabled></textarea>
|
||||
<div class="flex w-full grid gap-2" id="terminal">
|
||||
<!--<div class="flex w-full grid gap-2" id="terminal">
|
||||
<input type="text" name="cmd" id="command-text" class="grow rounded" /><button
|
||||
class="grid justify-items-end rounded shadow" id="command-button">
|
||||
SEND
|
||||
</button>
|
||||
</div>
|
||||
</div>!-->
|
||||
</div>
|
||||
<h1 />
|
||||
</div>
|
||||
@@ -213,8 +213,8 @@
|
||||
let gateway = `ws://${window.location.host + window.location.pathname}ws`;
|
||||
let websocket;
|
||||
let textArea = document.getElementById("record");
|
||||
let enableFlowLock = false;
|
||||
let enableTimestamp = false;
|
||||
let enableFlowLock = true;
|
||||
let enableTimestamp = true;
|
||||
let pingTimeout;
|
||||
let connectTimeout;
|
||||
let commandHistory = [];
|
||||
@@ -226,12 +226,12 @@
|
||||
}
|
||||
|
||||
function initWebPage() {
|
||||
document.getElementById("command-button").disabled = true;
|
||||
document.getElementById("command-text").disabled = true;
|
||||
//document.getElementById("command-button").disabled = true;
|
||||
//document.getElementById("command-text").disabled = true;
|
||||
initCommandHistory();
|
||||
initWebSocket();
|
||||
initButton();
|
||||
trapKeyPress();
|
||||
//initButton();
|
||||
//trapKeyPress();
|
||||
}
|
||||
|
||||
function initCommandHistory() {
|
||||
@@ -257,6 +257,7 @@
|
||||
websocket.onerror = onError;
|
||||
}
|
||||
|
||||
/*
|
||||
function initButton() {
|
||||
document.getElementById("command-button").addEventListener("click", sendCommand);
|
||||
}
|
||||
@@ -287,12 +288,13 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
function onOpen(event) {
|
||||
clearTimeout(connectTimeout);
|
||||
terminalWrite("[WebSerial] Connected...");
|
||||
document.getElementById("command-button").disabled = false;
|
||||
document.getElementById("command-text").disabled = false;
|
||||
//document.getElementById("command-button").disabled = false;
|
||||
//document.getElementById("command-text").disabled = false;
|
||||
}
|
||||
|
||||
function onError(e) {
|
||||
@@ -328,7 +330,8 @@
|
||||
textArea.value = "";
|
||||
textArea.scrollTop = textArea.scrollHeight;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function sendCommand() {
|
||||
let cmd = document.getElementById("command-text").value;
|
||||
console.log('send command: ', cmd);
|
||||
@@ -344,6 +347,7 @@
|
||||
document.getElementById("command-text").value = "";
|
||||
localStorage.history = JSON.stringify(commandHistory);
|
||||
}
|
||||
*/
|
||||
|
||||
setInterval(() => {
|
||||
if (!pingTimeout && websocket.readyState == WebSocket.OPEN) {
|
||||
@@ -351,7 +355,7 @@
|
||||
terminalWrite("[WebSerial] Ping timeout.");
|
||||
websocket.close();
|
||||
initWebSocket();
|
||||
}, 3000);
|
||||
}, 10000);
|
||||
websocket.send("ping");
|
||||
}
|
||||
}, 2000);
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "WebSerial.h"
|
||||
// SPDX-License-Identifier: MIT
|
||||
/*
|
||||
* Copyright (C) 2023-2024 Mathieu Carbou
|
||||
*/
|
||||
#include "MycilaWebSerial.h"
|
||||
|
||||
#include "WebSerialWebPage.h"
|
||||
#include "MycilaWebSerialPage.h"
|
||||
|
||||
void WebSerialClass::setAuthentication(const String& username, const String& password) {
|
||||
_username = username;
|
||||
@@ -59,16 +63,13 @@ void WebSerialClass::onMessage(WSLMessageHandler recv) {
|
||||
}
|
||||
|
||||
void WebSerialClass::onMessage(WSLStringMessageHandler callback) {
|
||||
_recvString = callback;
|
||||
_recv = [&](uint8_t* data, size_t len) {
|
||||
if (data && len) {
|
||||
#ifdef ESP8266
|
||||
String msg;
|
||||
msg.reserve(len);
|
||||
msg.concat((char*)data, len);
|
||||
callback(msg);
|
||||
#else
|
||||
callback(String((char*)data, len));
|
||||
#endif
|
||||
msg.concat((char*)data);
|
||||
_recvString(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
#ifndef WebSerial_h
|
||||
#define WebSerial_h
|
||||
// SPDX-License-Identifier: MIT
|
||||
/*
|
||||
* Copyright (C) 2023-2024 Mathieu Carbou
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include "ESP8266WiFi.h"
|
||||
@@ -11,11 +14,10 @@
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <functional>
|
||||
|
||||
#define WSL_VERSION "6.1.0"
|
||||
#define WSL_VERSION "6.3.0"
|
||||
#define WSL_VERSION_MAJOR 6
|
||||
#define WSL_VERSION_MINOR 1
|
||||
#define WSL_VERSION_MINOR 3
|
||||
#define WSL_VERSION_REVISION 0
|
||||
#define WSL_FORK_mathieucarbou
|
||||
|
||||
#ifndef WSL_MAX_WS_CLIENTS
|
||||
#define WSL_MAX_WS_CLIENTS DEFAULT_MAX_WS_CLIENTS
|
||||
@@ -56,6 +58,7 @@ class WebSerialClass : public Print {
|
||||
AsyncWebServer* _server;
|
||||
AsyncWebSocket* _ws;
|
||||
WSLMessageHandler _recv = nullptr;
|
||||
WSLStringMessageHandler _recvString = nullptr;
|
||||
bool _authenticate = false;
|
||||
String _username;
|
||||
String _password;
|
||||
@@ -65,4 +68,3 @@ class WebSerialClass : public Print {
|
||||
};
|
||||
|
||||
extern WebSerialClass WebSerial;
|
||||
#endif
|
||||
84
lib/MycilaWebSerial/src/MycilaWebSerialPage.h
Normal file
84
lib/MycilaWebSerial/src/MycilaWebSerialPage.h
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
const uint32_t WEBSERIAL_HTML_SIZE = 2320;
|
||||
const uint8_t WEBSERIAL_HTML[] PROGMEM = {
|
||||
31,139,8,0,0,0,0,0,2,3,116,85,247,146,179,54,16,127,21,197,95,202,57,99,225,242,117,48,78,239,
|
||||
189,231,95,33,45,160,156,144,136,36,184,115,24,222,61,139,4,87,231,238,108,107,181,179,229,183,85,199,119,132,
|
||||
225,254,220,2,169,125,163,78,199,249,23,152,56,29,27,240,140,240,154,89,7,62,239,124,73,223,44,60,163,61,
|
||||
104,159,175,190,249,34,7,81,193,10,149,125,75,225,223,78,246,249,223,244,143,79,232,103,166,105,153,151,133,130,
|
||||
211,209,75,143,199,95,80,144,207,140,118,70,193,113,27,89,15,140,93,73,225,235,92,64,47,57,208,112,217,72,
|
||||
45,189,100,138,58,206,20,228,251,21,209,172,129,188,151,112,213,26,235,79,71,231,207,104,71,200,126,16,210,181,
|
||||
138,157,211,66,25,126,57,178,161,97,182,146,58,77,94,88,104,50,15,215,158,10,224,198,34,38,163,83,109,52,
|
||||
140,31,110,210,148,149,30,44,158,5,148,198,194,64,175,160,184,148,158,22,230,154,58,249,159,212,85,42,117,13,
|
||||
86,250,236,49,107,108,23,39,59,178,35,123,244,51,22,70,156,7,211,131,117,220,26,165,104,1,53,235,165,177,
|
||||
193,97,86,131,172,106,159,238,119,187,247,178,16,94,36,23,35,89,203,132,64,251,72,149,152,18,90,178,70,170,
|
||||
115,74,89,219,42,160,238,236,60,52,155,120,208,78,110,62,85,82,95,254,192,248,111,129,243,37,106,108,86,191,
|
||||
65,101,128,252,241,205,106,243,171,41,140,55,155,213,215,160,122,240,146,51,242,35,116,176,218,56,166,29,117,8,
|
||||
191,28,147,144,21,142,169,7,59,4,154,41,89,233,52,114,198,164,178,236,60,112,163,16,254,179,87,175,94,239,
|
||||
223,188,29,19,87,51,97,174,134,82,42,20,73,133,53,45,141,172,139,29,121,209,94,147,231,248,181,85,129,183,
|
||||
233,127,75,146,221,235,245,154,220,151,59,160,204,225,145,220,171,245,122,76,174,104,217,41,53,220,38,103,66,33,
|
||||
197,77,113,167,11,178,88,75,15,3,254,166,201,203,41,235,73,169,224,250,70,102,186,76,106,8,115,34,233,68,
|
||||
165,251,49,249,167,115,94,150,103,42,49,91,142,130,22,195,61,78,10,26,77,91,211,105,1,98,40,140,21,96,
|
||||
169,101,66,118,110,113,227,128,79,221,51,220,105,133,89,14,57,89,193,248,101,21,244,233,156,180,242,77,249,182,
|
||||
100,99,210,48,169,239,193,203,2,48,33,109,52,152,162,124,215,232,108,193,51,15,68,16,165,206,51,235,179,80,
|
||||
153,25,104,172,207,157,110,18,125,29,157,144,164,101,90,131,26,90,227,100,176,108,65,49,47,123,200,34,80,196,
|
||||
84,150,51,77,195,236,164,206,40,41,22,86,76,124,8,55,187,159,130,169,189,31,133,24,205,69,37,206,20,191,
|
||||
152,74,70,104,152,133,117,108,98,204,19,164,13,160,141,102,110,116,234,77,155,30,230,148,70,188,164,232,188,199,
|
||||
196,242,206,58,180,218,26,25,34,92,230,225,13,54,203,126,135,63,72,60,182,106,58,175,164,134,24,78,24,180,
|
||||
37,216,93,118,7,229,99,236,187,221,171,215,229,139,7,24,82,172,19,43,20,136,225,177,194,75,246,106,255,234,
|
||||
237,141,194,51,11,28,29,13,13,198,52,23,227,121,114,8,185,91,144,199,76,90,8,120,123,176,211,32,170,236,
|
||||
169,5,49,62,155,42,143,124,26,177,220,150,145,21,88,166,206,67,134,185,91,140,78,14,35,253,80,111,73,231,
|
||||
211,17,48,133,88,136,195,64,134,206,77,173,0,10,184,159,147,119,163,53,37,14,246,47,196,77,56,135,185,16,
|
||||
217,189,101,155,221,228,115,135,163,104,204,180,78,22,141,169,19,8,130,124,170,121,198,132,155,246,28,98,89,116,
|
||||
112,152,16,125,131,170,113,180,13,243,84,65,233,135,64,166,19,185,176,163,94,228,7,122,60,110,227,139,112,220,
|
||||
198,23,108,90,200,167,163,144,61,225,138,57,151,175,194,152,204,131,76,238,44,192,21,190,121,123,34,69,30,94,
|
||||
38,18,172,228,75,152,152,151,7,239,87,189,63,29,25,169,45,148,249,150,156,142,178,169,38,93,101,42,67,80,
|
||||
214,90,99,115,132,143,133,254,30,89,23,107,226,44,207,183,10,105,68,198,238,1,138,107,145,132,157,70,166,253,
|
||||
70,98,123,173,162,20,90,189,95,220,211,49,158,139,254,188,177,72,180,179,66,247,92,73,126,153,99,76,216,152,
|
||||
76,125,166,128,233,139,53,62,149,125,69,152,149,140,214,82,8,208,185,183,29,16,193,60,163,18,61,228,2,20,
|
||||
120,32,165,84,42,231,157,181,152,149,207,166,50,145,210,240,46,140,68,94,50,245,63,173,85,181,237,214,14,3,
|
||||
127,69,55,239,210,146,101,89,86,46,115,15,190,148,222,187,92,56,204,252,245,149,189,147,148,185,93,49,206,140,
|
||||
33,123,76,231,207,96,90,234,191,165,48,182,223,195,127,31,223,252,54,51,133,8,62,183,30,103,48,93,228,161,
|
||||
248,253,215,120,4,236,192,211,223,102,219,30,2,41,182,86,179,93,161,115,99,204,133,50,138,83,69,211,41,172,
|
||||
229,34,109,224,192,81,133,5,9,166,87,206,107,201,184,97,170,84,131,204,2,73,41,247,60,203,85,150,198,160,
|
||||
164,144,201,192,251,111,199,152,244,64,52,196,69,114,75,129,103,165,4,50,39,7,75,96,153,230,145,239,104,209,
|
||||
22,132,0,131,73,159,142,145,15,18,45,141,230,24,205,215,220,189,245,238,25,28,199,16,232,87,216,7,29,211,
|
||||
193,197,76,166,112,119,136,194,12,188,150,141,175,176,202,78,102,189,170,114,55,11,231,251,199,136,44,156,136,116,
|
||||
97,39,124,166,159,179,103,71,221,132,255,15,142,175,183,142,163,254,211,155,245,217,39,13,62,8,213,15,180,55,
|
||||
11,168,233,14,154,63,22,237,246,86,238,95,175,82,198,36,190,140,107,217,189,13,10,184,215,97,41,128,136,87,
|
||||
34,163,131,15,185,236,218,24,58,53,208,128,166,176,99,202,109,106,17,53,92,112,209,232,177,206,237,253,30,109,
|
||||
231,104,57,77,51,51,205,65,10,37,44,6,197,34,221,17,245,54,96,14,96,112,48,184,62,191,181,104,217,255,
|
||||
224,221,161,26,131,49,175,73,0,37,219,78,9,191,51,235,221,182,186,66,229,116,85,242,59,171,82,249,221,117,
|
||||
84,242,19,117,226,4,83,202,144,184,79,133,191,215,138,121,184,123,248,44,30,17,135,39,177,100,222,4,62,189,
|
||||
102,90,95,52,216,118,207,218,193,15,60,26,74,146,208,252,35,166,100,48,233,87,229,224,206,133,57,42,170,254,
|
||||
122,196,21,138,17,31,212,50,39,93,52,136,236,238,144,193,133,91,168,74,224,140,185,10,38,51,178,81,138,120,
|
||||
190,170,65,196,101,14,3,133,37,186,172,173,248,149,41,175,77,223,220,168,130,101,39,219,42,170,125,181,228,66,
|
||||
229,177,184,55,70,37,237,94,163,247,223,154,6,214,33,96,116,24,48,248,149,212,66,125,105,11,25,36,18,40,
|
||||
193,100,48,42,7,201,130,129,36,76,214,66,61,20,62,84,14,41,164,152,168,30,72,32,152,231,77,122,70,181,
|
||||
147,232,84,177,231,93,244,161,133,20,133,151,149,88,5,147,235,32,16,254,43,57,158,193,132,161,61,25,57,225,
|
||||
185,187,187,49,47,91,153,201,145,78,224,180,237,127,127,11,132,54,228,124,164,73,214,89,190,101,151,98,135,185,
|
||||
189,227,186,160,170,65,117,241,20,134,113,146,97,183,54,114,189,159,197,201,72,198,23,215,156,194,12,148,225,140,
|
||||
109,228,70,63,243,221,179,33,162,253,104,58,186,26,173,198,183,94,232,204,56,6,141,39,246,118,9,54,195,171,
|
||||
151,65,180,129,229,19,156,2,28,72,113,178,227,136,66,13,255,108,252,28,42,11,7,234,72,254,61,48,91,189,
|
||||
222,117,188,41,104,196,188,64,152,250,139,157,24,85,198,230,93,162,91,187,187,55,206,15,204,95,238,66,186,135,
|
||||
33,201,2,193,187,11,218,138,33,216,71,37,184,215,251,71,207,10,74,66,244,132,241,238,137,219,231,39,42,170,
|
||||
143,1,238,238,42,93,60,29,27,91,213,71,242,199,175,148,130,22,15,37,94,232,246,116,24,57,218,83,193,244,
|
||||
204,16,74,228,19,38,130,48,101,252,76,65,159,111,148,244,243,138,104,230,21,73,252,92,70,230,11,175,238,26,
|
||||
141,243,203,91,53,4,116,235,190,30,36,65,162,139,70,228,131,223,2,202,82,221,174,244,20,183,197,216,12,164,
|
||||
203,113,249,1,137,104,89,140,2,123,187,147,18,184,243,252,195,155,215,184,11,181,1,10,108,235,212,20,165,20,
|
||||
81,130,30,218,81,119,1,49,58,244,95,130,170,27,80,208,20,35,140,39,204,22,152,88,27,89,114,101,181,3,
|
||||
46,105,32,190,82,74,153,188,61,141,51,212,151,122,108,129,146,31,46,2,168,199,170,252,149,61,8,170,153,13,
|
||||
10,2,225,178,0,176,192,99,211,192,41,57,101,124,29,214,25,191,216,44,134,41,68,98,83,106,56,200,150,182,
|
||||
154,58,104,59,173,116,53,1,45,43,253,6,31,9,221,135,131,140,7,238,153,112,16,199,70,13,29,239,149,127,
|
||||
75,185,97,142,173,244,35,247,92,238,69,240,64,225,130,93,184,120,149,80,248,69,182,45,123,87,222,116,152,180,
|
||||
5,86,66,170,235,37,86,8,135,147,9,79,44,249,197,158,103,41,70,225,196,189,126,33,208,106,98,163,73,138,
|
||||
179,66,38,149,30,18,41,65,184,238,120,135,94,22,99,108,43,205,67,208,111,121,233,176,177,58,7,180,115,204,
|
||||
176,41,72,242,131,228,212,97,224,161,178,192,132,173,240,72,82,65,230,131,173,209,37,101,57,249,149,145,28,114,
|
||||
242,83,147,121,60,230,196,190,42,247,32,151,129,220,57,210,102,51,186,144,11,23,210,143,213,68,118,72,79,125,
|
||||
83,79,34,78,110,22,211,212,149,36,132,95,214,232,220,128,125,166,209,30,106,54,37,215,202,222,108,182,220,96,
|
||||
212,44,142,62,88,92,251,138,92,84,129,120,243,246,209,107,92,67,208,185,122,13,191,69,189,171,22,240,42,108,
|
||||
180,5,13,232,130,18,23,0,97,142,189,230,234,187,233,63,170,40,30,237,131,182,47,199,198,130,134,154,146,135,
|
||||
111,94,33,232,172,163,85,170,128,130,112,26,179,138,121,76,14,105,180,133,224,217,233,53,13,114,167,231,255,151,
|
||||
253,15,145,100,45,14,173,21,0,0
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
Language: Cpp
|
||||
BasedOnStyle: LLVM
|
||||
|
||||
AccessModifierOffset: -2
|
||||
BinPackArguments: false
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
ColumnLimit: 0
|
||||
ContinuationIndentWidth: 2
|
||||
FixNamespaceComments: false
|
||||
IndentAccessModifiers: true
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 2
|
||||
NamespaceIndentation: All
|
||||
PointerAlignment: Left
|
||||
ReferenceAlignment: Left
|
||||
TabWidth: 2
|
||||
UseTab: Never
|
||||
AlignConsecutiveMacros: true
|
||||
13
lib/WebSerialLite/.github/FUNDING.yml
vendored
13
lib/WebSerialLite/.github/FUNDING.yml
vendored
@@ -1,13 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: mathieucarbou
|
||||
# patreon: # Replace with a single Patreon username
|
||||
# open_collective: # Replace with a single Open Collective username
|
||||
# ko_fi: # Replace with a single Ko-fi username
|
||||
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
# liberapay: # Replace with a single Liberapay username
|
||||
# issuehunt: # Replace with a single IssueHunt username
|
||||
# otechie: # Replace with a single Otechie username
|
||||
# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: https://paypal.me/mathieucarboufr
|
||||
10
lib/WebSerialLite/.github/dependabot.yml
vendored
10
lib/WebSerialLite/.github/dependabot.yml
vendored
@@ -1,10 +0,0 @@
|
||||
# Set update schedule for GitHub Actions
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
# Check for updates to GitHub Actions every week
|
||||
interval: "weekly"
|
||||
129
lib/WebSerialLite/.github/workflows/ci.yml
vendored
129
lib/WebSerialLite/.github/workflows/ci.yml
vendored
@@ -1,129 +0,0 @@
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
|
||||
|
||||
name: Continuous Integration
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
arduino:
|
||||
name: arduino ${{ matrix.name }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: package_esp32_index.json
|
||||
core: esp32:esp32
|
||||
board: esp32:esp32:esp32
|
||||
index_url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
|
||||
- name: package_esp32_dev_index.json
|
||||
core: esp32:esp32
|
||||
board: esp32:esp32:esp32
|
||||
index_url: https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
|
||||
- name: package_esp8266com_index.json
|
||||
core: esp8266:esp8266
|
||||
board: esp8266:esp8266:huzzah
|
||||
index_url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Arduino Lint
|
||||
uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
||||
- name: Install arduino-cli
|
||||
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
||||
|
||||
- name: Update core index
|
||||
run: arduino-cli core update-index --additional-urls "${{ matrix.index_url }}"
|
||||
|
||||
- name: Install core
|
||||
run: arduino-cli core install --additional-urls "${{ matrix.index_url }}" ${{ matrix.core }}
|
||||
|
||||
- name: Install Async TCP
|
||||
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/AsyncTCP#v3.1.4
|
||||
|
||||
- name: Install ESPAsyncTCP
|
||||
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0
|
||||
|
||||
- name: Install ESP Async WebServer
|
||||
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.0.6
|
||||
|
||||
- name: Build Demo
|
||||
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Demo/Demo.ino"
|
||||
|
||||
- name: Build Demo_AP
|
||||
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Demo_AP/Demo_AP.ino"
|
||||
|
||||
- name: Build Logging
|
||||
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Logging/Logging.ino"
|
||||
|
||||
- name: Build HighPerf
|
||||
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/HighPerf/HighPerf.ino"
|
||||
|
||||
platformio:
|
||||
name: pio ${{ matrix.name }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: esp32dev|arduino
|
||||
board: esp32dev
|
||||
platform: espressif32
|
||||
opts: "--project-option 'lib_compat_mode = strict'"
|
||||
- name: esp32dev|arduino-2
|
||||
board: esp32dev
|
||||
platform: espressif32@6.7.0
|
||||
opts: "--project-option 'lib_compat_mode = strict'"
|
||||
- name: esp32dev|arduino-3
|
||||
board: esp32dev
|
||||
platform: espressif32
|
||||
opts: "--project-option 'lib_compat_mode = strict' --project-option 'platform_packages=platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2, platform_packages=platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip'"
|
||||
|
||||
- name: esp32-s3-devkitc-1|arduino
|
||||
board: esp32-s3-devkitc-1
|
||||
platform: espressif32
|
||||
opts: "--project-option 'lib_compat_mode = strict'"
|
||||
- name: esp32-s3-devkitc-1|arduino-2
|
||||
board: esp32-s3-devkitc-1
|
||||
platform: espressif32@6.7.0
|
||||
opts: "--project-option 'lib_compat_mode = strict'"
|
||||
- name: esp32-s3-devkitc-1|arduino-3
|
||||
board: esp32-s3-devkitc-1
|
||||
platform: espressif32
|
||||
opts: "--project-option 'lib_compat_mode = strict' --project-option 'platform_packages=platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2, platform_packages=platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip'"
|
||||
|
||||
- name: huzzah|espressif8266
|
||||
board: huzzah
|
||||
platform: espressif8266
|
||||
opts: "--project-option 'lib_compat_mode = strict'"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.platformio
|
||||
~/.cache/pip
|
||||
key: ${{ matrix.name }}
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.x"
|
||||
- run: pip install platformio
|
||||
- run: platformio platform install ${{ matrix.platform }}
|
||||
|
||||
- run: platformio ci "examples/Demo/Demo.ino" -l '.' -b ${{ matrix.board }} ${{ matrix.opts }}
|
||||
- run: platformio ci "examples/Demo_AP/Demo_AP.ino" -l '.' -b ${{ matrix.board }} ${{ matrix.opts }}
|
||||
- run: platformio ci "examples/Logging/Logging.ino" -l '.' -b ${{ matrix.board }} ${{ matrix.opts }}
|
||||
- run: platformio ci "examples/HighPerf/HighPerf.ino" -l '.' -b ${{ matrix.board }} ${{ matrix.opts }}
|
||||
@@ -1,19 +0,0 @@
|
||||
name: PlatformIO Dependabot
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# Runs every day at 01:00
|
||||
- cron: "0 1 * * *"
|
||||
|
||||
jobs:
|
||||
dependabot:
|
||||
runs-on: ubuntu-latest
|
||||
name: PlatformIO Dependabot
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: run PlatformIO Dependabot
|
||||
uses: peterus/platformio_dependabot@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
24
lib/WebSerialLite/.github/workflows/stale.yaml
vendored
24
lib/WebSerialLite/.github/workflows/stale.yaml
vendored
@@ -1,24 +0,0 @@
|
||||
name: "Close stale issues and PRs"
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v9
|
||||
with:
|
||||
stale-issue-message: "This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days."
|
||||
stale-pr-message: "This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days."
|
||||
close-issue-message: "This issue was closed because it has been stalled for 7 days with no activity."
|
||||
close-pr-message: "This PR was closed because it has been stalled for 7 days with no activity."
|
||||
days-before-issue-stale: 30
|
||||
days-before-pr-stale: 30
|
||||
days-before-issue-close: 7
|
||||
days-before-pr-close: 7
|
||||
|
||||
permissions:
|
||||
# contents: write # only for delete-branch option
|
||||
issues: write
|
||||
pull-requests: write
|
||||
7
lib/WebSerialLite/.gitignore
vendored
7
lib/WebSerialLite/.gitignore
vendored
@@ -1,7 +0,0 @@
|
||||
.DS_Store
|
||||
.lh
|
||||
/.pio
|
||||
/.vscode/*
|
||||
!/.vscode/settings.json
|
||||
/logs
|
||||
/frontend/node_modules
|
||||
@@ -1,8 +0,0 @@
|
||||
# bundle exec jekyll serve --host=0.0.0.0
|
||||
|
||||
title: WebSerialLite
|
||||
description: "WebSerial is a Serial Monitor for ESP32 that can be accessed remotely via a web browser."
|
||||
remote_theme: pages-themes/cayman@v0.2.0
|
||||
plugins:
|
||||
- jekyll-remote-theme
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
--------------
|
||||
WebSerial Demo
|
||||
--------------
|
||||
|
||||
Skill Level: Beginner
|
||||
|
||||
This example provides with a bare minimal app with WebSerial functionality.
|
||||
|
||||
Github: https://github.com/ayushsharma82/WebSerial
|
||||
Wiki: https://docs.webserial.pro
|
||||
|
||||
Works with following hardware:
|
||||
- ESP8266
|
||||
- ESP32
|
||||
|
||||
WebSerial terminal will be accessible at your microcontroller's <IPAddress>/webserial URL.
|
||||
|
||||
Checkout WebSerial Pro: https://webserial.pro
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#elif defined(ESP32)
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#endif
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WebSerial.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
const char* ssid = ""; // Your WiFi SSID
|
||||
const char* password = ""; // Your WiFi Password
|
||||
|
||||
unsigned long last_print_time = millis();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.printf("WiFi Failed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Once connected, print IP
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/plain", "Hi! This is WebSerial demo. You can access webserial interface at http://" + WiFi.localIP().toString() + "/webserial");
|
||||
});
|
||||
|
||||
// WebSerial is accessible at "<IP Address>/webserial" in browser
|
||||
WebSerial.begin(&server);
|
||||
|
||||
/* Attach Message Callback */
|
||||
WebSerial.onMessage([&](uint8_t *data, size_t len) {
|
||||
Serial.printf("Received %u bytes from WebSerial: ", len);
|
||||
Serial.write(data, len);
|
||||
Serial.println();
|
||||
WebSerial.println("Received Data...");
|
||||
String d = "";
|
||||
for(size_t i=0; i < len; i++){
|
||||
d += char(data[i]);
|
||||
}
|
||||
WebSerial.println(d);
|
||||
});
|
||||
|
||||
// Start server
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Print every 2 seconds (non-blocking)
|
||||
if ((unsigned long)(millis() - last_print_time) > 2000) {
|
||||
WebSerial.print(F("IP address: "));
|
||||
WebSerial.println(WiFi.localIP());
|
||||
WebSerial.printf("Uptime: %lums\n", millis());
|
||||
WebSerial.printf("Free heap: %" PRIu32 "\n", ESP.getFreeHeap());
|
||||
last_print_time = millis();
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
--------------
|
||||
WebSerial Demo
|
||||
--------------
|
||||
|
||||
Skill Level: Beginner
|
||||
|
||||
This example provides with a bare minimal app with WebSerial functionality using softAP mode.
|
||||
|
||||
Github: https://github.com/ayushsharma82/WebSerial
|
||||
Wiki: https://docs.webserial.pro
|
||||
|
||||
Works with following hardware:
|
||||
- ESP8266
|
||||
- ESP32
|
||||
|
||||
WebSerial terminal will be accessible at your microcontroller's <IPAddress>/webserial URL.
|
||||
|
||||
Checkout WebSerial Pro: https://webserial.pro
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#elif defined(ESP32)
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#endif
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WebSerial.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
const char* ssid = "WSLDemo"; // WiFi AP SSID
|
||||
const char* password = ""; // WiFi AP Password
|
||||
|
||||
unsigned long last_print_time = millis();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
WiFi.softAP(ssid, password);
|
||||
// Once connected, print IP
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/plain", "Hi! This is WebSerial demo. You can access webserial interface at http://" + WiFi.softAPIP().toString() + "/webserial");
|
||||
});
|
||||
|
||||
// WebSerial is accessible at "<IP Address>/webserial" in browser
|
||||
WebSerial.begin(&server);
|
||||
|
||||
/* Attach Message Callback */
|
||||
WebSerial.onMessage([&](uint8_t *data, size_t len) {
|
||||
Serial.printf("Received %u bytes from WebSerial: ", len);
|
||||
Serial.write(data, len);
|
||||
Serial.println();
|
||||
WebSerial.println("Received Data...");
|
||||
String d = "";
|
||||
for(size_t i=0; i < len; i++){
|
||||
d += char(data[i]);
|
||||
}
|
||||
WebSerial.println(d);
|
||||
});
|
||||
|
||||
// Start server
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Print every 2 seconds (non-blocking)
|
||||
if ((unsigned long)(millis() - last_print_time) > 2000) {
|
||||
WebSerial.print(F("IP address: "));
|
||||
WebSerial.println(WiFi.softAPIP());
|
||||
WebSerial.printf("Uptime: %lums\n", millis());
|
||||
WebSerial.printf("Free heap: %" PRIu32 "\n", ESP.getFreeHeap());
|
||||
last_print_time = millis();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
{
|
||||
"name": "WebSerialLite",
|
||||
"version": "6.1.0",
|
||||
"keywords": "WebSerial, serial, monitor, ESP8266, ESP32, webpage, websocket, wireless",
|
||||
"description": "WebSerial is a webpage based Serial Monitor to log, monitor, or debug your code remotely.",
|
||||
"homepage": "https://github.com/mathieucarbou/WebSerialLite",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathieucarbou/WebSerial.git"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "HomeboyC",
|
||||
"email": "homeboyc@foxmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Mathieu Carbou",
|
||||
"email": "mathieu.carbou@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["espressif8266", "espressif32"],
|
||||
"headers": ["WebSerialLite.h", "WebSerial.h"],
|
||||
"dependencies": [
|
||||
{
|
||||
"owner": "mathieucarbou",
|
||||
"name": "ESP Async WebServer",
|
||||
"version": "^3.0.6",
|
||||
"platforms": ["espressif8266", "espressif32"]
|
||||
}
|
||||
],
|
||||
"export": {
|
||||
"include": [
|
||||
"examples",
|
||||
"src",
|
||||
"library.json",
|
||||
"library.properties",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
name=WebSerialLite
|
||||
version=6.1.0
|
||||
author=HomeboyC
|
||||
category=Communication
|
||||
maintainer=Mathieu Carbou <mathieu.carbou@gmail.com>
|
||||
sentence=A Web based Serial Monitor for ESP8266 & ESP32 to debug your code remotely.
|
||||
paragraph=WebSerial is a webpage based Serial Monitor to log, monitor, or debug your code remotely.
|
||||
url=https://github.com/mathieucarbou/WebSerialLite
|
||||
architectures=esp8266,esp32
|
||||
license=GPL-3.0-or-later
|
||||
@@ -1 +0,0 @@
|
||||
#include "./WebSerial.h"
|
||||
@@ -1,96 +0,0 @@
|
||||
#ifndef _webserial_webapge_h
|
||||
#define _webserial_webpage_h
|
||||
const uint32_t WEBSERIAL_HTML_SIZE = 2696;
|
||||
const uint8_t WEBSERIAL_HTML[] PROGMEM = {
|
||||
31,139,8,0,0,0,0,0,2,3,116,86,119,151,163,54,16,255,42,10,151,178,206,179,112,185,189,45,20,167,
|
||||
247,222,243,175,64,131,81,86,72,68,18,46,225,241,221,51,72,176,245,221,22,51,204,155,242,155,238,236,29,174,
|
||||
75,119,110,129,212,174,145,187,108,250,4,198,119,89,3,142,145,178,102,198,130,203,59,87,209,155,153,167,149,3,
|
||||
229,242,232,155,47,114,224,123,136,80,217,181,20,254,237,196,33,255,155,254,241,9,253,76,55,45,115,162,144,176,
|
||||
203,156,112,248,248,11,10,242,153,86,86,75,200,86,158,245,220,216,81,112,87,231,28,14,162,4,234,95,150,66,
|
||||
9,39,152,164,182,100,18,242,77,68,20,107,32,63,8,56,182,218,184,93,102,221,25,237,112,113,232,185,176,173,
|
||||
100,231,164,144,186,188,27,88,223,48,179,23,42,137,47,13,52,169,131,147,163,28,74,109,16,147,86,137,210,10,
|
||||
134,15,151,73,194,42,7,6,159,5,84,218,64,79,143,80,220,9,71,11,125,162,86,252,39,212,62,17,170,6,
|
||||
35,92,250,146,53,180,179,147,53,89,147,13,250,25,10,205,207,189,62,128,177,165,209,82,210,2,106,118,16,218,
|
||||
120,135,105,13,98,95,187,100,179,94,191,151,250,240,2,57,27,73,91,198,57,218,71,170,194,148,208,138,53,66,
|
||||
158,19,202,218,86,2,181,103,235,160,89,134,7,237,196,242,83,41,212,221,15,172,252,205,115,190,68,141,101,244,
|
||||
27,236,53,144,63,190,137,150,191,234,66,59,189,140,190,6,121,0,39,74,70,126,132,14,162,165,101,202,82,139,
|
||||
240,171,33,246,89,41,65,57,48,189,167,153,20,123,149,4,206,16,239,13,59,247,165,150,8,255,213,213,213,245,
|
||||
230,230,118,136,109,205,184,62,246,149,144,40,146,112,163,91,26,88,23,107,114,217,158,200,107,252,55,251,2,223,
|
||||
198,223,21,137,215,215,139,5,121,42,183,69,153,237,11,185,171,197,98,136,143,180,234,164,236,31,146,51,162,16,
|
||||
252,190,184,227,11,178,88,75,183,61,126,38,241,155,49,235,113,37,225,116,47,51,190,140,106,8,115,36,233,72,
|
||||
37,155,33,254,167,179,78,84,103,42,48,91,150,130,226,253,19,78,2,10,77,27,221,41,14,188,47,180,225,96,
|
||||
168,97,92,116,118,118,99,161,28,187,167,127,212,10,147,28,114,210,130,149,119,123,175,79,167,164,85,55,213,109,
|
||||
197,134,184,97,66,61,129,151,122,96,92,152,96,48,65,249,174,81,233,140,103,26,8,47,74,173,99,198,165,190,
|
||||
50,19,208,80,159,71,221,196,15,117,112,66,226,150,41,5,178,111,181,21,222,178,1,201,156,56,64,26,128,34,
|
||||
166,170,154,104,234,103,39,177,90,10,62,179,124,226,67,184,233,211,20,140,237,253,50,68,111,46,40,149,76,150,
|
||||
23,99,201,8,245,179,176,8,77,140,121,130,164,1,180,209,76,141,78,157,110,147,109,72,233,132,151,20,157,115,
|
||||
152,216,178,51,22,173,182,90,248,8,231,121,184,193,102,217,172,241,3,137,151,86,117,231,164,80,16,194,241,131,
|
||||
54,7,187,78,31,161,124,137,125,189,190,186,174,46,159,97,72,184,176,172,144,192,251,151,10,111,216,213,230,234,
|
||||
246,94,225,149,129,18,29,245,13,198,52,21,227,117,188,245,185,155,145,135,76,26,240,120,15,96,198,65,148,233,
|
||||
219,22,196,240,106,172,60,242,105,192,242,80,70,86,88,45,59,7,41,230,110,54,234,29,122,250,185,222,156,206,
|
||||
183,71,192,36,98,33,22,3,233,59,59,182,2,72,40,221,148,188,123,173,49,113,176,185,228,247,225,108,167,66,
|
||||
164,79,150,109,122,159,207,53,142,162,214,227,58,153,52,124,219,16,4,249,182,230,25,226,82,183,103,31,203,172,
|
||||
67,11,141,232,27,84,13,163,173,153,163,18,42,215,123,50,25,201,153,29,244,2,223,211,67,182,10,23,33,91,
|
||||
133,11,54,46,228,93,198,197,129,148,146,89,155,71,126,76,166,65,38,143,22,96,132,55,111,67,4,207,253,101,
|
||||
34,222,74,62,135,137,121,121,118,191,234,205,46,99,164,54,80,229,43,178,203,68,179,31,117,165,222,107,130,178,
|
||||
198,104,147,35,124,44,244,247,200,186,88,16,107,202,124,37,145,70,100,236,9,160,176,22,201,184,217,136,95,108,
|
||||
36,180,87,20,164,208,234,211,226,238,178,240,156,245,167,141,69,130,157,8,221,151,82,148,119,185,3,131,141,201,
|
||||
228,103,18,152,186,88,224,169,60,236,9,51,130,209,90,112,14,42,119,166,3,194,153,99,84,160,135,156,131,4,
|
||||
7,164,18,82,230,101,103,12,40,247,217,88,38,82,233,178,243,35,145,87,76,90,32,161,213,243,13,22,118,188,
|
||||
195,159,234,83,30,93,93,18,252,187,185,189,26,255,35,18,14,57,74,236,50,252,18,80,19,158,71,255,211,90,
|
||||
5,173,109,52,49,244,175,232,203,93,66,35,105,52,242,249,131,178,135,228,212,146,123,25,2,14,216,77,105,96,
|
||||
11,254,245,213,204,218,38,33,45,233,161,97,87,171,213,123,79,187,98,159,48,190,139,20,72,245,165,169,175,24,
|
||||
220,25,181,146,162,4,53,116,219,206,69,171,244,137,3,103,9,103,18,220,214,224,165,56,119,44,141,90,146,42,
|
||||
80,140,116,100,149,85,165,51,24,25,40,57,196,56,246,206,100,7,177,20,87,209,94,18,87,163,2,178,163,0,
|
||||
47,224,74,187,204,123,171,214,147,16,96,112,25,227,120,242,131,68,47,179,29,179,125,137,136,62,30,207,16,56,
|
||||
95,129,177,226,120,233,28,7,207,147,108,231,233,136,194,12,188,168,243,138,77,246,202,182,54,57,221,164,243,227,
|
||||
99,100,74,39,242,122,182,19,254,210,207,155,135,111,195,132,79,135,167,159,183,79,89,255,247,186,190,121,215,224,
|
||||
67,170,62,208,94,21,48,183,61,122,220,139,13,123,27,143,175,215,72,177,72,92,98,209,136,62,41,224,81,195,
|
||||
69,0,25,171,200,124,192,159,92,14,235,12,131,154,104,66,219,185,119,227,190,117,100,133,103,46,155,238,109,231,
|
||||
191,247,232,78,179,115,27,83,153,118,32,149,10,86,135,234,121,221,139,69,159,48,39,48,57,152,220,152,111,209,
|
||||
124,110,118,158,142,230,12,206,188,72,2,85,125,95,211,111,101,59,221,89,24,52,46,107,213,55,91,105,252,118,
|
||||
143,170,126,181,32,46,176,93,25,10,143,81,248,95,109,204,151,199,227,67,254,137,56,126,207,149,121,13,188,191,
|
||||
51,125,44,13,246,199,31,253,240,129,63,13,181,72,106,254,23,55,114,216,244,215,251,228,158,133,57,11,179,120,
|
||||
25,120,69,49,227,115,171,59,178,115,67,166,211,145,33,132,123,170,106,226,140,218,4,139,59,249,184,27,241,124,
|
||||
173,32,227,146,97,162,112,65,47,213,149,127,97,202,117,124,15,167,6,174,65,126,91,205,198,182,104,165,122,47,
|
||||
17,157,209,200,134,215,24,227,88,44,177,1,1,99,192,132,33,86,105,149,198,106,11,57,20,18,168,201,40,56,
|
||||
213,67,241,100,160,8,147,247,84,79,69,76,85,64,73,41,22,106,7,73,4,117,215,101,164,95,205,89,135,114,
|
||||
227,56,12,253,21,133,215,200,177,194,180,155,146,66,167,110,239,123,189,159,230,132,244,72,26,83,78,207,191,223,
|
||||
3,41,219,162,36,111,188,158,182,45,150,89,30,64,242,129,120,80,56,56,52,44,129,242,252,201,131,166,17,9,
|
||||
15,200,48,253,45,206,130,201,128,146,38,159,188,24,23,17,178,181,53,107,203,209,72,25,153,209,3,39,39,175,
|
||||
129,34,104,108,107,190,95,142,92,246,172,26,129,95,65,135,25,207,101,57,159,240,88,225,142,237,0,109,148,180,
|
||||
144,81,179,98,88,54,61,98,41,47,124,74,188,184,72,32,36,24,223,151,132,255,93,164,159,206,140,222,96,171,
|
||||
8,8,224,170,125,249,225,201,219,131,230,38,249,159,199,43,227,239,94,89,64,198,157,20,101,31,169,51,66,233,
|
||||
104,17,45,84,198,5,84,12,7,25,148,105,140,40,202,160,54,70,95,143,146,146,174,146,27,243,239,149,221,88,
|
||||
90,250,26,149,78,6,223,52,194,204,21,166,250,56,183,101,175,217,200,103,199,139,124,184,178,255,198,188,228,93,
|
||||
108,169,73,17,124,23,8,69,125,68,229,147,115,226,199,189,155,23,169,20,126,247,133,138,155,25,99,37,110,222,
|
||||
8,104,170,214,254,252,196,150,249,224,198,252,241,87,216,2,196,107,131,130,116,152,121,201,84,87,53,119,83,93,
|
||||
96,165,35,148,246,131,165,138,167,14,116,124,193,72,167,183,116,165,183,140,112,186,82,60,140,173,242,107,0,232,
|
||||
175,247,201,17,125,202,108,120,142,128,29,83,118,97,121,186,15,117,50,53,230,176,221,253,96,59,176,152,202,153,
|
||||
31,220,97,87,223,247,156,69,124,41,7,73,241,138,110,222,15,200,90,169,194,21,52,145,238,64,14,91,70,100,
|
||||
248,164,207,127,64,35,214,167,143,125,247,102,227,96,104,251,229,15,239,222,130,11,3,75,146,212,70,231,65,133,
|
||||
45,250,156,178,163,242,56,112,162,230,57,236,67,27,14,42,106,202,144,169,42,14,58,107,148,86,117,126,51,131,
|
||||
194,137,198,210,232,81,74,169,76,255,110,20,212,191,12,16,117,82,252,193,30,16,114,206,249,95,209,190,159,26,
|
||||
149,126,130,6,105,199,97,164,145,124,44,181,247,251,65,197,107,180,166,226,199,97,225,166,214,1,166,201,232,42,
|
||||
154,96,85,209,88,55,154,103,121,65,153,201,179,119,248,8,218,157,59,232,216,231,207,160,7,209,100,147,35,238,
|
||||
123,227,158,130,94,95,13,160,239,9,127,134,103,225,89,243,89,140,70,141,244,228,18,221,175,113,196,4,108,41,
|
||||
92,178,23,177,165,44,173,8,86,163,93,72,199,187,89,99,160,109,229,140,110,10,6,17,177,36,156,169,120,226,
|
||||
138,38,99,12,161,130,75,233,219,111,37,105,12,224,73,7,116,152,12,207,57,50,102,95,150,91,132,84,56,220,
|
||||
218,172,78,47,112,51,102,149,19,147,129,88,236,37,85,22,190,253,54,92,13,124,236,30,168,79,82,184,45,118,
|
||||
113,46,87,63,21,147,181,108,203,86,96,45,46,182,131,109,107,25,179,103,12,193,254,242,118,103,251,226,202,198,
|
||||
178,106,67,247,13,176,219,6,59,33,224,196,172,167,122,153,156,15,169,225,224,31,45,51,127,41,181,225,55,229,
|
||||
0,91,29,28,113,107,108,175,215,229,124,167,159,157,155,245,37,46,30,28,172,5,144,191,8,36,61,114,89,62,
|
||||
126,25,81,234,239,162,121,146,215,202,28,201,107,165,182,6,127,247,184,69,248,23,24,26,9,58,244,210,141,88,
|
||||
16,49,117,220,192,53,36,127,251,117,35,133,235,229,225,110,126,170,129,26,96,84,183,36,163,136,34,207,142,4,
|
||||
83,140,139,142,109,57,107,210,81,27,225,142,251,249,53,43,97,55,44,157,28,202,134,250,81,119,100,196,31,162,
|
||||
39,57,41,28,36,37,41,93,230,80,74,137,31,243,67,57,128,73,169,122,226,175,72,244,168,39,254,204,196,195,
|
||||
72,125,121,58,245,140,111,110,40,173,251,123,57,30,231,223,243,253,152,23,166,209,244,220,213,74,129,199,193,11,
|
||||
155,187,208,148,17,34,158,21,116,130,89,75,10,64,100,149,74,230,179,2,102,51,56,102,134,139,170,97,27,81,
|
||||
131,44,220,41,169,25,208,186,24,218,99,110,14,128,42,141,19,241,123,81,6,234,12,110,213,221,220,95,229,139,
|
||||
183,19,142,217,147,13,11,209,154,105,11,228,23,146,203,221,136,40,18,231,242,79,205,170,192,102,14,223,241,81,
|
||||
119,41,66,227,4,160,117,180,68,13,211,184,78,213,131,165,242,5,103,101,128,84,202,171,22,51,247,247,147,147,
|
||||
2,95,210,155,31,74,48,126,193,140,197,144,126,247,254,201,91,48,151,231,204,35,229,222,99,222,60,58,174,201,
|
||||
32,193,14,8,197,221,171,220,237,139,161,14,45,112,240,238,13,174,154,146,219,242,36,165,84,196,114,196,123,112,
|
||||
61,168,24,128,133,43,99,107,169,170,214,182,150,220,47,57,255,7,236,22,1,194,250,28,0,0
|
||||
};
|
||||
#endif
|
||||
@@ -32,13 +32,11 @@ build_flags =
|
||||
-DESP_PLATFORM
|
||||
-DESP32
|
||||
-DARDUINO_ARCH_ESP32
|
||||
-DUSE_ESP_IDF_LOG
|
||||
-DCONFIG_BTDM_BLE_SCAN_DUPL=y
|
||||
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=3000
|
||||
-DCONFIG_ASYNC_TCP_PRIORITY=10
|
||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||
-DWS_MAX_QUEUED_MESSAGES=128
|
||||
-Wno-ignored-qualifiers
|
||||
-Wno-missing-field-initializers
|
||||
-Wno-type-limits
|
||||
@@ -59,11 +57,16 @@ monitor_filters =
|
||||
|
||||
[env:esp32dev]
|
||||
board = esp32dev
|
||||
board_build.cmake_extra_args =
|
||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.release.defaults"
|
||||
extra_scripts =
|
||||
pre:pio_package_pre.py
|
||||
post:pio_package.py
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||
-DWS_MAX_QUEUED_MESSAGES=128
|
||||
-DNUKI_ALT_CONNECT
|
||||
-DBLESCANNER_USE_LATEST_NIMBLE
|
||||
-DNUKI_USE_LATEST_NIMBLE
|
||||
@@ -89,6 +92,8 @@ board = esp32-c6-devkitm-1
|
||||
[env:esp32dev_dbg]
|
||||
extends = env:esp32dev
|
||||
custom_build = debug
|
||||
board_build.cmake_extra_args =
|
||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.debug.defaults"
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
@@ -107,10 +112,15 @@ build_flags =
|
||||
-DDEBUG_NUKI_COMMUNICATION
|
||||
;-DDEBUG_NUKI_HEX_DATA
|
||||
-DDEBUG_NUKI_READABLE_DATA
|
||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=1024
|
||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
||||
-DWS_MAX_QUEUED_MESSAGES=512
|
||||
|
||||
[env:esp32-c3_dbg]
|
||||
extends = env:esp32-c3
|
||||
custom_build = debug
|
||||
board_build.cmake_extra_args =
|
||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.debug.defaults"
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
@@ -129,10 +139,15 @@ build_flags =
|
||||
-DDEBUG_NUKI_COMMUNICATION
|
||||
;-DDEBUG_NUKI_HEX_DATA
|
||||
-DDEBUG_NUKI_READABLE_DATA
|
||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=1024
|
||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
||||
-DWS_MAX_QUEUED_MESSAGES=512
|
||||
|
||||
[env:esp32-c6_dbg]
|
||||
extends = env:esp32-c6
|
||||
custom_build = debug
|
||||
board_build.cmake_extra_args =
|
||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.debug.defaults"
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
@@ -151,10 +166,15 @@ build_flags =
|
||||
-DDEBUG_NUKI_COMMUNICATION
|
||||
;-DDEBUG_NUKI_HEX_DATA
|
||||
-DDEBUG_NUKI_READABLE_DATA
|
||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=1024
|
||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
||||
-DWS_MAX_QUEUED_MESSAGES=512
|
||||
|
||||
[env:esp32-s3_dbg]
|
||||
extends = env:esp32-s3
|
||||
custom_build = debug
|
||||
board_build.cmake_extra_args =
|
||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.debug.defaults"
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
@@ -172,4 +192,7 @@ build_flags =
|
||||
-DDEBUG_NUKI_CONNECT
|
||||
-DDEBUG_NUKI_COMMUNICATION
|
||||
;-DDEBUG_NUKI_HEX_DATA
|
||||
-DDEBUG_NUKI_READABLE_DATA
|
||||
-DDEBUG_NUKI_READABLE_DATA
|
||||
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=1024
|
||||
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
||||
-DWS_MAX_QUEUED_MESSAGES=512
|
||||
3
sdkconfig.debug.defaults
Normal file
3
sdkconfig.debug.defaults
Normal file
@@ -0,0 +1,3 @@
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=4
|
||||
CONFIG_ESP_IPC_TASK_STACK_SIZE=8192
|
||||
@@ -18,57 +18,60 @@ CONFIG_BT_NIMBLE_MAX_CONNECTIONS=8
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=8
|
||||
CONFIG_BT_NIMBLE_NVS_PERSIST=y
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=8
|
||||
CONFIG_NIMBLE_PINNED_TO_CORE_0=y
|
||||
CONFIG_NIMBLE_PINNED_TO_CORE=0
|
||||
CONFIG_NIMBLE_TASK_STACK_SIZE=8192
|
||||
CONFIG_BT_NIMBLE_TASK_STACK_SIZE=8192
|
||||
CONFIG_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_NIMBLE_ROLE_PERIPHERAL=y
|
||||
CONFIG_NIMBLE_ROLE_BROADCASTER=y
|
||||
CONFIG_NIMBLE_ROLE_OBSERVER=y
|
||||
CONFIG_NIMBLE_SM_LEGACY=y
|
||||
CONFIG_NIMBLE_SM_SC=y
|
||||
CONFIG_NIMBLE_SVC_GAP_DEVICE_NAME="nimble"
|
||||
CONFIG_NIMBLE_GAP_DEVICE_NAME_MAX_LEN=31
|
||||
CONFIG_NIMBLE_ATT_PREFERRED_MTU=256
|
||||
CONFIG_NIMBLE_SVC_GAP_APPEARANCE=0
|
||||
CONFIG_BT_NIMBLE_MSYS1_BLOCK_COUNT=12
|
||||
CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
|
||||
CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
|
||||
CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=8192
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
CONFIG_BT_NIMBLE_SM_LEGACY=y
|
||||
CONFIG_BT_NIMBLE_SM_SC=y
|
||||
CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME="nimble"
|
||||
CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN=31
|
||||
CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=256
|
||||
CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE=0
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_COUNT=12
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_SIZE=256
|
||||
CONFIG_BT_NIMBLE_MSYS_2_BLOCK_COUNT=24
|
||||
CONFIG_BT_NIMBLE_MSYS_2_BLOCK_SIZE=320
|
||||
CONFIG_BT_NIMBLE_ACL_BUF_COUNT=24
|
||||
CONFIG_BT_NIMBLE_ACL_BUF_SIZE=255
|
||||
CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70
|
||||
CONFIG_BT_NIMBLE_HCI_EVT_HI_BUF_COUNT=30
|
||||
CONFIG_BT_NIMBLE_HCI_EVT_LO_BUF_COUNT=8
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_ACL_FROM_LL_COUNT=24
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_ACL_SIZE=255
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_SIZE=70
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=30
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_DISCARD_COUNT=8
|
||||
CONFIG_BTDM_CTRL_MODEM_SLEEP=n
|
||||
CONFIG_NIMBLE_HS_FLOW_CTRL=y
|
||||
CONFIG_NIMBLE_HS_FLOW_CTRL_ITVL=1000
|
||||
CONFIG_NIMBLE_HS_FLOW_CTRL_THRESH=2
|
||||
CONFIG_NIMBLE_HS_FLOW_CTRL_TX_ON_DISCONNECT=y
|
||||
CONFIG_NIMBLE_RPA_TIMEOUT=900
|
||||
CONFIG_NIMBLE_CRYPTO_STACK_MBEDTLS=y
|
||||
CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN=8
|
||||
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=8
|
||||
CONFIG_BT_NIMBLE_HS_FLOW_CTRL=y
|
||||
CONFIG_BT_NIMBLE_HS_FLOW_CTRL_ITVL=1000
|
||||
CONFIG_BT_NIMBLE_HS_FLOW_CTRL_THRESH=2
|
||||
CONFIG_BT_NIMBLE_HS_FLOW_CTRL_TX_ON_DISCONNECT=y
|
||||
CONFIG_BT_NIMBLE_RPA_TIMEOUT=900
|
||||
CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_BLE_MAX_CONN=8
|
||||
CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=8
|
||||
CONFIG_BT_ACL_CONNECTIONS=8
|
||||
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=0
|
||||
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0
|
||||
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
|
||||
CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
|
||||
CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y
|
||||
CONFIG_BLE_SCAN_DUPLICATE=y
|
||||
CONFIG_SCAN_DUPLICATE_BY_DEVICE_ADDR=y
|
||||
CONFIG_SCAN_DUPLICATE_TYPE=0
|
||||
CONFIG_DUPLICATE_SCAN_CACHE_SIZE=100
|
||||
CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED=y
|
||||
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED=y
|
||||
CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM=100
|
||||
CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
|
||||
CONFIG_BTDM_CTRLR_BR_EDR_MAX_ACL_CONN_EFF=0
|
||||
CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0
|
||||
CONFIG_BTDM_CTRL_PINNED_TO_CORE=0
|
||||
CONFIG_BTDM_CTRL_HCI_MODE_VHCI=y
|
||||
CONFIG_BTDM_CTRL_MODEM_SLEEP=y
|
||||
CONFIG_BTDM_BLE_SCAN_DUPL=y
|
||||
CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE=y
|
||||
CONFIG_BTDM_SCAN_DUPL_TYPE=0
|
||||
CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE=100
|
||||
CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED=y
|
||||
CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP=y
|
||||
CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM=100
|
||||
CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
|
||||
CONFIG_BT_NIMBLE_MSYS_BUF_FROM_HEAP=n
|
||||
CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=n
|
||||
CONFIG_IEEE802154_ENABLED=n
|
||||
CONFIG_ARDUINO_SELECTIVE_COMPILATION=y
|
||||
CONFIG_ARDUINO_SELECTIVE_HTTPClient=n
|
||||
CONFIG_ARDUINO_SELECTIVE_WebServer=n
|
||||
CONFIG_HEAP_TASK_TRACKING=n
|
||||
CONFIG_HEAP_TASK_TRACKING=n
|
||||
CONFIG_LOG_COLORS=n
|
||||
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=n
|
||||
CONFIG_LOG_MAXIMUM_LEVEL=4
|
||||
CONFIG_ARDUINO_LOOP_STACK_SIZE=2048
|
||||
3
sdkconfig.release.defaults
Normal file
3
sdkconfig.release.defaults
Normal file
@@ -0,0 +1,3 @@
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
CONFIG_ESP_IPC_TASK_STACK_SIZE=1024
|
||||
@@ -3,7 +3,6 @@
|
||||
#define MQTT_LOGGER_GLOBAL
|
||||
|
||||
#include "MqttLogger.h"
|
||||
#include "WebSerial.h"
|
||||
extern Print* Log;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3838,4 +3838,9 @@ void NukiNetwork::disableMqtt()
|
||||
_device->disableMqtt();
|
||||
_mqttEnabled = false;
|
||||
}
|
||||
|
||||
String NukiNetwork::localIP()
|
||||
{
|
||||
return _device->localIP();
|
||||
}
|
||||
#endif
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
#endif
|
||||
void disableAutoRestarts(); // disable on OTA start
|
||||
void disableMqtt();
|
||||
String localIP();
|
||||
|
||||
void subscribe(const char* prefix, const char* path);
|
||||
void initTopic(const char* prefix, const char* path, const char* value);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define preference_mqtt_user (char*)"mqttuser"
|
||||
#define preference_mqtt_password (char*)"mqttpass"
|
||||
#define preference_mqtt_log_enabled (char*)"mqttlog"
|
||||
#define preference_webserial_enabled (char*)"weblog"
|
||||
#define preference_webserver_enabled (char*)"websrvena"
|
||||
#define preference_lock_enabled (char*)"lockena"
|
||||
#define preference_lock_pin_status (char*)"lockpin"
|
||||
@@ -251,7 +252,7 @@ private:
|
||||
preference_official_hybrid, preference_query_interval_hybrid_lockstate, preference_official_hybrid_actions, preference_official_hybrid_retry, preference_has_mac_saved,
|
||||
preference_has_mac_byte_0, preference_has_mac_byte_1, preference_has_mac_byte_2, preference_latest_version, preference_task_size_network, preference_task_size_nuki,
|
||||
preference_authlog_max_entries, preference_keypad_max_entries, preference_timecontrol_max_entries, preference_update_from_mqtt, preference_show_secrets,
|
||||
preference_ble_tx_power, preference_recon_netw_on_mqtt_discon
|
||||
preference_ble_tx_power, preference_recon_netw_on_mqtt_discon, preference_webserial_enabled
|
||||
};
|
||||
std::vector<char*> _redact =
|
||||
{
|
||||
@@ -266,7 +267,7 @@ private:
|
||||
preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_register_opener_as_app, preference_ip_dhcp_enabled,
|
||||
preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled, preference_official_hybrid,
|
||||
preference_official_hybrid_actions, preference_official_hybrid_retry, preference_conf_info_enabled, preference_disable_non_json, preference_update_from_mqtt,
|
||||
preference_recon_netw_on_mqtt_discon
|
||||
preference_recon_netw_on_mqtt_discon, preference_webserial_enabled
|
||||
};
|
||||
std::vector<char*> _bytePrefs =
|
||||
{
|
||||
|
||||
@@ -299,6 +299,10 @@ void WebCfgServer::initialize()
|
||||
waitAndProcess(true, 1000);
|
||||
restartEsp(RestartReason::ConfigurationUpdated);
|
||||
});
|
||||
_server.on("/webserial", [&]() {
|
||||
_server.sendHeader("Location", (String)"http://" + _network->localIP() + ":81/webserial");
|
||||
_server.send(302, "text/plain", "");
|
||||
});
|
||||
#endif
|
||||
_server.on("/ota", [&]() {
|
||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||
@@ -1026,6 +1030,11 @@ bool WebCfgServer::processArgs(String& message)
|
||||
_preferences->putBool(preference_mqtt_log_enabled, (value == "1"));
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "WEBLOG")
|
||||
{
|
||||
_preferences->putBool(preference_webserial_enabled, (value == "1"));
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "CHECKUPDATE")
|
||||
{
|
||||
_preferences->putBool(preference_check_updates, (value == "1"));
|
||||
@@ -2061,6 +2070,11 @@ void WebCfgServer::buildHtml(String& response)
|
||||
{
|
||||
buildNavigationMenuEntry(response, "Advanced Configuration", "/advanced");
|
||||
}
|
||||
|
||||
if(_preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
buildNavigationMenuEntry(response, "Open Webserial", "/webserial");
|
||||
}
|
||||
|
||||
if(_allowRestartToPortal)
|
||||
{
|
||||
@@ -2177,6 +2191,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
||||
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect), "");
|
||||
printCheckBox(response, "RECNWTMQTTDIS", "Reconnect network on MQTT connection failure", _preferences->getBool(preference_recon_netw_on_mqtt_discon), "");
|
||||
printCheckBox(response, "MQTTLOG", "Enable MQTT logging", _preferences->getBool(preference_mqtt_log_enabled), "");
|
||||
printCheckBox(response, "WEBLOG", "Enable WebSerial logging", _preferences->getBool(preference_webserial_enabled), "");
|
||||
printCheckBox(response, "CHECKUPDATE", "Check for Firmware Updates every 24h", _preferences->getBool(preference_check_updates), "");
|
||||
printCheckBox(response, "UPDATEMQTT", "Allow updating using MQTT", _preferences->getBool(preference_update_from_mqtt), "");
|
||||
printCheckBox(response, "DISNONJSON", "Disable some extraneous non-JSON topics", _preferences->getBool(preference_disable_non_json), "");
|
||||
|
||||
77
src/main.cpp
77
src/main.cpp
@@ -22,6 +22,14 @@
|
||||
#include "Logger.h"
|
||||
#include "PreferencesKeys.h"
|
||||
#include "RestartReason.h"
|
||||
#include <AsyncTCP.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <WString.h>
|
||||
#include <MycilaWebSerial.h>
|
||||
|
||||
AsyncWebServer webserialserver(81);
|
||||
char log_print_buffer[1024];
|
||||
|
||||
NukiNetworkLock* networkLock = nullptr;
|
||||
NukiNetworkOpener* networkOpener = nullptr;
|
||||
@@ -64,17 +72,57 @@ RTC_NOINIT_ATTR bool rebuildGpioRequested;
|
||||
RTC_NOINIT_ATTR uint64_t bootloopValidDetect;
|
||||
RTC_NOINIT_ATTR int8_t bootloopCounter;
|
||||
|
||||
|
||||
bool restartReason_isValid;
|
||||
RestartReason currentRestartReason = RestartReason::NotApplicable;
|
||||
|
||||
TaskHandle_t otaTaskHandle = nullptr;
|
||||
TaskHandle_t networkTaskHandle = nullptr;
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
ssize_t write_fn(void* cookie, const char* buf, ssize_t size)
|
||||
{
|
||||
Log->write((uint8_t *)buf, (size_t)size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void ets_putc_handler(char c)
|
||||
{
|
||||
static char buf[1024];
|
||||
static size_t buf_pos = 0;
|
||||
buf[buf_pos] = c;
|
||||
buf_pos++;
|
||||
if (c == '\n' || buf_pos == sizeof(buf)) {
|
||||
write_fn(NULL, buf, buf_pos);
|
||||
buf_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _log_vprintf(const char *fmt, va_list args) {
|
||||
int ret = vsnprintf(log_print_buffer, sizeof(log_print_buffer), fmt, args);
|
||||
if (ret >= 0){
|
||||
Log->write((uint8_t *)log_print_buffer, (size_t)ret);
|
||||
}
|
||||
return 0; //return vprintf(fmt, args);
|
||||
}
|
||||
|
||||
void setReroute(){
|
||||
esp_log_set_vprintf(_log_vprintf);
|
||||
if(preferences->getBool(preference_mqtt_log_enabled)) esp_log_level_set("*", ESP_LOG_INFO);
|
||||
else
|
||||
{
|
||||
esp_log_level_set("*", ESP_LOG_DEBUG);
|
||||
esp_log_level_set("nvs", ESP_LOG_INFO);
|
||||
esp_log_level_set("wifi", ESP_LOG_INFO);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void networkTask(void *pvParameters)
|
||||
{
|
||||
int64_t networkLoopTs = 0;
|
||||
bool secrets = preferences->getBool(preference_show_secrets);
|
||||
bool reroute = true;
|
||||
|
||||
while(true)
|
||||
{
|
||||
@@ -92,15 +140,15 @@ void networkTask(void *pvParameters)
|
||||
bool connected = network->update();
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
if(connected && openerEnabled)
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
if(connected && reroute)
|
||||
{
|
||||
networkOpener->update();
|
||||
}
|
||||
|
||||
if(preferences->getBool(preference_webserver_enabled, true))
|
||||
{
|
||||
webCfgServer->update();
|
||||
reroute = false;
|
||||
setReroute();
|
||||
}
|
||||
#endif
|
||||
if(connected && openerEnabled) networkOpener->update();
|
||||
if(preferences->getBool(preference_webserver_enabled, true)) webCfgServer->update();
|
||||
#else
|
||||
webCfgServer->update();
|
||||
#endif
|
||||
@@ -337,10 +385,9 @@ void initEthServer(const NetworkDeviceType device)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
esp_log_level_set("*", ESP_LOG_ERROR);
|
||||
Serial.begin(115200);
|
||||
Log = &Serial;
|
||||
|
||||
@@ -397,13 +444,13 @@ void setup()
|
||||
bleScanner->initialize("NukiHub", true, 40, 40);
|
||||
bleScanner->setScanDuration(0);
|
||||
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
if(preferences->getInt(preference_presence_detection_timeout) >= 0)
|
||||
{
|
||||
presenceDetection = new PresenceDetection(preferences, bleScanner, CharBuffer::get(), buffer_size);
|
||||
presenceDetection->initialize();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lockEnabled = preferences->getBool(preference_lock_enabled);
|
||||
openerEnabled = preferences->getBool(preference_opener_enabled);
|
||||
@@ -443,6 +490,12 @@ void setup()
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, gpio, ethServer, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType);
|
||||
webCfgServer->initialize();
|
||||
}
|
||||
|
||||
WebSerial.setAuthentication(preferences->getString(preference_cred_user), preferences->getString(preference_cred_password));
|
||||
WebSerial.begin(&webserialserver);
|
||||
WebSerial.setBuffer(1024);
|
||||
webserialserver.onNotFound([](AsyncWebServerRequest* request) { request->redirect("/webserial"); });
|
||||
webserialserver.begin();
|
||||
#endif
|
||||
|
||||
if((partitionType==1 && preferences->getString(preference_ota_updater_url).length() > 0) || (partitionType==2 && preferences->getString(preference_ota_main_url).length() > 0)) setupTasks(true);
|
||||
|
||||
@@ -52,15 +52,21 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* preferen
|
||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||
}
|
||||
|
||||
if(preferences->getBool(preference_mqtt_log_enabled))
|
||||
if(preferences->getBool(preference_mqtt_log_enabled, false) || preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
MqttLoggerMode mode;
|
||||
|
||||
if(preferences->getBool(preference_mqtt_log_enabled, false) && preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||
else if (preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
|
||||
else mode = MqttLoggerMode::MqttAndSerial;
|
||||
|
||||
_path = new char[200];
|
||||
memset(_path, 0, sizeof(_path));
|
||||
|
||||
String pathStr = preferences->getString(preference_mqtt_lock_path);
|
||||
pathStr.concat(mqtt_topic_log);
|
||||
strcpy(_path, pathStr.c_str());
|
||||
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
|
||||
Log = new MqttLogger(*getMqttClient(), _path, mode);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -65,14 +65,20 @@ void W5500Device::initialize()
|
||||
}
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled))
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled, false) || _preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
MqttLoggerMode mode;
|
||||
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||
else if (_preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
|
||||
else mode = MqttLoggerMode::MqttAndSerial;
|
||||
|
||||
String pathStr = _preferences->getString(preference_mqtt_lock_path);
|
||||
pathStr.concat(mqtt_topic_log);
|
||||
_path = new char[pathStr.length() + 1];
|
||||
memset(_path, 0, sizeof(_path));
|
||||
strcpy(_path, pathStr.c_str());
|
||||
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
|
||||
Log = new MqttLogger(*getMqttClient(), _path, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -46,15 +46,21 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
|
||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||
}
|
||||
|
||||
if(preferences->getBool(preference_mqtt_log_enabled))
|
||||
if(preferences->getBool(preference_mqtt_log_enabled, false) || preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
MqttLoggerMode mode;
|
||||
|
||||
if(preferences->getBool(preference_mqtt_log_enabled, false) && preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||
else if (preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
|
||||
else mode = MqttLoggerMode::MqttAndSerial;
|
||||
|
||||
_path = new char[200];
|
||||
memset(_path, 0, sizeof(_path));
|
||||
|
||||
String pathStr = preferences->getString(preference_mqtt_lock_path);
|
||||
pathStr.concat(mqtt_topic_log);
|
||||
strcpy(_path, pathStr.c_str());
|
||||
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
|
||||
Log = new MqttLogger(*getMqttClient(), _path, mode);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user