PsychicHTTP
This commit is contained in:
@@ -90,8 +90,8 @@ void MqttLogger::sendBuffer()
|
||||
}
|
||||
if (doWebSerial)
|
||||
{
|
||||
WebSerial.write(this->buffer, this->bufferCnt);
|
||||
WebSerial.println();
|
||||
//WebSerial.write(this->buffer, this->bufferCnt);
|
||||
//WebSerial.println();
|
||||
}
|
||||
this->bufferCnt=0;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <Print.h>
|
||||
#include <espMqttClient.h>
|
||||
#include "MycilaWebSerial.h"
|
||||
//#include "MycilaWebSerial.h"
|
||||
|
||||
#define MQTT_MAX_PACKET_SIZE 1024
|
||||
|
||||
|
||||
@@ -325,11 +325,19 @@ const std::list<PsychicClient*>& PsychicHttpServer::getClientList() {
|
||||
}
|
||||
|
||||
bool ON_STA_FILTER(PsychicRequest *request) {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
return WiFi.localIP() == request->client()->localIP();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ON_AP_FILTER(PsychicRequest *request) {
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
return WiFi.softAPIP() == request->client()->localIP();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
String urlDecode(const char* encoded)
|
||||
|
||||
@@ -318,6 +318,11 @@ PsychicWebParameter * PsychicRequest::addParam(PsychicWebParameter *param) {
|
||||
return param;
|
||||
}
|
||||
|
||||
int PsychicRequest::params()
|
||||
{
|
||||
return _params.size();
|
||||
}
|
||||
|
||||
bool PsychicRequest::hasParam(const char *key)
|
||||
{
|
||||
return getParam(key) != NULL;
|
||||
@@ -332,6 +337,18 @@ PsychicWebParameter * PsychicRequest::getParam(const char *key)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PsychicWebParameter * PsychicRequest::getParam(int index)
|
||||
{
|
||||
if (_params.size() > index){
|
||||
std::list<PsychicWebParameter*>::iterator it = _params.begin();
|
||||
for(int i=0; i<index; i++){
|
||||
++it;
|
||||
}
|
||||
return *it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool PsychicRequest::hasSessionKey(const String& key)
|
||||
{
|
||||
return this->_session->find(key) != this->_session->end();
|
||||
|
||||
@@ -81,9 +81,11 @@ class PsychicRequest {
|
||||
void loadParams();
|
||||
PsychicWebParameter * addParam(PsychicWebParameter *param);
|
||||
PsychicWebParameter * addParam(const String &name, const String &value, bool decode = true, bool post = false);
|
||||
int params();
|
||||
bool hasParam(const char *key);
|
||||
PsychicWebParameter * getParam(const char *name);
|
||||
|
||||
PsychicWebParameter * getParam(int index);
|
||||
|
||||
const String getFilename();
|
||||
|
||||
bool authenticate(const char * username, const char * password);
|
||||
|
||||
@@ -627,30 +627,28 @@ boolean WiFiManager::configPortalHasTimeout(){
|
||||
}
|
||||
|
||||
void WiFiManager::setupHTTPServer(){
|
||||
|
||||
server.reset(new WM_WebServer(_httpPort));
|
||||
server->listen(_httpPort);
|
||||
|
||||
/* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */
|
||||
server->on(String(FPSTR(R_wifi)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleWifi, this,std::placeholders::_1,true));
|
||||
server->on(String(FPSTR(R_wifinoscan)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleWifi, this,std::placeholders::_1,false));
|
||||
server->on(String(FPSTR(R_erase)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleErase, this,std::placeholders::_1,false));
|
||||
server->on(String(FPSTR(R_wifi)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleWifi, this,std::placeholders::_1,true));
|
||||
server->on(String(FPSTR(R_wifinoscan)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleWifi, this,std::placeholders::_1,false));
|
||||
server->on(String(FPSTR(R_erase)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleErase, this,std::placeholders::_1,false));
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
server->on(String(FPSTR(R_root)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleRoot, this,_1));
|
||||
server->on(String(FPSTR(R_wifisave)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleWifiSave, this,_1));
|
||||
server->on(String(FPSTR(R_info)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleInfo, this,_1));
|
||||
server->on(String(FPSTR(R_param)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleParam, this,_1));
|
||||
server->on(String(FPSTR(R_paramsave)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleParamSave, this,_1));
|
||||
server->on(String(FPSTR(R_restart)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleReset, this,_1));
|
||||
server->on(String(FPSTR(R_exit)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleExit, this,_1));
|
||||
server->on(String(FPSTR(R_close)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleClose, this,_1));
|
||||
server->on(String(FPSTR(R_status)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleWiFiStatus, this,_1));
|
||||
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this, _1));
|
||||
server->on(String(FPSTR(R_root)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleRoot, this,_1));
|
||||
server->on(String(FPSTR(R_wifisave)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleWifiSave, this,_1));
|
||||
server->on(String(FPSTR(R_info)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleInfo, this,_1));
|
||||
server->on(String(FPSTR(R_param)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleParam, this,_1));
|
||||
server->on(String(FPSTR(R_paramsave)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleParamSave, this,_1));
|
||||
server->on(String(FPSTR(R_restart)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleReset, this,_1));
|
||||
server->on(String(FPSTR(R_exit)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleExit, this,_1));
|
||||
server->on(String(FPSTR(R_close)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleClose, this,_1));
|
||||
server->on(String(FPSTR(R_status)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleWiFiStatus, this,_1));
|
||||
server->onNotFound ((PsychicHttpRequestCallback)std::bind(&WiFiManager::handleNotFound, this, _1));
|
||||
|
||||
server->on(String(FPSTR(R_update)).c_str(), HTTP_ANY, std::bind(&WiFiManager::handleUpdate, this, _1));
|
||||
server->on(String(FPSTR(R_updatedone)).c_str(), HTTP_POST,std::bind(&WiFiManager::handleUpdateDone, this, _1), std::bind(&WiFiManager::handleUpdating, this, _1,_2,_3,_4,_5,_6));
|
||||
server->on(String(FPSTR(R_update)).c_str(), (PsychicHttpRequestCallback)std::bind(&WiFiManager::handleUpdate, this, _1));
|
||||
//server->on(String(FPSTR(R_updatedone)).c_str(), HTTP_POST, std::bind(&WiFiManager::handleUpdateDone, this, _1), std::bind(&WiFiManager::handleUpdating, this, _1,_2,_3,_4,_5,_6));
|
||||
}
|
||||
server->begin(); // Web server start
|
||||
}
|
||||
|
||||
void WiFiManager::teardownHTTPServer(){
|
||||
@@ -979,7 +977,7 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
// @todo what is the proper way to shutdown and free the server up
|
||||
// debug - many open issues aobut port not clearing for use with other servers
|
||||
#ifdef WM_ASYNCWEBSERVER
|
||||
server->end();
|
||||
server->stop();
|
||||
#else
|
||||
server->stop();
|
||||
#endif
|
||||
@@ -1423,10 +1421,13 @@ String WiFiManager::getHTTPHead(String title){
|
||||
return page;
|
||||
}
|
||||
|
||||
void WiFiManager::HTTPSend(AsyncWebServerRequest *request, String page){
|
||||
AsyncWebServerResponse *response = request->beginResponse(200,FPSTR(HTTP_HEAD_CT), page);
|
||||
response->addHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
request->send(response);
|
||||
esp_err_t WiFiManager::HTTPSend(PsychicRequest *request, String page){
|
||||
PsychicResponse response(request);
|
||||
response.addHeader(HTTP_HEAD_CL, ((String)page.length()).c_str());
|
||||
response.setCode(200);
|
||||
response.setContentType(HTTP_HEAD_CT);
|
||||
response.setContent(page.c_str());
|
||||
return response.send();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1446,12 +1447,12 @@ void WiFiManager::handleRequest() {
|
||||
/**
|
||||
* HTTPD CALLBACK root or redirect to captive portal
|
||||
*/
|
||||
void WiFiManager::handleRoot(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleRoot(PsychicRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Root"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if (captivePortal(request)) return; // If captive portal redirect instead of displaying the page
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
if (captivePortal(request)) return 0; // If captive portal redirect instead of displaying the page
|
||||
handleRequest();
|
||||
String page = getHTTPHead(_title); // @token options @todo replace options with title
|
||||
String str = FPSTR(HTTP_ROOT_MAIN); // @todo custom title
|
||||
@@ -1463,28 +1464,29 @@ void WiFiManager::handleRoot(AsyncWebServerRequest *request) {
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
if(_preloadwifiscan) WiFi_scanNetworks(_scancachetime,true); // preload wifiscan throttled, async
|
||||
// @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load
|
||||
// I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone
|
||||
// if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK Wifi config page handler
|
||||
*/
|
||||
void WiFiManager::handleWifi(AsyncWebServerRequest *request,bool scan = true) {
|
||||
esp_err_t WiFiManager::handleWifi(PsychicRequest *request,bool scan = true) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Wifi"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
||||
if (scan) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
// DEBUG_WM(WM_DEBUG_DEV,"refresh flag:",request->hasArg(F("refresh")));
|
||||
#endif
|
||||
WiFi_scanNetworks(request->hasArg(F("refresh")),true); //wifiscan, force if arg refresh
|
||||
WiFi_scanNetworks(request->hasParam("refresh")); //wifiscan, force if arg refresh
|
||||
page += getScanItemOut();
|
||||
}
|
||||
String pitem = "";
|
||||
@@ -1520,21 +1522,21 @@ void WiFiManager::handleWifi(AsyncWebServerRequest *request,bool scan = true) {
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Sent config page"));
|
||||
#endif
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK Wifi param page handler
|
||||
*/
|
||||
void WiFiManager::handleParam(AsyncWebServerRequest *request){
|
||||
esp_err_t WiFiManager::handleParam(PsychicRequest *request){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
|
||||
|
||||
@@ -1550,11 +1552,11 @@ void WiFiManager::handleParam(AsyncWebServerRequest *request){
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Sent param page"));
|
||||
#endif
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
|
||||
@@ -1914,34 +1916,35 @@ String WiFiManager::getParamOut(){
|
||||
return page;
|
||||
}
|
||||
|
||||
void WiFiManager::handleWiFiStatus(AsyncWebServerRequest *request){
|
||||
esp_err_t WiFiManager::handleWiFiStatus(PsychicRequest *request){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi status "));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
String page;
|
||||
// String page = "{\"result\":true,\"count\":1}";
|
||||
#ifdef WM_JSTEST
|
||||
page = FPSTR(HTTP_JS);
|
||||
#endif
|
||||
HTTPSend(request,page);
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK save form and redirect to WLAN config page again
|
||||
*/
|
||||
void WiFiManager::handleWifiSave(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleWifiSave(PsychicRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi save "));
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Method:"),request->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
|
||||
//SAVE/connect here
|
||||
_ssid = request->arg(F("s")).c_str();
|
||||
_pass = request->arg(F("p")).c_str();
|
||||
_ssid = request->getParam("s")->value();
|
||||
_pass = request->getParam("p")->value();
|
||||
|
||||
if(_ssid == "" && _pass != ""){
|
||||
_ssid = WiFi_SSID(true); // password change, placeholder ssid, @todo compare pass to old?, confirm ssid is clean
|
||||
@@ -1957,40 +1960,40 @@ void WiFiManager::handleWifiSave(AsyncWebServerRequest *request) {
|
||||
requestinfo += "\nMethod: ";
|
||||
requestinfo += (request->method() == HTTP_GET) ? "GET" : "POST";
|
||||
requestinfo += "\nArguments: ";
|
||||
requestinfo += request->args();
|
||||
requestinfo += request->params();
|
||||
requestinfo += "\n";
|
||||
for (uint8_t i = 0; i < request->args(); i++) {
|
||||
requestinfo += " " + request->argName(i) + ": " + request->arg(i) + "\n";
|
||||
for (uint8_t i = 0; i < request->params(); i++) {
|
||||
requestinfo += " " + request->getParam(i)->name() + ": " + request->getParam(i)->value() + "\n";
|
||||
}
|
||||
|
||||
DEBUG_WM(WM_DEBUG_MAX,requestinfo);
|
||||
#endif
|
||||
|
||||
// set static ips from server args
|
||||
if (request->arg(FPSTR(S_ip)) != "") {
|
||||
if (request->getParam(S_ip)->value() != "") {
|
||||
//_sta_static_ip.fromString(request->arg(FPSTR(S_ip));
|
||||
String ip = request->arg(FPSTR(S_ip));
|
||||
String ip = request->getParam(S_ip)->value();
|
||||
optionalIPFromString(&_sta_static_ip, ip.c_str());
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("static ip:"),ip);
|
||||
#endif
|
||||
}
|
||||
if (request->arg(FPSTR(S_gw)) != "") {
|
||||
String gw = request->arg(FPSTR(S_gw));
|
||||
if (request->getParam(S_gw)->value() != "") {
|
||||
String gw = request->getParam(S_gw)->value();
|
||||
optionalIPFromString(&_sta_static_gw, gw.c_str());
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("static gateway:"),gw);
|
||||
#endif
|
||||
}
|
||||
if (request->arg(FPSTR(S_sn)) != "") {
|
||||
String sn = request->arg(FPSTR(S_sn));
|
||||
if (request->getParam(S_sn)->value() != "") {
|
||||
String sn = request->getParam(S_sn)->value();
|
||||
optionalIPFromString(&_sta_static_sn, sn.c_str());
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("static netmask:"),sn);
|
||||
#endif
|
||||
}
|
||||
if (request->arg(FPSTR(S_dns)) != "") {
|
||||
String dns = request->arg(FPSTR(S_dns));
|
||||
if (request->getParam(S_dns)->value() != "") {
|
||||
String dns = request->getParam(S_dns)->value();
|
||||
optionalIPFromString(&_sta_static_dns, dns.c_str());
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("static DNS:"),dns);
|
||||
@@ -2018,16 +2021,17 @@ void WiFiManager::handleWifiSave(AsyncWebServerRequest *request) {
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
//server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); // @HTTPHEAD send cors
|
||||
HTTPSend(request,page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Sent wifi save page"));
|
||||
#endif
|
||||
|
||||
connect = true; //signal ready to connect/reset process in processConfigPortal
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
void WiFiManager::handleParamSave(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleParamSave(PsychicRequest *request) {
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param save "));
|
||||
@@ -2035,7 +2039,7 @@ void WiFiManager::handleParamSave(AsyncWebServerRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Method:"),request->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
|
||||
doParamSave(request);
|
||||
@@ -2045,14 +2049,14 @@ void WiFiManager::handleParamSave(AsyncWebServerRequest *request) {
|
||||
if(_showBack) page += FPSTR(HTTP_BACKBTN);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Sent param save page"));
|
||||
#endif
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
void WiFiManager::doParamSave(AsyncWebServerRequest *request){
|
||||
void WiFiManager::doParamSave(PsychicRequest *request){
|
||||
// @todo use new callback for before paramsaves, is this really needed?
|
||||
if ( _presaveparamscallback != NULL) {
|
||||
_presaveparamscallback(); // @CALLBACK
|
||||
@@ -2075,10 +2079,10 @@ void WiFiManager::doParamSave(AsyncWebServerRequest *request){
|
||||
//read parameter from server
|
||||
String name = (String)FPSTR(S_parampre)+(String)i;
|
||||
String value;
|
||||
if(request->hasArg(name.c_str())) {
|
||||
value = request->arg(name);
|
||||
if(request->hasParam(name.c_str())) {
|
||||
value = request->getParam(name.c_str())->value();
|
||||
} else {
|
||||
value = request->arg(_params[i]->getID());
|
||||
value = request->getParam(_params[i]->getID())->value();
|
||||
}
|
||||
|
||||
//store it in params array
|
||||
@@ -2101,11 +2105,11 @@ void WiFiManager::doParamSave(AsyncWebServerRequest *request){
|
||||
/**
|
||||
* HTTPD CALLBACK info page
|
||||
*/
|
||||
void WiFiManager::handleInfo(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleInfo(PsychicRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
//handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
||||
reportStatus(page);
|
||||
@@ -2203,11 +2207,11 @@ void WiFiManager::handleInfo(AsyncWebServerRequest *request) {
|
||||
page += FPSTR(HTTP_HELP);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_DEV,F("Sent info page"));
|
||||
#endif
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
String WiFiManager::getInfoData(String id){
|
||||
@@ -2447,41 +2451,45 @@ String WiFiManager::getInfoData(String id){
|
||||
/**
|
||||
* HTTPD CALLBACK exit, closes configportal if blocking, if non blocking undefined
|
||||
*/
|
||||
void WiFiManager::handleExit(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleExit(PsychicRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
||||
page += FPSTR(S_exiting); // @token exiting
|
||||
// ('Logout', 401, {'WWW-Authenticate': 'Basic realm="Login required"'})
|
||||
AsyncWebServerResponse *response = request->beginResponse(200,FPSTR(HTTP_HEAD_CT), page);
|
||||
response->addHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
request->send(response);
|
||||
delay(2000);
|
||||
abort = true;
|
||||
|
||||
PsychicResponse response(request);
|
||||
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
response.setCode(200);
|
||||
response.setContentType(HTTP_HEAD_CT);
|
||||
response.setContent(page.c_str());
|
||||
return response.send();
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK reset page
|
||||
*/
|
||||
void WiFiManager::handleReset(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleReset(PsychicRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
||||
page += FPSTR(S_resetting); //@token resetting
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(F("RESETTING ESP"));
|
||||
#endif
|
||||
_rebootNeeded = true;
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2491,11 +2499,11 @@ void WiFiManager::handleReset(AsyncWebServerRequest *request) {
|
||||
// void WiFiManager::handleErase() {
|
||||
// handleErase(false);
|
||||
// }
|
||||
void WiFiManager::handleErase(AsyncWebServerRequest *request,bool opt = false) {
|
||||
esp_err_t WiFiManager::handleErase(PsychicRequest *request,bool opt = false) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
||||
|
||||
@@ -2510,18 +2518,19 @@ void WiFiManager::handleErase(AsyncWebServerRequest *request,bool opt = false) {
|
||||
}
|
||||
|
||||
page += FPSTR(HTTP_END);
|
||||
HTTPSend(request,page);
|
||||
|
||||
if(ret){
|
||||
_rebootNeeded = true;
|
||||
}
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPD CALLBACK 404
|
||||
*/
|
||||
void WiFiManager::handleNotFound(AsyncWebServerRequest *request) {
|
||||
if (captivePortal(request)) return; // If captive portal redirect instead of displaying the page
|
||||
esp_err_t WiFiManager::handleNotFound(PsychicRequest *request) {
|
||||
if (captivePortal(request)) return 0; // If captive portal redirect instead of displaying the page
|
||||
handleRequest();
|
||||
String message = FPSTR(S_notfound); // @token notfound
|
||||
|
||||
@@ -2532,18 +2541,22 @@ void WiFiManager::handleNotFound(AsyncWebServerRequest *request) {
|
||||
message += FPSTR(S_method); // @token method
|
||||
message += ( request->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST);
|
||||
message += FPSTR(S_args); // @token args
|
||||
message += request->args();
|
||||
message += request->params();
|
||||
message += F("\n");
|
||||
|
||||
for ( uint8_t i = 0; i < request->args(); i++ ) {
|
||||
message += " " + request->argName ( i ) + ": " + request->arg ( i ) + "\n";
|
||||
for ( uint8_t i = 0; i < request->params(); i++ ) {
|
||||
message += " " + request->getParam(i)->name() + ": " + request->getParam(i)->value() + "\n";
|
||||
}
|
||||
}
|
||||
AsyncWebServerResponse *response = request->beginResponse(404,FPSTR(HTTP_HEAD_CT2), message);
|
||||
response->addHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
response->addHeader(F("Pragma"), F("no-cache"));
|
||||
response->addHeader(F("Expires"), F("-1"));
|
||||
request->send(response);
|
||||
|
||||
PsychicResponse response(request);
|
||||
response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
response.addHeader("Pragma", "no-cache");
|
||||
response.addHeader("Expires", "-1");
|
||||
response.setCode(404);
|
||||
response.setContentType(HTTP_HEAD_CT2);
|
||||
response.setContent(message.c_str());
|
||||
return response.send();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2551,7 +2564,7 @@ void WiFiManager::handleNotFound(AsyncWebServerRequest *request) {
|
||||
* Redirect to captive portal if we got a request for another domain.
|
||||
* Return true in that case so the page handler do not try to handle the request again.
|
||||
*/
|
||||
boolean WiFiManager::captivePortal(AsyncWebServerRequest *request) {
|
||||
boolean WiFiManager::captivePortal(PsychicRequest *request) {
|
||||
|
||||
if(!_enableCaptivePortal || !configPortalActive) return false; // skip redirections if cp not enabled or not in ap mode
|
||||
|
||||
@@ -2578,9 +2591,11 @@ boolean WiFiManager::captivePortal(AsyncWebServerRequest *request) {
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Request redirected to captive portal"));
|
||||
DEBUG_WM(WM_DEBUG_DEV,"serverLoc " + serverLoc);
|
||||
#endif
|
||||
AsyncWebServerResponse *response = request->beginResponse(302,FPSTR(HTTP_HEAD_CT2), "");
|
||||
response->addHeader(F("Location"), (String)F("http://") + serverLoc);
|
||||
request->send(response);
|
||||
PsychicResponse response(request);
|
||||
response.addHeader("Location", ((String)("http://") + serverLoc).c_str());
|
||||
response.setCode(302);
|
||||
response.setContentType(HTTP_HEAD_CT2);
|
||||
response.send();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -2592,9 +2607,9 @@ void WiFiManager::stopCaptivePortal(){
|
||||
}
|
||||
|
||||
// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined
|
||||
void WiFiManager::handleClose(AsyncWebServerRequest *request){
|
||||
esp_err_t WiFiManager::handleClose(PsychicRequest *request){
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling Captive Portal"));
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
stopCaptivePortal();
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close"));
|
||||
@@ -2602,7 +2617,7 @@ void WiFiManager::handleClose(AsyncWebServerRequest *request){
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose
|
||||
page += FPSTR(S_closing); // @token closing
|
||||
HTTPSend(request,page);
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
void WiFiManager::reportStatus(String &page){
|
||||
@@ -4011,12 +4026,12 @@ void WiFiManager::WiFi_autoReconnect(){
|
||||
}
|
||||
|
||||
// Called when /update is requested
|
||||
void WiFiManager::handleUpdate(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleUpdate(PsychicRequest *request) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Handle update"));
|
||||
#endif
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if (captivePortal(request)) return; // If captive portal redirect instead of displaying the page
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
if (captivePortal(request)) return 0; // If captive portal redirect instead of displaying the page
|
||||
String page = getHTTPHead(_title); // @token options
|
||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||
str.replace(FPSTR(T_t), _title);
|
||||
@@ -4026,12 +4041,12 @@ void WiFiManager::handleUpdate(AsyncWebServerRequest *request) {
|
||||
page += FPSTR(HTTP_UPDATE);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
return HTTPSend(request,page);
|
||||
|
||||
}
|
||||
|
||||
// upload via /u POST
|
||||
void WiFiManager::handleUpdating(AsyncWebServerRequest *request,String filename, size_t index, uint8_t *data, size_t len, bool final){
|
||||
void WiFiManager::handleUpdating(String filename, size_t index, uint8_t *data, size_t len, bool final){
|
||||
// @todo
|
||||
// cannot upload files in captive portal, file select is not allowed, show message with link or hide
|
||||
// cannot upload if softreset after upload, maybe check for hard reset at least for dev, ERROR[11]: Invalid bootstrapping state, reset ESP8266 before updating
|
||||
@@ -4123,10 +4138,10 @@ void WiFiManager::handleUpdating(AsyncWebServerRequest *request,String filename,
|
||||
}
|
||||
|
||||
// upload and ota done, show status
|
||||
void WiFiManager::handleUpdateDone(AsyncWebServerRequest *request) {
|
||||
esp_err_t WiFiManager::handleUpdateDone(PsychicRequest *request) {
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE, F("<- Handle update done"));
|
||||
// if (captivePortal(request)) return; // If captive portal redirect instead of displaying the page
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication();
|
||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||
str.replace(FPSTR(T_t),_title);
|
||||
@@ -4148,13 +4163,13 @@ void WiFiManager::handleUpdateDone(AsyncWebServerRequest *request) {
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
HTTPSend(request,page);
|
||||
|
||||
// delay(1000); // send page
|
||||
if (!Update.hasError()) {
|
||||
//ESP.restart();
|
||||
_rebootNeeded = true;
|
||||
}
|
||||
|
||||
return HTTPSend(request,page);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -97,8 +97,8 @@
|
||||
#define WM_WIFIOPEN WIFI_AUTH_OPEN
|
||||
|
||||
#ifdef WM_ASYNCWEBSERVER
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <PsychicHttpsServer.h>
|
||||
#else
|
||||
#ifndef WEBSERVER_H
|
||||
#ifdef WM_WEBSERVERSHIM
|
||||
@@ -521,7 +521,7 @@ class WiFiManager
|
||||
|
||||
#if defined(ESP32) && defined(WM_WEBSERVERSHIM)
|
||||
#ifdef WM_ASYNCWEBSERVER
|
||||
using WM_WebServer = AsyncWebServer;
|
||||
using WM_WebServer = PsychicHttpServer;
|
||||
#else
|
||||
using WM_WebServer = WebServer;
|
||||
#endif
|
||||
@@ -694,32 +694,32 @@ public:
|
||||
bool WiFi_scanNetworks(bool force,bool async);
|
||||
protected:
|
||||
// webserver handlers
|
||||
void handleRoot(AsyncWebServerRequest *request);
|
||||
void handleWifi(AsyncWebServerRequest *request,bool scan);
|
||||
void handleWifiSave(AsyncWebServerRequest *request);
|
||||
void handleInfo(AsyncWebServerRequest *request);
|
||||
void handleReset(AsyncWebServerRequest *request);
|
||||
void handleNotFound(AsyncWebServerRequest *request);
|
||||
void handleExit(AsyncWebServerRequest *request);
|
||||
void handleClose(AsyncWebServerRequest *request);
|
||||
// void handleErase(AsyncWebServerRequest *request);
|
||||
void handleErase(AsyncWebServerRequest *request, bool opt);
|
||||
void handleParam(AsyncWebServerRequest *request);
|
||||
void handleWiFiStatus(AsyncWebServerRequest *request);
|
||||
void handleParamSave(AsyncWebServerRequest *request);
|
||||
void doParamSave(AsyncWebServerRequest *request);
|
||||
esp_err_t handleRoot(PsychicRequest *request);
|
||||
esp_err_t handleWifi(PsychicRequest *request,bool scan);
|
||||
esp_err_t handleWifiSave(PsychicRequest *request);
|
||||
esp_err_t handleInfo(PsychicRequest *request);
|
||||
esp_err_t handleReset(PsychicRequest *request);
|
||||
esp_err_t handleNotFound(PsychicRequest *request);
|
||||
esp_err_t handleExit(PsychicRequest *request);
|
||||
esp_err_t handleClose(PsychicRequest *request);
|
||||
// esp_err_t handleErase(PsychicRequest *request);
|
||||
esp_err_t handleErase(PsychicRequest *request, bool opt);
|
||||
esp_err_t handleParam(PsychicRequest *request);
|
||||
esp_err_t handleWiFiStatus(PsychicRequest *request);
|
||||
esp_err_t handleParamSave(PsychicRequest *request);
|
||||
void doParamSave(PsychicRequest *request);
|
||||
|
||||
void handleRequest();
|
||||
void HTTPSend(AsyncWebServerRequest *request, String page);
|
||||
esp_err_t HTTPSend(PsychicRequest *request, String page);
|
||||
|
||||
boolean captivePortal(AsyncWebServerRequest *request);
|
||||
boolean captivePortal(PsychicRequest *request);
|
||||
boolean configPortalHasTimeout();
|
||||
uint8_t processConfigPortal();
|
||||
void stopCaptivePortal();
|
||||
// OTA Update handler
|
||||
void handleUpdate(AsyncWebServerRequest *request);
|
||||
void handleUpdating(AsyncWebServerRequest *request,String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||
void handleUpdateDone(AsyncWebServerRequest *request);
|
||||
esp_err_t handleUpdate(PsychicRequest *request);
|
||||
void handleUpdating(String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||
esp_err_t handleUpdateDone(PsychicRequest *request);
|
||||
|
||||
// wifi platform abstractions
|
||||
bool WiFi_Mode(WiFiMode_t m);
|
||||
|
||||
@@ -82,4 +82,13 @@ CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y
|
||||
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y
|
||||
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE=y
|
||||
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y
|
||||
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="resources/github_root_ca.pem"
|
||||
CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH="resources/github_root_ca.pem"
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||
CONFIG_HTTPD_MAX_URI_LEN=512
|
||||
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
|
||||
CONFIG_HTTPD_PURGE_BUF_LEN=32
|
||||
CONFIG_HTTPD_WS_SUPPORT=y
|
||||
CONFIG_ESP_HTTPS_SERVER_ENABLE=y
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define NUKI_HUB_VERSION "9.01"
|
||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
||||
#define NUKI_HUB_DATE "2024-08-18"
|
||||
#define NUKI_HUB_DATE "2024-08-27"
|
||||
|
||||
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
|
||||
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include "NukiConstants.h"
|
||||
#endif
|
||||
|
||||
#define JSON_BUFFER_SIZE 1024
|
||||
|
||||
class NukiNetwork
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
#include "QueryCommand.h"
|
||||
#include "LockActionResult.h"
|
||||
|
||||
#define LOCK_LOG_JSON_BUFFER_SIZE 2048
|
||||
|
||||
class NukiNetworkLock : public MqttReceiver
|
||||
{
|
||||
public:
|
||||
|
||||
2726
src/WebCfgServer.cpp
2726
src/WebCfgServer.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <Preferences.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <PsychicHttpsServer.h>
|
||||
#include "esp_ota_ops.h"
|
||||
#include "Config.h"
|
||||
|
||||
@@ -37,9 +36,9 @@ class WebCfgServer
|
||||
{
|
||||
public:
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, AsyncWebServer* asyncServer);
|
||||
WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer);
|
||||
#else
|
||||
WebCfgServer(NukiNetwork* network, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, AsyncWebServer* asyncServer);
|
||||
WebCfgServer(NukiNetwork* network, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer);
|
||||
#endif
|
||||
~WebCfgServer() = default;
|
||||
|
||||
@@ -47,34 +46,34 @@ public:
|
||||
|
||||
private:
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
void sendSettings(AsyncWebServerRequest *request);
|
||||
bool processArgs(AsyncWebServerRequest *request, String& message);
|
||||
bool processImport(AsyncWebServerRequest *request, String& message);
|
||||
void processGpioArgs(AsyncWebServerRequest *request);
|
||||
void buildHtml(AsyncWebServerRequest *request);
|
||||
void buildAccLvlHtml(AsyncWebServerRequest *request);
|
||||
void buildCredHtml(AsyncWebServerRequest *request);
|
||||
void buildImportExportHtml(AsyncWebServerRequest *request);
|
||||
void buildMqttConfigHtml(AsyncWebServerRequest *request);
|
||||
void buildStatusHtml(AsyncWebServerRequest *request);
|
||||
void buildAdvancedConfigHtml(AsyncWebServerRequest *request);
|
||||
void buildNukiConfigHtml(AsyncWebServerRequest *request);
|
||||
void buildGpioConfigHtml(AsyncWebServerRequest *request);
|
||||
esp_err_t sendSettings(PsychicRequest *request);
|
||||
bool processArgs(PsychicRequest *request, String& message);
|
||||
bool processImport(PsychicRequest *request, String& message);
|
||||
void processGpioArgs(PsychicRequest *request);
|
||||
esp_err_t buildHtml(PsychicRequest *request);
|
||||
esp_err_t buildAccLvlHtml(PsychicRequest *request);
|
||||
esp_err_t buildCredHtml(PsychicRequest *request);
|
||||
esp_err_t buildImportExportHtml(PsychicRequest *request);
|
||||
esp_err_t buildMqttConfigHtml(PsychicRequest *request);
|
||||
esp_err_t buildStatusHtml(PsychicRequest *request);
|
||||
esp_err_t buildAdvancedConfigHtml(PsychicRequest *request);
|
||||
esp_err_t buildNukiConfigHtml(PsychicRequest *request);
|
||||
esp_err_t buildGpioConfigHtml(PsychicRequest *request);
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
void buildConfigureWifiHtml(AsyncWebServerRequest *request);
|
||||
esp_err_t buildConfigureWifiHtml(PsychicRequest *request);
|
||||
#endif
|
||||
void buildInfoHtml(AsyncWebServerRequest *request);
|
||||
void buildCustomNetworkConfigHtml(AsyncWebServerRequest *request);
|
||||
void processUnpair(AsyncWebServerRequest *request, bool opener);
|
||||
void processUpdate(AsyncWebServerRequest *request);
|
||||
void processFactoryReset(AsyncWebServerRequest *request);
|
||||
void printInputField(const char* token, const char* description, const char* value, const size_t& maxLength, const char* args, const bool& isPassword = false, const bool& showLengthRestriction = false);
|
||||
void printInputField(const char* token, const char* description, const int value, size_t maxLength, const char* args);
|
||||
void printCheckBox(const char* token, const char* description, const bool value, const char* htmlClass);
|
||||
void printTextarea(const char *token, const char *description, const char *value, const size_t& maxLength, const bool& enabled = true, const bool& showLengthRestriction = false);
|
||||
void printDropDown(const char *token, const char *description, const String preselectedValue, std::vector<std::pair<String, String>> options, const String className);
|
||||
void buildNavigationButton(const char* caption, const char* targetPath, const char* labelText = "");
|
||||
void buildNavigationMenuEntry(const char *title, const char *targetPath, const char* warningMessage = "");
|
||||
esp_err_t buildInfoHtml(PsychicRequest *request);
|
||||
esp_err_t buildCustomNetworkConfigHtml(PsychicRequest *request);
|
||||
esp_err_t processUnpair(PsychicRequest *request, bool opener);
|
||||
esp_err_t processUpdate(PsychicRequest *request);
|
||||
esp_err_t processFactoryReset(PsychicRequest *request);
|
||||
void printInputField(PsychicStreamResponse *response, const char* token, const char* description, const char* value, const size_t& maxLength, const char* args, const bool& isPassword = false, const bool& showLengthRestriction = false);
|
||||
void printInputField(PsychicStreamResponse *response, const char* token, const char* description, const int value, size_t maxLength, const char* args);
|
||||
void printCheckBox(PsychicStreamResponse *response, const char* token, const char* description, const bool value, const char* htmlClass);
|
||||
void printTextarea(PsychicStreamResponse *response, const char *token, const char *description, const char *value, const size_t& maxLength, const bool& enabled = true, const bool& showLengthRestriction = false);
|
||||
void printDropDown(PsychicStreamResponse *response, const char *token, const char *description, const String preselectedValue, std::vector<std::pair<String, String>> options, const String className);
|
||||
void buildNavigationButton(PsychicStreamResponse *response, const char* caption, const char* targetPath, const char* labelText = "");
|
||||
void buildNavigationMenuEntry(PsychicStreamResponse *response, const char *title, const char *targetPath, const char* warningMessage = "");
|
||||
|
||||
const std::vector<std::pair<String, String>> getNetworkDetectionOptions() const;
|
||||
const std::vector<std::pair<String, String>> getGpioOptions() const;
|
||||
@@ -86,8 +85,8 @@ private:
|
||||
String getPreselectionForGpio(const uint8_t& pin);
|
||||
String pinStateToString(uint8_t value);
|
||||
|
||||
void printParameter(const char* description, const char* value, const char *link = "", const char *id = "");
|
||||
|
||||
void printParameter(PsychicStreamResponse *response, const char* description, const char* value, const char *link = "", const char *id = "");
|
||||
|
||||
NukiWrapper* _nuki = nullptr;
|
||||
NukiOpenerWrapper* _nukiOpener = nullptr;
|
||||
Gpio* _gpio = nullptr;
|
||||
@@ -96,21 +95,19 @@ private:
|
||||
bool _rebootRequired = false;
|
||||
#endif
|
||||
|
||||
String _response;
|
||||
String generateConfirmCode();
|
||||
String _confirmCode = "----";
|
||||
void buildConfirmHtml(AsyncWebServerRequest *request, const String &message, uint32_t redirectDelay = 5, bool redirect = false);
|
||||
void buildOtaHtml(AsyncWebServerRequest *request, bool debug = false);
|
||||
void buildOtaCompletedHtml(AsyncWebServerRequest *request);
|
||||
void sendCss(AsyncWebServerRequest *request);
|
||||
void sendFavicon(AsyncWebServerRequest *request);
|
||||
void buildHtmlHeader(String additionalHeader = "");
|
||||
esp_err_t buildConfirmHtml(PsychicRequest *request, const String &message, uint32_t redirectDelay = 5, bool redirect = false);
|
||||
esp_err_t buildOtaHtml(PsychicRequest *request, bool debug = false);
|
||||
esp_err_t buildOtaCompletedHtml(PsychicRequest *request);
|
||||
esp_err_t sendCss(PsychicRequest *request);
|
||||
esp_err_t sendFavicon(PsychicRequest *request);
|
||||
void buildHtmlHeader(PsychicStreamResponse *response, String additionalHeader = "");
|
||||
void waitAndProcess(const bool blocking, const uint32_t duration);
|
||||
void handleOtaUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||
esp_err_t handleOtaUpload(PsychicRequest *request, const String& filename, uint64_t index, uint8_t *data, size_t len, bool final);
|
||||
void printProgress(size_t prg, size_t sz);
|
||||
void sendResponse(AsyncWebServerRequest *request);
|
||||
|
||||
AsyncWebServer* _asyncServer = nullptr;
|
||||
|
||||
PsychicHttpServer* _psychicServer = nullptr;
|
||||
NukiNetwork* _network = nullptr;
|
||||
Preferences* _preferences = nullptr;
|
||||
|
||||
|
||||
34
src/main.cpp
34
src/main.cpp
@@ -19,11 +19,12 @@
|
||||
#include "Logger.h"
|
||||
#include "PreferencesKeys.h"
|
||||
#include "RestartReason.h"
|
||||
#include <AsyncTCP.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
/*
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
#include <WString.h>
|
||||
#include <MycilaWebSerial.h>
|
||||
#endif
|
||||
*/
|
||||
|
||||
char log_print_buffer[1024];
|
||||
|
||||
@@ -54,7 +55,7 @@ int64_t restartTs = 10 * 1000 * 60000;
|
||||
|
||||
#endif
|
||||
|
||||
AsyncWebServer* asyncServer = nullptr;
|
||||
PsychicHttpServer* psychicServer = nullptr;
|
||||
NukiNetwork* network = nullptr;
|
||||
WebCfgServer* webCfgServer = nullptr;
|
||||
Preferences* preferences = nullptr;
|
||||
@@ -418,11 +419,11 @@ void setup()
|
||||
|
||||
if(!doOta)
|
||||
{
|
||||
asyncServer = new AsyncWebServer(80);
|
||||
webCfgServer = new WebCfgServer(network, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, asyncServer);
|
||||
psychicServer = new PsychicHttpServer;
|
||||
webCfgServer = new WebCfgServer(network, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
||||
webCfgServer->initialize();
|
||||
asyncServer->onNotFound([](AsyncWebServerRequest* request) { request->redirect("/"); });
|
||||
asyncServer->begin();
|
||||
psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); });
|
||||
psychicServer->listen(80);
|
||||
}
|
||||
#else
|
||||
Log->print(F("Nuki Hub version "));
|
||||
@@ -490,15 +491,20 @@ void setup()
|
||||
{
|
||||
if(!doOta)
|
||||
{
|
||||
asyncServer = new AsyncWebServer(80);
|
||||
psychicServer = new PsychicHttpServer;
|
||||
psychicServer->config.max_uri_handlers = 40;
|
||||
psychicServer->config.stack_size = 8192;
|
||||
psychicServer->listen(80);
|
||||
|
||||
if(forceEnableWebServer || preferences->getBool(preference_webserver_enabled, true))
|
||||
{
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, gpio, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, asyncServer);
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, gpio, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
||||
webCfgServer->initialize();
|
||||
asyncServer->onNotFound([](AsyncWebServerRequest* request) { request->redirect("/"); });
|
||||
psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); });
|
||||
}
|
||||
else asyncServer->onNotFound([](AsyncWebServerRequest* request) { request->redirect("/webserial"); });
|
||||
/*
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
else psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/webserial"); });
|
||||
|
||||
if(preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
@@ -506,8 +512,8 @@ void setup()
|
||||
WebSerial.begin(asyncServer);
|
||||
WebSerial.setBuffer(1024);
|
||||
}
|
||||
|
||||
asyncServer->begin();
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -53,8 +53,7 @@ lib_ignore =
|
||||
SimpleBLE
|
||||
WiFiProv
|
||||
lib_deps =
|
||||
AsyncTCP=symlink://../lib/AsyncTCP
|
||||
ESPAsyncWebServer=symlink://../lib/ESPAsyncWebServer
|
||||
PsychicHttp=symlink://../lib/PsychicHttp
|
||||
WiFiManager=symlink://../lib/WiFiManager
|
||||
|
||||
monitor_speed = 115200
|
||||
@@ -86,8 +85,7 @@ board = esp32-h2-devkitm-1
|
||||
board_build.cmake_extra_args =
|
||||
-DNUKI_TARGET_H2=y
|
||||
lib_deps =
|
||||
AsyncTCP=symlink://../lib/AsyncTCP
|
||||
ESPAsyncWebServer=symlink://../lib/ESPAsyncWebServer
|
||||
PsychicHttp=symlink://../lib/PsychicHttp
|
||||
|
||||
[env:updater_esp32-solo1]
|
||||
extends = env:updater_esp32
|
||||
|
||||
@@ -22,4 +22,13 @@ CONFIG_ETH_ENABLED=y
|
||||
CONFIG_ETH_USE_SPI_ETHERNET=y
|
||||
CONFIG_ETH_SPI_ETHERNET_W5500=y
|
||||
CONFIG_ETH_SPI_ETHERNET_DM9051=y
|
||||
CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y
|
||||
CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||
CONFIG_HTTPD_MAX_URI_LEN=512
|
||||
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
|
||||
CONFIG_HTTPD_PURGE_BUF_LEN=32
|
||||
CONFIG_HTTPD_WS_SUPPORT=y
|
||||
CONFIG_ESP_HTTPS_SERVER_ENABLE=y
|
||||
Reference in New Issue
Block a user