Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
[starmod]
lib_deps =
https://github.com/bblanchon/ArduinoJson.git
; https://github.com/ewowi/ESPAsyncWebServer.git ;me-no-dev + 64 + queueLength
https://github.com/ewoudwijma/ESPAsyncWebServer.git ;aircoookie + getClients
; https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 ;optionally combine with aircoookie
; https://github.com/lost-hope/ESPAsyncWebServer.git#master ;artifx on <ip>/edit
https://github.com/hoeken/PsychicHttp.git @ 1.0.1

[appmod_leds]
build_flags =
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ void SysModPrint::printJDocInfo(const char * text, DynamicJsonDocument source) {
print("%s %u / %u (%u%%) (%u %u %u)\n", text, source.memoryUsage(), source.capacity(), percentage, source.size(), source.overflowed(), source.nesting());
}

void SysModPrint::printClient(const char * text, AsyncWebSocketClient * client) {
print("%s client: %d ...%d q:%d l:%d s:%d (#:%d)\n", text, client?client->id():-1, client?client->remoteIP()[3]:-1, client->queueIsFull(), client->queueLength(), client->status(), client->server()->count());
void SysModPrint::printClient(const char * text, PsychicWebSocketClient * client) {
// TODO: print("%s client: %d ...%d q:%d l:%d s:%d (#:%d)\n", text, client?client->id():-1, client?client->remoteIP()[3]:-1, client->queueIsFull(), client->queueLength(), client->status(), client->server()->count());
//status: { WS_DISCONNECTED, WS_CONNECTED, WS_DISCONNECTING }
}

4 changes: 2 additions & 2 deletions src/Sys/SysModPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#pragma once
#include "SysModule.h"

#include <ESPAsyncWebServer.h>
#include <PsychicHttp.h>

#define USER_PRINTF(x...) print->print(x)
#define USER_PRINT_FUNCTION(x...) //print->print(x)
Expand Down Expand Up @@ -39,7 +39,7 @@ class SysModPrint:public SysModule {

void printJDocInfo(const char * text, DynamicJsonDocument source);

void printClient(const char * text, AsyncWebSocketClient * client);
void printClient(const char * text, PsychicWebSocketClient * client);

private:
bool setupsDone = false;
Expand Down
24 changes: 12 additions & 12 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
//https://randomnerdtutorials.com/esp32-async-web-server-espasyncwebserver-library/


AsyncWebServer * SysModWeb::server = nullptr;
AsyncWebSocket * SysModWeb::ws = nullptr;
PsychicHttpServer * SysModWeb::server = nullptr;
PsychicWebSocketHandler * SysModWeb::ws = nullptr;

const char * (*SysModWeb::processWSFunc)(JsonVariant &) = nullptr;

Expand Down Expand Up @@ -415,7 +415,7 @@ void SysModWeb::sendDataWs(JsonVariant json, AsyncWebSocketClient * client) {

//add an url to the webserver to listen to
bool SysModWeb::addURL(const char * uri, const char * contentType, const char * path, const uint8_t * content, size_t len) {
server->on(uri, HTTP_GET, [uri, contentType, path, content, len](AsyncWebServerRequest *request) {
server->on(uri, HTTP_GET, [uri, contentType, path, content, len](PsychicRequest *request) {
if (path) {
USER_PRINT_Async("Webserver: addUrl %s %s file: %s", uri, contentType, path);
request->send(LittleFS, path, contentType);
Expand All @@ -439,8 +439,8 @@ bool SysModWeb::addURL(const char * uri, const char * contentType, const char *
}

//not used at the moment
bool SysModWeb::processURL(const char * uri, void (*func)(AsyncWebServerRequest *)) {
server->on(uri, HTTP_GET, [uri, func](AsyncWebServerRequest *request) {
bool SysModWeb::processURL(const char * uri, void (*func)(PsychicRequest *)) {
server->on(uri, HTTP_GET, [uri, func](PsychicRequest *request) {
func(request);
});
return true;
Expand All @@ -449,8 +449,8 @@ bool SysModWeb::processURL(const char * uri, void (*func)(AsyncWebServerRequest
bool SysModWeb::addUpload(const char * uri) {

// curl -F 'data=@fixture1.json' 192.168.8.213/upload
server->on(uri, HTTP_POST, [](AsyncWebServerRequest *request) {},
[](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
server->on(uri, HTTP_POST, [](PsychicRequest *request) {},
[](PsychicRequest *request, const String& filename, size_t index, uint8_t *data,
size_t len, bool final) {
USER_PRINT_Async("handleUpload r:%s f:%s i:%d l:%d f:%d\n", request->url().c_str(), filename.c_str(), index, len, final);
if (!index) {
Expand Down Expand Up @@ -490,8 +490,8 @@ bool SysModWeb::addUpload(const char * uri) {
bool SysModWeb::addUpdate(const char * uri) {

// curl -F 'data=@fixture1.json' 192.168.8.213/upload
server->on(uri, HTTP_POST, [](AsyncWebServerRequest *request) {},
[](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
server->on(uri, HTTP_POST, [](PsychicRequest *request) {},
[](PsychicRequest *request, const String& filename, size_t index, uint8_t *data,
size_t len, bool final) {
USER_PRINT_Async("handleUpdate r:%s f:%s i:%d l:%d f:%d\n", request->url().c_str(), filename.c_str(), index, len, final);
if(!index){
Expand Down Expand Up @@ -520,7 +520,7 @@ bool SysModWeb::addUpdate(const char * uri) {

bool SysModWeb::addFileServer(const char * uri) {

server->on(uri, HTTP_GET, [uri](AsyncWebServerRequest *request){
server->on(uri, HTTP_GET, [uri](PsychicRequest *request){
const char * ddd = request->url().c_str();
const char * path = ddd + strlen(uri); //remove the uri from the path (skip their positions)
USER_PRINT_Async("fileServer request %s %s %s\n", uri, request->url().c_str(), path);
Expand All @@ -535,7 +535,7 @@ bool SysModWeb::setupJsonHandlers(const char * uri, const char * (*processFunc)(
processWSFunc = processFunc; //for WebSocket requests

//URL handler, e.g. for curl calls
AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler(uri, [processFunc](AsyncWebServerRequest *request, JsonVariant &json) {
AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler(uri, [processFunc](PsychicRequest *request, JsonVariant &json) {
JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonVariant responseVariant = responseDoc->as<JsonVariant>();
Expand Down Expand Up @@ -626,7 +626,7 @@ JsonDocument * SysModWeb::getResponseDoc() {
return strncmp(pcTaskGetTaskName(NULL), "loopTask", 8) == 0?web->responseDocLoopTask:web->responseDocAsyncTCP;
}

void SysModWeb::serveJson(AsyncWebServerRequest *request) {
void SysModWeb::serveJson(PsychicRequest *request) {

AsyncJsonResponse * response;

Expand Down
16 changes: 8 additions & 8 deletions src/Sys/SysModWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#pragma once
#include "SysModule.h"

#include <ESPAsyncWebServer.h>
#include <PsychicHttp.h>

class SysModWeb:public SysModule {

public:
static AsyncWebSocket *ws;
static PsychicWebSocketHandler *ws;

SysModWeb();

Expand All @@ -28,17 +28,17 @@ class SysModWeb:public SysModule {

void connectedChanged();

static void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
static void wsEvent2(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
static void wsEvent(AsyncWebSocket * server, PsychicWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
static void wsEvent2(AsyncWebSocket * server, PsychicWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);

//send json to client or all clients
static void sendDataWs(JsonVariant json = JsonVariant(), AsyncWebSocketClient * client = nullptr);
static void sendDataWs(JsonVariant json = JsonVariant(), PsychicWebSocketClient * client = nullptr);

//add an url to the webserver to listen to
bool addURL(const char * uri, const char * contentType, const char * path = nullptr, const uint8_t * content = nullptr, size_t len = -1);

//not used at the moment
bool processURL(const char * uri, void (*func)(AsyncWebServerRequest *));
bool processURL(const char * uri, void (*func)(PsychicRequest *));

// curl -F 'data=@fixture1.json' 192.168.8.213/upload
bool addUpload(const char * uri);
Expand Down Expand Up @@ -71,7 +71,7 @@ class SysModWeb:public SysModule {
JsonDocument * getResponseDoc();

//Currently only WLED style state and info
static void serveJson(AsyncWebServerRequest *request);
static void serveJson(PsychicRequest *request);

static unsigned long wsSendBytesCounter;
static unsigned long wsSendJsonCounter;
Expand All @@ -81,7 +81,7 @@ class SysModWeb:public SysModule {

static bool clientsChanged;

static AsyncWebServer *server;
static PsychicHttpServer *server;
static const char * (*processWSFunc)(JsonVariant &);

static DynamicJsonDocument *responseDocLoopTask;
Expand Down