Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PsychicHttp Support #25

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions examples/AdvancedCaptivePortal/AdvancedCaptivePortal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/BlockingCaptivePortal/BlockingCaptivePortal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void setup() {
espConnect.clearConfiguration();
request->send(200);
ESP.restart();
return PSYCHIC_OK;
});

// network state listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/MycilaESPConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
});
}

Expand Down
12 changes: 10 additions & 2 deletions src/MycilaESPConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
#pragma once

#include <ArduinoJson.h>
#include <AsyncJson.h>
#include <DNSServer.h>
#include <ESPAsyncWebServer.h>
#ifdef ESPCONNECT_USE_PSYCHIC
#include <FS.h>
#include <NetworkInterface.h>
#include <PsychicHttp.h>
#else
#include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#define PSYCHIC_OK
#define PSYCHIC_REQ
#endif

#ifdef ESP8266
#include <ESP8266WiFi.h>
Expand Down
Loading