Reimplement WebSerial
This commit is contained in:
@@ -88,10 +88,9 @@ void MqttLogger::sendBuffer()
|
||||
Serial.write(this->buffer, this->bufferCnt);
|
||||
Serial.println();
|
||||
}
|
||||
if (doWebSerial)
|
||||
if (doWebSerial && websocketHandler != nullptr)
|
||||
{
|
||||
//WebSerial.write(this->buffer, this->bufferCnt);
|
||||
//WebSerial.println();
|
||||
websocketHandler->sendAll(HTTPD_WS_TYPE_TEXT, this->buffer, this->bufferCnt);
|
||||
}
|
||||
this->bufferCnt=0;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,11 @@
|
||||
#include <Arduino.h>
|
||||
#include <Print.h>
|
||||
#include <espMqttClient.h>
|
||||
//#include "MycilaWebSerial.h"
|
||||
#include "PsychicWebSocket.h"
|
||||
|
||||
#define MQTT_MAX_PACKET_SIZE 1024
|
||||
|
||||
extern PsychicWebSocketHandler* websocketHandler;
|
||||
extern bool coredumpPrinted;
|
||||
|
||||
enum MqttLoggerMode {
|
||||
|
||||
@@ -306,6 +306,7 @@ String PsychicRequest::getCookie(const char* key)
|
||||
if (!hasCookie(key, &size))
|
||||
return cookie;
|
||||
|
||||
//Following line is needed until https://github.com/espressif/esp-idf/pull/16202 is merged and available in ESP-IDF 5.5 (beta2/RC/final)
|
||||
size = httpd_req_get_hdr_value_len(this->_req, "Cookie");
|
||||
|
||||
// allocate cookie buffer... keep it on the stack
|
||||
|
||||
@@ -58,8 +58,12 @@ lib_ignore =
|
||||
SimpleBLE
|
||||
WiFiProv
|
||||
NimBLE-Arduino
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
ESPAsyncTCP
|
||||
ESPAsyncTCP-esphome
|
||||
AsyncTCP_RP2040W
|
||||
RPAsyncTCP
|
||||
monitor_speed = 115200
|
||||
monitor_filters =
|
||||
esp32_exception_decoder
|
||||
@@ -148,13 +152,7 @@ board_build.cmake_extra_args =
|
||||
-DNUKI_TARGET_H2=y
|
||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.release.defaults;sdkconfig.singlecore.defaults;sdkconfig.ramoptimize.defaults"
|
||||
lib_ignore =
|
||||
BLE
|
||||
BluetoothSerial
|
||||
SimpleBLE
|
||||
WiFiProv
|
||||
NimBLE-Arduino
|
||||
ESPAsyncTCP-esphome
|
||||
AsyncTCP_RP2040W
|
||||
${env.lib_ignore}
|
||||
WiFiManager
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
|
||||
@@ -120,50 +120,50 @@ As an alternative to the Download Tools, you can also use the esptool from the E
|
||||
|
||||
## ESP32
|
||||
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32.bin 0x10000 nuki_hub_esp32.bin 0x270000 nuki_hub_updater_esp32.bin 0x8000 nuki_hub_partitions_esp32.bin
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32.bin 0x10000 nuki_hub_esp32.bin 0x270000 nuki_hub_updater_esp32.bin 0x8000 nuki_hub_partitions_esp32.bin
|
||||
|
||||
## ESP32-NOPSRAM
|
||||
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32nopsram.bin 0x10000 nuki_hub_esp32nopsram.bin 0x270000 nuki_hub_updater_esp32nopsram.bin 0x8000 nuki_hub_partitions_esp32nopsram.bin
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32nopsram.bin 0x10000 nuki_hub_esp32nopsram.bin 0x270000 nuki_hub_updater_esp32nopsram.bin 0x8000 nuki_hub_partitions_esp32nopsram.bin
|
||||
|
||||
## ESP32-GL-S10
|
||||
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32gls10.bin 0x10000 nuki_hub_esp32gls10.bin 0x270000 nuki_hub_updater_esp32gls10.bin 0x8000 nuki_hub_partitions_esp32gls10.bin
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32gls10.bin 0x10000 nuki_hub_esp32gls10.bin 0x270000 nuki_hub_updater_esp32gls10.bin 0x8000 nuki_hub_partitions_esp32gls10.bin
|
||||
|
||||
## ESP32-S3
|
||||
|
||||
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32s3.bin 0x10000 nuki_hub_esp32s3.bin 0x270000 nuki_hub_updater_esp32s3.bin 0x8000 nuki_hub_partitions_esp32s3.bin
|
||||
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32s3.bin 0x10000 nuki_hub_esp32s3.bin 0x270000 nuki_hub_updater_esp32s3.bin 0x8000 nuki_hub_partitions_esp32s3.bin
|
||||
|
||||
## ESP32-S3-NOPSRAM
|
||||
|
||||
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32s3nopsram.bin 0x10000 nuki_hub_esp32s3nopsram.bin 0x270000 nuki_hub_updater_esp32s3nopsram.bin 0x8000 nuki_hub_partitions_esp32s3nopsram.bin
|
||||
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32s3nopsram.bin 0x10000 nuki_hub_esp32s3nopsram.bin 0x270000 nuki_hub_updater_esp32s3nopsram.bin 0x8000 nuki_hub_partitions_esp32s3nopsram.bin
|
||||
|
||||
## ESP32-S3-OCT
|
||||
|
||||
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32s3oct.bin 0x10000 nuki_hub_esp32s3oct.bin 0x270000 nuki_hub_updater_esp32s3oct.bin 0x8000 nuki_hub_partitions_esp32s3oct.bin
|
||||
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32s3oct.bin 0x10000 nuki_hub_esp32s3oct.bin 0x270000 nuki_hub_updater_esp32s3oct.bin 0x8000 nuki_hub_partitions_esp32s3oct.bin
|
||||
|
||||
## ESP32-C3
|
||||
|
||||
esptool.py --chip esp32c3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32c3.bin 0x10000 nuki_hub_esp32c3.bin 0x270000 nuki_hub_updater_esp32c3.bin 0x8000 nuki_hub_partitions_esp32c3.bin
|
||||
esptool.py --chip esp32c3 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32c3.bin 0x10000 nuki_hub_esp32c3.bin 0x270000 nuki_hub_updater_esp32c3.bin 0x8000 nuki_hub_partitions_esp32c3.bin
|
||||
|
||||
## ESP32-C5
|
||||
|
||||
esptool.py --chip esp32c5 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x2000 nuki_hub_bootloader_esp32c5.bin 0x10000 nuki_hub_esp32c5.bin 0x260000 nuki_hub_updater_esp32c5.bin 0x8000 nuki_hub_partitions_esp32c5.bin
|
||||
esptool.py --chip esp32c5 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x2000 nuki_hub_bootloader_esp32c5.bin 0x10000 nuki_hub_esp32c5.bin 0x260000 nuki_hub_updater_esp32c5.bin 0x8000 nuki_hub_partitions_esp32c5.bin
|
||||
|
||||
## ESP32-C6
|
||||
|
||||
esptool.py --chip esp32c6 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32c6.bin 0x10000 nuki_hub_esp32c6.bin 0x270000 nuki_hub_updater_esp32c6.bin 0x8000 nuki_hub_partitions_esp32c6.bin
|
||||
esptool.py --chip esp32c6 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32c6.bin 0x10000 nuki_hub_esp32c6.bin 0x270000 nuki_hub_updater_esp32c6.bin 0x8000 nuki_hub_partitions_esp32c6.bin
|
||||
|
||||
## ESP32-H2
|
||||
|
||||
esptool.py --chip esp32h2 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32h2.bin 0x10000 nuki_hub_esp32h2.bin 0x270000 nuki_hub_updater_esp32h2.bin 0x8000 nuki_hub_partitions_esp32h2.bin
|
||||
esptool.py --chip esp32h2 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x0 nuki_hub_bootloader_esp32h2.bin 0x10000 nuki_hub_esp32h2.bin 0x270000 nuki_hub_updater_esp32h2.bin 0x8000 nuki_hub_partitions_esp32h2.bin
|
||||
|
||||
## ESP32-P4
|
||||
|
||||
esptool.py --chip esp32p4 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x2000 nuki_hub_bootloader_esp32p4.bin 0x10000 nuki_hub_esp32p4.bin 0x270000 nuki_hub_updater_esp32p4.bin 0x8000 nuki_hub_partitions_esp32p4.bin
|
||||
esptool.py --chip esp32p4 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x2000 nuki_hub_bootloader_esp32p4.bin 0x10000 nuki_hub_esp32p4.bin 0x270000 nuki_hub_updater_esp32p4.bin 0x8000 nuki_hub_partitions_esp32p4.bin
|
||||
|
||||
## ESP32-SOLO1
|
||||
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32solo1.bin 0x10000 nuki_hub_esp32solo1.bin 0x270000 nuki_hub_updater_esp32solo1.bin 0x8000 nuki_hub_partitions_esp32solo1.bin
|
||||
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq keep --flash-size detect 0xe000 boot_app0.bin 0x1000 nuki_hub_bootloader_esp32solo1.bin 0x10000 nuki_hub_esp32solo1.bin 0x270000 nuki_hub_updater_esp32solo1.bin 0x8000 nuki_hub_partitions_esp32solo1.bin
|
||||
|
||||
Adjust the serial device and path to the binaries if necessary.
|
||||
@@ -5,7 +5,7 @@
|
||||
#define NUKI_HUB_VERSION "9.12"
|
||||
#define NUKI_HUB_VERSION_INT (uint32_t)912
|
||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
||||
#define NUKI_HUB_DATE "2025-06-27"
|
||||
#define NUKI_HUB_DATE "2025-06-30"
|
||||
|
||||
#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"
|
||||
|
||||
@@ -28,6 +28,15 @@ extern bool timeSynced;
|
||||
#include <HTTPClient.h>
|
||||
#include <NetworkClientSecure.h>
|
||||
#include "ArduinoJson.h"
|
||||
#include <freertos/queue.h>
|
||||
|
||||
typedef struct {
|
||||
int socket;
|
||||
char *buffer;
|
||||
size_t len;
|
||||
} WebsocketMessage;
|
||||
|
||||
QueueHandle_t wsMessages;
|
||||
|
||||
WebCfgServer::WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport)
|
||||
: _nuki(nuki),
|
||||
@@ -88,6 +97,7 @@ WebCfgServer::WebCfgServer(NukiNetwork* network, Preferences* preferences, bool
|
||||
}
|
||||
_confirmCode = generateConfirmCode();
|
||||
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
_brokerConfigured = _preferences->getString(preference_mqtt_broker).length() > 0 && _preferences->getInt(preference_mqtt_broker_port) > 0;
|
||||
#endif
|
||||
@@ -422,6 +432,96 @@ void WebCfgServer::initialize()
|
||||
{
|
||||
return sendCss(request, resp);
|
||||
});
|
||||
|
||||
|
||||
if(_preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
if (websocketHandler == nullptr)
|
||||
{
|
||||
websocketHandler = new PsychicWebSocketHandler;
|
||||
}
|
||||
|
||||
_psychicServer->on("/webserial", HTTP_GET, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||
{
|
||||
int authReq = doAuthentication(request);
|
||||
|
||||
switch (authReq)
|
||||
{
|
||||
case 0:
|
||||
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
break;
|
||||
case 1:
|
||||
return request->requestAuthentication(DIGEST_AUTH, "Nuki Hub", "You must log in.");
|
||||
break;
|
||||
case 2:
|
||||
resp->setCode(302);
|
||||
resp->addHeader("Cache-Control", "no-cache");
|
||||
return resp->redirect("/get?page=login");
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
case 4:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return sendWebSerial(request, resp);
|
||||
});
|
||||
|
||||
//prepare our message queue of 10 messages
|
||||
wsMessages = xQueueCreate(10, sizeof(WebsocketMessage));
|
||||
if (wsMessages == 0) {
|
||||
Log->printf("Failed to create queue= %p\n", wsMessages);
|
||||
}
|
||||
|
||||
websocketHandler->onOpen([](PsychicWebSocketClient *client) {
|
||||
Log->printf("[socket] connection #%u connected from %s\n", client->socket(), client->remoteIP().toString());
|
||||
client->sendMessage("NukiHub WebSerial started");
|
||||
});
|
||||
websocketHandler->onFrame([](PsychicWebSocketRequest *request, httpd_ws_frame *frame)
|
||||
{
|
||||
if(strcmp((char *)frame->payload, "ping") == 0)
|
||||
{
|
||||
WebsocketMessage wm;
|
||||
wm.socket = request->client()->socket();
|
||||
wm.len = frame->len;
|
||||
wm.buffer = (char *)malloc(frame->len);
|
||||
|
||||
if (wm.buffer == NULL)
|
||||
{
|
||||
Log->printf("Queue message: unable to allocate %d bytes\n", frame->len);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
memcpy(wm.buffer, "pong", frame->len);
|
||||
|
||||
if (xQueueSend(wsMessages, &wm, 1) != pdTRUE)
|
||||
{
|
||||
Log->printf("[socket] queue full #%d\n", wm.socket);
|
||||
free(wm.buffer);
|
||||
}
|
||||
|
||||
if (!uxQueueSpacesAvailable(wsMessages))
|
||||
{
|
||||
return request->reply("Queue Full");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->printf("[socket] #%d sent: %s\n", request->client()->socket(), (char *)frame->payload);
|
||||
}
|
||||
return ESP_OK;
|
||||
});
|
||||
websocketHandler->onClose([](PsychicWebSocketClient *client) {
|
||||
Log->printf("[socket] connection #%u closed from %s\n", client->socket(), client->remoteIP().toString());
|
||||
});
|
||||
|
||||
_psychicServer->on("/ws", websocketHandler);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
_psychicServer->on("/favicon.ico", HTTP_GET, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||
{
|
||||
return sendFavicon(request, resp);
|
||||
@@ -430,6 +530,110 @@ void WebCfgServer::initialize()
|
||||
if(_network->isApOpen())
|
||||
{
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
_psychicServer->on("/get", HTTP_GET, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||
{
|
||||
String value = "";
|
||||
if(request->hasParam("page"))
|
||||
{
|
||||
const PsychicWebParameter* p = request->getParam("page");
|
||||
if(p->value() != "")
|
||||
{
|
||||
value = p->value();
|
||||
}
|
||||
}
|
||||
if (value != "login")
|
||||
{
|
||||
int authReq = doAuthentication(request);
|
||||
|
||||
switch (authReq)
|
||||
{
|
||||
case 0:
|
||||
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
break;
|
||||
case 1:
|
||||
return request->requestAuthentication(DIGEST_AUTH, "Nuki Hub", "You must log in.");
|
||||
break;
|
||||
case 2:
|
||||
resp->setCode(302);
|
||||
resp->addHeader("Cache-Control", "no-cache");
|
||||
return resp->redirect("/get?page=login");
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (value == "login")
|
||||
{
|
||||
return buildLoginHtml(request, resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println("Page not found, loading index");
|
||||
resp->setCode(302);
|
||||
resp->addHeader("Cache-Control", "no-cache");
|
||||
return resp->redirect("/");
|
||||
}
|
||||
});
|
||||
|
||||
_psychicServer->on("/post", HTTP_POST, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||
{
|
||||
String value = "";
|
||||
if(request->hasParam("page"))
|
||||
{
|
||||
const PsychicWebParameter* p = request->getParam("page");
|
||||
if(p->value() != "")
|
||||
{
|
||||
value = p->value();
|
||||
}
|
||||
}
|
||||
|
||||
if(value != "login")
|
||||
{
|
||||
int authReq = doAuthentication(request);
|
||||
|
||||
switch (authReq)
|
||||
{
|
||||
case 0:
|
||||
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||
break;
|
||||
case 1:
|
||||
return request->requestAuthentication(DIGEST_AUTH, "Nuki Hub", "You must log in.");
|
||||
break;
|
||||
case 2:
|
||||
resp->setCode(302);
|
||||
resp->addHeader("Cache-Control", "no-cache");
|
||||
return resp->redirect("/get?page=login");
|
||||
break;
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (value == "login")
|
||||
{
|
||||
bool loggedIn = processLogin(request, resp);
|
||||
if (loggedIn)
|
||||
{
|
||||
resp->setCode(302);
|
||||
resp->addHeader("Cache-Control", "no-cache");
|
||||
return resp->redirect("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
resp->setCode(302);
|
||||
resp->addHeader("Cache-Control", "no-cache");
|
||||
return resp->redirect("/get?page=login");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return buildWifiConnectHtml(request, resp);
|
||||
}
|
||||
});
|
||||
|
||||
_psychicServer->on("/ssidlist", HTTP_GET, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||
{
|
||||
return buildSSIDListHtml(request, resp);
|
||||
@@ -2440,6 +2644,34 @@ bool WebCfgServer::processTOTP(PsychicRequest *request, PsychicResponse* resp)
|
||||
}
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
esp_err_t WebCfgServer::sendWebSerial(PsychicRequest* request, PsychicResponse* resp)
|
||||
{
|
||||
// escaped by https://www.cescaper.com/
|
||||
resp->addHeader("Cache-Control", "public, max-age=3600");
|
||||
resp->setCode(200);
|
||||
resp->setContentType("text/html");
|
||||
resp->setContent((const uint8_t *)WEBSERIAL_HTML, sizeof(WEBSERIAL_HTML));
|
||||
return resp->send();
|
||||
}
|
||||
|
||||
void WebCfgServer::updateWebSerial()
|
||||
{
|
||||
if (websocketHandler != nullptr) {
|
||||
WebsocketMessage message;
|
||||
while (xQueueReceive(wsMessages, &message, 0) == pdTRUE)
|
||||
{
|
||||
PsychicWebSocketClient *client = websocketHandler->getClient(message.socket);
|
||||
if (client == NULL) {
|
||||
Log->printf("[socket] client #%d bad, bailing\n", message.socket);
|
||||
return;
|
||||
}
|
||||
|
||||
client->sendMessage(HTTPD_WS_TYPE_TEXT, message.buffer, message.len);
|
||||
free(message.buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t WebCfgServer::sendSettings(PsychicRequest *request, PsychicResponse* resp, bool adminKey)
|
||||
{
|
||||
JsonDocument json;
|
||||
@@ -4873,10 +5105,6 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
||||
{
|
||||
response.print("<table><tbody><tr><td colspan=\"2\" style=\"border: 0; color: red; font-size: 32px; font-weight: bold; text-align: center;\">RESTART SERVICES REQUIRED TO APPLY SOME SETTINGS</td></tr></tbody></table>");
|
||||
}
|
||||
if(_preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
response.print("<table><tbody><tr><td colspan=\"2\" style=\"border: 0; color: red; font-size: 32px; font-weight: bold; text-align: center;\">WEBSERIAL IS ENABLED, ONLY ENABLE WHEN DEBUGGING AND DISABLE ASAP</td></tr></tbody></table>");
|
||||
}
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
response.print("<table><tbody><tr><td colspan=\"2\" style=\"border: 0; color: red; font-size: 32px; font-weight: bold; text-align: center;\">RUNNING DEBUG BUILD, SWITCH TO RELEASE BUILD ASAP</td></tr></tbody></table>");
|
||||
#endif
|
||||
@@ -4949,7 +5177,7 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
||||
}
|
||||
if(_preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
buildNavigationMenuEntry(&response, "Open Webserial", "/get?page=webserial");
|
||||
buildNavigationMenuEntry(&response, "Open Webserial", "/webserial");
|
||||
}
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
if(_allowRestartToPortal)
|
||||
@@ -5420,7 +5648,7 @@ esp_err_t WebCfgServer::buildAdvancedConfigHtml(PsychicRequest *request, Psychic
|
||||
response.print(_preferences->getBool(preference_enable_bootloop_reset, false) ? "Enabled" : "Disabled");
|
||||
response.print("</td></tr>");
|
||||
printCheckBox(&response, "DISNTWNOCON", "Disable Network if not connected within 60s", _preferences->getBool(preference_disable_network_not_connected, false), "");
|
||||
//printCheckBox(&response, "WEBLOG", "Enable WebSerial logging", _preferences->getBool(preference_webserial_enabled), "");
|
||||
printCheckBox(&response, "WEBLOG", "Enable WebSerial logging", _preferences->getBool(preference_webserial_enabled), "");
|
||||
printCheckBox(&response, "BTLPRST", "Enable Bootloop prevention (Try to reset these settings to default on bootloop)", true, "");
|
||||
printInputField(&response, "BUFFSIZE", "Char buffer size (min 4096, max 65536)", _preferences->getInt(preference_buffer_size, CHAR_BUFFER_SIZE), 6, "");
|
||||
response.print("<tr><td>Advised minimum char buffer size based on current settings</td><td id=\"mincharbuffer\"></td>");
|
||||
|
||||
@@ -44,6 +44,7 @@ class WebCfgServer
|
||||
public:
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport);
|
||||
void updateWebSerial();
|
||||
#else
|
||||
WebCfgServer(NukiNetwork* network, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport);
|
||||
#endif
|
||||
@@ -127,6 +128,7 @@ private:
|
||||
esp_err_t buildConfirmHtml(PsychicRequest *request, PsychicResponse* resp, const String &message, uint32_t redirectDelay = 5, bool redirect = false, String redirectTo = "/");
|
||||
esp_err_t buildOtaHtml(PsychicRequest *request, PsychicResponse* resp, bool debug = false);
|
||||
esp_err_t sendCss(PsychicRequest *request, PsychicResponse* resp);
|
||||
esp_err_t sendWebSerial(PsychicRequest *request, PsychicResponse* resp);
|
||||
esp_err_t sendFavicon(PsychicRequest *request, PsychicResponse* resp);
|
||||
void createSsidList();
|
||||
void buildHtmlHeader(PsychicStreamResponse *response, String additionalHeader = "");
|
||||
|
||||
File diff suppressed because one or more lines are too long
45
src/main.cpp
45
src/main.cpp
@@ -45,13 +45,6 @@ bool nuki_hub_https_server_enabled = false;
|
||||
#include "NimBLEDevice.h"
|
||||
#include "ImportExport.h"
|
||||
|
||||
/*
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
#include <WString.h>
|
||||
#include <MycilaWebSerial.h>
|
||||
#endif
|
||||
*/
|
||||
|
||||
NukiNetworkLock* networkLock = nullptr;
|
||||
NukiNetworkOpener* networkOpener = nullptr;
|
||||
BleScanner::Scanner* bleScanner = nullptr;
|
||||
@@ -94,6 +87,8 @@ char log_print_buffer[1024];
|
||||
PsychicHttpServer* psychicServer = nullptr;
|
||||
PsychicHttpServer* psychicServerRedirect = nullptr;
|
||||
PsychicHttpsServer* psychicSSLServer = nullptr;
|
||||
PsychicWebSocketHandler* websocketHandler = nullptr;
|
||||
|
||||
NukiNetwork* network = nullptr;
|
||||
WebCfgServer* webCfgServer = nullptr;
|
||||
WebCfgServer* webCfgServerSSL = nullptr;
|
||||
@@ -118,6 +113,7 @@ bool webSSLStarted = false;
|
||||
bool lockStarted = false;
|
||||
bool openerStarted = false;
|
||||
bool bleScannerStarted = false;
|
||||
bool webSerialEnabled = false;
|
||||
uint8_t partitionType = -1;
|
||||
|
||||
int lastHTTPeventId = -1;
|
||||
@@ -261,12 +257,16 @@ void startWebServer()
|
||||
{
|
||||
bool failed = true;
|
||||
|
||||
if (!nuki_hub_https_server_enabled) {
|
||||
webSerialEnabled = preferences->getBool(preference_webserial_enabled, false);
|
||||
|
||||
if (!nuki_hub_https_server_enabled)
|
||||
{
|
||||
Log->println("Not running on PSRAM enabled device");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SPIFFS.begin(true)) {
|
||||
if (!SPIFFS.begin(true))
|
||||
{
|
||||
Log->println("SPIFFS Mount Failed");
|
||||
}
|
||||
else
|
||||
@@ -286,7 +286,8 @@ void startWebServer()
|
||||
cert[filesize] = '\0';
|
||||
|
||||
File file2 = SPIFFS.open("/http_ssl.key");
|
||||
if (!file2 || file2.isDirectory()) {
|
||||
if (!file2 || file2.isDirectory())
|
||||
{
|
||||
Log->println("http_ssl.key not found");
|
||||
}
|
||||
else
|
||||
@@ -602,6 +603,15 @@ void networkTask(void *pvParameters)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(connected && webSerialEnabled && (webSSLStarted || webStarted))
|
||||
{
|
||||
webCfgServerSSL->updateWebSerial();
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
if(connected && lockStarted)
|
||||
{
|
||||
rebootLock = networkLock->update();
|
||||
@@ -1304,9 +1314,6 @@ void setup()
|
||||
Log->print("Nuki Hub build ");
|
||||
Log->println(NUKI_HUB_BUILD);
|
||||
|
||||
Log->println(preferences->getString(preference_cred_user));
|
||||
Log->println(preferences->getString(preference_cred_password));
|
||||
|
||||
uint32_t devIdOpener = preferences->getUInt(preference_device_id_opener);
|
||||
|
||||
deviceIdLock = new NukiDeviceId(preferences, preference_device_id_lock);
|
||||
@@ -1380,18 +1387,6 @@ void setup()
|
||||
{
|
||||
startWebServer();
|
||||
}
|
||||
/*
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
else psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/webserial"); });
|
||||
|
||||
if(preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
WebSerial.setAuthentication(preferences->getString(preference_cred_user), preferences->getString(preference_cred_password));
|
||||
WebSerial.begin(psychicServer);
|
||||
WebSerial.setBuffer(1024);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -37,14 +37,22 @@ void WifiDevice::initialize()
|
||||
{
|
||||
Log->println(String("Attempting to connect to saved SSID ") + String(ssid));
|
||||
_openAP = false;
|
||||
if(_preferences->getBool(preference_find_best_rssi, false))
|
||||
{
|
||||
scan(false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.mode(WIFI_STA);
|
||||
connect();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println("No SSID or Wifi password saved, opening AP");
|
||||
_openAP = true;
|
||||
scan(false, true);
|
||||
}
|
||||
|
||||
scan(false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -133,6 +141,15 @@ void WifiDevice::openAP()
|
||||
|
||||
bool WifiDevice::connect()
|
||||
{
|
||||
int loop = 0;
|
||||
while (!_wifiClientStarted && loop < 50) {
|
||||
if (esp_task_wdt_status(NULL) == ESP_OK) {
|
||||
esp_task_wdt_reset();
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
loop++;
|
||||
}
|
||||
|
||||
int bestConnection = -1;
|
||||
|
||||
if(_preferences->getBool(preference_find_best_rssi, false))
|
||||
@@ -180,10 +197,17 @@ bool WifiDevice::connect()
|
||||
WiFi.config(_ipConfiguration->ipAddress(), _ipConfiguration->dnsServer(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet());
|
||||
}
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
if (bestConnection == -1)
|
||||
{
|
||||
WiFi.begin(ssid, pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
WiFi.begin(ssid, pass, WiFi.channel(bestConnection), WiFi.BSSID(bestConnection), 1);
|
||||
}
|
||||
|
||||
Log->print("WiFi connecting");
|
||||
int loop = 0;
|
||||
loop = 0;
|
||||
while(!isConnected() && loop < 600)
|
||||
{
|
||||
Log->print(".");
|
||||
|
||||
Reference in New Issue
Block a user