From edffbb4038886fbba6a59c28b7b3399ace1de97c Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Tue, 6 Aug 2024 23:05:14 +0200 Subject: [PATCH] PsychicHttp --- .../AdvancedCaptivePortal.ino | 1 + .../BlockingCaptivePortal.ino | 1 + .../NonBlockingCaptivePortal.ino | 2 ++ platformio.ini | 25 +++++++++++++++++-- src/MycilaESPConnect.cpp | 5 ++-- src/MycilaESPConnect.h | 12 +++++++-- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/examples/AdvancedCaptivePortal/AdvancedCaptivePortal.ino b/examples/AdvancedCaptivePortal/AdvancedCaptivePortal.ino index e98ba65..7974afc 100644 --- a/examples/AdvancedCaptivePortal/AdvancedCaptivePortal.ino +++ b/examples/AdvancedCaptivePortal/AdvancedCaptivePortal.ino @@ -26,6 +26,7 @@ void setup() { preferences.end(); request->send(200); ESP.restart(); + return PSYCHIC_OK; }); // network state listener is required here in async mode diff --git a/examples/BlockingCaptivePortal/BlockingCaptivePortal.ino b/examples/BlockingCaptivePortal/BlockingCaptivePortal.ino index 147c973..630faac 100644 --- a/examples/BlockingCaptivePortal/BlockingCaptivePortal.ino +++ b/examples/BlockingCaptivePortal/BlockingCaptivePortal.ino @@ -22,6 +22,7 @@ void setup() { espConnect.clearConfiguration(); request->send(200); ESP.restart(); + return PSYCHIC_OK; }); // network state listener diff --git a/examples/NonBlockingCaptivePortal/NonBlockingCaptivePortal.ino b/examples/NonBlockingCaptivePortal/NonBlockingCaptivePortal.ino index ab936d2..4214958 100644 --- a/examples/NonBlockingCaptivePortal/NonBlockingCaptivePortal.ino +++ b/examples/NonBlockingCaptivePortal/NonBlockingCaptivePortal.ino @@ -24,12 +24,14 @@ void setup() { espConnect.clearConfiguration(); request->send(200); ESP.restart(); + return PSYCHIC_OK; }); server.on("/restart", HTTP_GET, [&](AsyncWebServerRequest* request) { Serial.println("Restarting..."); request->send(200); ESP.restart(); + return PSYCHIC_OK; }); // network state listener is required here in async mode diff --git a/platformio.ini b/platformio.ini index b31276e..5e32577 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,10 +20,10 @@ monitor_filters = esp32_exception_decoder, log2file [platformio] lib_dir = . ; src_dir = examples/BlockingCaptivePortal -; src_dir = examples/NonBlockingCaptivePortal +src_dir = examples/NonBlockingCaptivePortal ; src_dir = examples/AdvancedCaptivePortal ; src_dir = examples/TestWiFi8266 -src_dir = examples/WiFiStaticIP +; src_dir = examples/WiFiStaticIP ; esp8266 @@ -159,3 +159,24 @@ board = esp32dev [env:pioarduino-c6] platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.04/platform-espressif32.zip board = esp32-c6-devkitc-1 + +; PsychicHttp + +[env:psychichttp] +platform = espressif32 +platform_packages= + 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 +lib_deps = + bblanchon/ArduinoJson @ 7.1.0 + ; hoeken/PsychicHttp @ 1.1.0 + ; symlink:///Users/mat/Data/Workspace/forks/PsychicHttp + https://github.com/mathieucarbou/hoeken-PsychicHttp#espasyncws +build_flags = + -Wall -Wextra + -D CONFIG_ARDUHAL_LOG_COLORS + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG + -D ESPCONNECT_DEBUG + -D ESPCONNECT_USE_PSYCHIC + -D PSYCHIC_TO_ESPASYNCWS diff --git a/src/MycilaESPConnect.cpp b/src/MycilaESPConnect.cpp index b78d76e..0e9f040 100644 --- a/src/MycilaESPConnect.cpp +++ b/src/MycilaESPConnect.cpp @@ -600,7 +600,7 @@ void Mycila::ESPConnect::_enableCaptivePortal() { // send empty json response, to let the user choose AP mode if timeout, or still ask client to wait if (timedOut) { - AsyncJsonResponse* response = new AsyncJsonResponse(true); + AsyncJsonResponse* response = new AsyncJsonResponse(PSYCHIC_REQ true); response->setLength(); return request->send(response); } else { @@ -609,7 +609,7 @@ void Mycila::ESPConnect::_enableCaptivePortal() { // scan results ? } else { - AsyncJsonResponse* response = new AsyncJsonResponse(true); + AsyncJsonResponse* response = new AsyncJsonResponse(PSYCHIC_REQ true); JsonArray json = response->getRoot(); // we have some results for (int i = 0; i < n; ++i) { @@ -651,6 +651,7 @@ void Mycila::ESPConnect::_enableCaptivePortal() { request->send(200, "application/json", "{\"message\":\"Configuration Saved.\"}"); _setState(Mycila::ESPConnect::State::PORTAL_COMPLETE); } + return PSYCHIC_OK; }); } diff --git a/src/MycilaESPConnect.h b/src/MycilaESPConnect.h index bcee38c..5eb522d 100644 --- a/src/MycilaESPConnect.h +++ b/src/MycilaESPConnect.h @@ -5,9 +5,17 @@ #pragma once #include -#include #include -#include +#ifdef ESPCONNECT_USE_PSYCHIC + #include + #include + #include +#else + #include + #include + #define PSYCHIC_OK + #define PSYCHIC_REQ +#endif #ifdef ESP8266 #include