Skip to content

Commit

Permalink
PsychicHttp
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Aug 13, 2024
1 parent d664b12 commit edffbb4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
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

0 comments on commit edffbb4

Please sign in to comment.