Reimplement WebSerial
This commit is contained in:
@@ -75,7 +75,7 @@ void MqttLogger::sendBuffer()
|
|||||||
{
|
{
|
||||||
bool doSerial = this->mode==MqttLoggerMode::SerialOnly || this->mode==MqttLoggerMode::MqttAndSerial || this->mode==MqttLoggerMode::MqttAndSerialAndWeb || this->mode==MqttLoggerMode::SerialAndWeb;
|
bool doSerial = this->mode==MqttLoggerMode::SerialOnly || this->mode==MqttLoggerMode::MqttAndSerial || this->mode==MqttLoggerMode::MqttAndSerialAndWeb || this->mode==MqttLoggerMode::SerialAndWeb;
|
||||||
bool doWebSerial = this->mode==MqttLoggerMode::MqttAndSerialAndWeb || this->mode==MqttLoggerMode::SerialAndWeb;
|
bool doWebSerial = this->mode==MqttLoggerMode::MqttAndSerialAndWeb || this->mode==MqttLoggerMode::SerialAndWeb;
|
||||||
if (this->mode!=MqttLoggerMode::SerialOnly && this->mode!=MqttLoggerMode::SerialAndWeb && this->client != NULL && this->client->connected())
|
if (this->mode!=MqttLoggerMode::SerialOnly && this->mode!=MqttLoggerMode::SerialAndWeb && this->client != NULL && this->client->connected())
|
||||||
{
|
{
|
||||||
this->client->publish(topic, 0, true, this->buffer, this->bufferCnt);
|
this->client->publish(topic, 0, true, this->buffer, this->bufferCnt);
|
||||||
}
|
}
|
||||||
@@ -88,10 +88,9 @@ void MqttLogger::sendBuffer()
|
|||||||
Serial.write(this->buffer, this->bufferCnt);
|
Serial.write(this->buffer, this->bufferCnt);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
if (doWebSerial)
|
if (doWebSerial && websocketHandler != nullptr)
|
||||||
{
|
{
|
||||||
//WebSerial.write(this->buffer, this->bufferCnt);
|
websocketHandler->sendAll(HTTPD_WS_TYPE_TEXT, this->buffer, this->bufferCnt);
|
||||||
//WebSerial.println();
|
|
||||||
}
|
}
|
||||||
this->bufferCnt=0;
|
this->bufferCnt=0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,11 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Print.h>
|
#include <Print.h>
|
||||||
#include <espMqttClient.h>
|
#include <espMqttClient.h>
|
||||||
//#include "MycilaWebSerial.h"
|
#include "PsychicWebSocket.h"
|
||||||
|
|
||||||
#define MQTT_MAX_PACKET_SIZE 1024
|
#define MQTT_MAX_PACKET_SIZE 1024
|
||||||
|
|
||||||
|
extern PsychicWebSocketHandler* websocketHandler;
|
||||||
extern bool coredumpPrinted;
|
extern bool coredumpPrinted;
|
||||||
|
|
||||||
enum MqttLoggerMode {
|
enum MqttLoggerMode {
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ String PsychicRequest::getCookie(const char* key)
|
|||||||
if (!hasCookie(key, &size))
|
if (!hasCookie(key, &size))
|
||||||
return cookie;
|
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");
|
size = httpd_req_get_hdr_value_len(this->_req, "Cookie");
|
||||||
|
|
||||||
// allocate cookie buffer... keep it on the stack
|
// allocate cookie buffer... keep it on the stack
|
||||||
|
|||||||
@@ -58,8 +58,12 @@ lib_ignore =
|
|||||||
SimpleBLE
|
SimpleBLE
|
||||||
WiFiProv
|
WiFiProv
|
||||||
NimBLE-Arduino
|
NimBLE-Arduino
|
||||||
|
AsyncTCP
|
||||||
|
ESPAsyncWebServer
|
||||||
|
ESPAsyncTCP
|
||||||
ESPAsyncTCP-esphome
|
ESPAsyncTCP-esphome
|
||||||
AsyncTCP_RP2040W
|
AsyncTCP_RP2040W
|
||||||
|
RPAsyncTCP
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_filters =
|
monitor_filters =
|
||||||
esp32_exception_decoder
|
esp32_exception_decoder
|
||||||
@@ -148,13 +152,7 @@ board_build.cmake_extra_args =
|
|||||||
-DNUKI_TARGET_H2=y
|
-DNUKI_TARGET_H2=y
|
||||||
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.release.defaults;sdkconfig.singlecore.defaults;sdkconfig.ramoptimize.defaults"
|
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.release.defaults;sdkconfig.singlecore.defaults;sdkconfig.ramoptimize.defaults"
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
BLE
|
${env.lib_ignore}
|
||||||
BluetoothSerial
|
|
||||||
SimpleBLE
|
|
||||||
WiFiProv
|
|
||||||
NimBLE-Arduino
|
|
||||||
ESPAsyncTCP-esphome
|
|
||||||
AsyncTCP_RP2040W
|
|
||||||
WiFiManager
|
WiFiManager
|
||||||
build_flags =
|
build_flags =
|
||||||
${env.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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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.
|
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 "9.12"
|
||||||
#define NUKI_HUB_VERSION_INT (uint32_t)912
|
#define NUKI_HUB_VERSION_INT (uint32_t)912
|
||||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
#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_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"
|
#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 <HTTPClient.h>
|
||||||
#include <NetworkClientSecure.h>
|
#include <NetworkClientSecure.h>
|
||||||
#include "ArduinoJson.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)
|
WebCfgServer::WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport)
|
||||||
: _nuki(nuki),
|
: _nuki(nuki),
|
||||||
@@ -88,6 +97,7 @@ WebCfgServer::WebCfgServer(NukiNetwork* network, Preferences* preferences, bool
|
|||||||
}
|
}
|
||||||
_confirmCode = generateConfirmCode();
|
_confirmCode = generateConfirmCode();
|
||||||
|
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
_brokerConfigured = _preferences->getString(preference_mqtt_broker).length() > 0 && _preferences->getInt(preference_mqtt_broker_port) > 0;
|
_brokerConfigured = _preferences->getString(preference_mqtt_broker).length() > 0 && _preferences->getInt(preference_mqtt_broker_port) > 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -422,6 +432,96 @@ void WebCfgServer::initialize()
|
|||||||
{
|
{
|
||||||
return sendCss(request, resp);
|
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)
|
_psychicServer->on("/favicon.ico", HTTP_GET, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||||
{
|
{
|
||||||
return sendFavicon(request, resp);
|
return sendFavicon(request, resp);
|
||||||
@@ -430,6 +530,110 @@ void WebCfgServer::initialize()
|
|||||||
if(_network->isApOpen())
|
if(_network->isApOpen())
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
#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)
|
_psychicServer->on("/ssidlist", HTTP_GET, [&](PsychicRequest *request, PsychicResponse* resp)
|
||||||
{
|
{
|
||||||
return buildSSIDListHtml(request, resp);
|
return buildSSIDListHtml(request, resp);
|
||||||
@@ -2440,6 +2644,34 @@ bool WebCfgServer::processTOTP(PsychicRequest *request, PsychicResponse* resp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#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)
|
esp_err_t WebCfgServer::sendSettings(PsychicRequest *request, PsychicResponse* resp, bool adminKey)
|
||||||
{
|
{
|
||||||
JsonDocument json;
|
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>");
|
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
|
#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>");
|
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
|
#endif
|
||||||
@@ -4949,7 +5177,7 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
|
|||||||
}
|
}
|
||||||
if(_preferences->getBool(preference_webserial_enabled, false))
|
if(_preferences->getBool(preference_webserial_enabled, false))
|
||||||
{
|
{
|
||||||
buildNavigationMenuEntry(&response, "Open Webserial", "/get?page=webserial");
|
buildNavigationMenuEntry(&response, "Open Webserial", "/webserial");
|
||||||
}
|
}
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||||
if(_allowRestartToPortal)
|
if(_allowRestartToPortal)
|
||||||
@@ -5387,7 +5615,7 @@ esp_err_t WebCfgServer::buildHttpSSLConfigHtml(PsychicRequest *request, PsychicR
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
printTextarea(&response, "HTTPKEY", "HTTP SSL Key (*, optional)", "", 2200, true, true);
|
printTextarea(&response, "HTTPKEY", "HTTP SSL Key (*, optional)", "", 2200, true, true);
|
||||||
@@ -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(_preferences->getBool(preference_enable_bootloop_reset, false) ? "Enabled" : "Disabled");
|
||||||
response.print("</td></tr>");
|
response.print("</td></tr>");
|
||||||
printCheckBox(&response, "DISNTWNOCON", "Disable Network if not connected within 60s", _preferences->getBool(preference_disable_network_not_connected, false), "");
|
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, "");
|
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, "");
|
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>");
|
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:
|
public:
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport);
|
WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, NukiNetwork* network, Gpio* gpio, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport);
|
||||||
|
void updateWebSerial();
|
||||||
#else
|
#else
|
||||||
WebCfgServer(NukiNetwork* network, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport);
|
WebCfgServer(NukiNetwork* network, Preferences* preferences, bool allowRestartToPortal, uint8_t partitionType, PsychicHttpServer* psychicServer, ImportExport* importExport);
|
||||||
#endif
|
#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 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 buildOtaHtml(PsychicRequest *request, PsychicResponse* resp, bool debug = false);
|
||||||
esp_err_t sendCss(PsychicRequest *request, PsychicResponse* resp);
|
esp_err_t sendCss(PsychicRequest *request, PsychicResponse* resp);
|
||||||
|
esp_err_t sendWebSerial(PsychicRequest *request, PsychicResponse* resp);
|
||||||
esp_err_t sendFavicon(PsychicRequest *request, PsychicResponse* resp);
|
esp_err_t sendFavicon(PsychicRequest *request, PsychicResponse* resp);
|
||||||
void createSsidList();
|
void createSsidList();
|
||||||
void buildHtmlHeader(PsychicStreamResponse *response, String additionalHeader = "");
|
void buildHtmlHeader(PsychicStreamResponse *response, String additionalHeader = "");
|
||||||
@@ -145,7 +147,7 @@ private:
|
|||||||
NukiNetwork* _network = nullptr;
|
NukiNetwork* _network = nullptr;
|
||||||
Preferences* _preferences = nullptr;
|
Preferences* _preferences = nullptr;
|
||||||
ImportExport* _importExport;
|
ImportExport* _importExport;
|
||||||
|
|
||||||
char _credUser[31] = {0};
|
char _credUser[31] = {0};
|
||||||
char _credPassword[31] = {0};
|
char _credPassword[31] = {0};
|
||||||
bool _allowRestartToPortal = false;
|
bool _allowRestartToPortal = false;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
47
src/main.cpp
47
src/main.cpp
@@ -45,13 +45,6 @@ bool nuki_hub_https_server_enabled = false;
|
|||||||
#include "NimBLEDevice.h"
|
#include "NimBLEDevice.h"
|
||||||
#include "ImportExport.h"
|
#include "ImportExport.h"
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef DEBUG_NUKIHUB
|
|
||||||
#include <WString.h>
|
|
||||||
#include <MycilaWebSerial.h>
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
NukiNetworkLock* networkLock = nullptr;
|
NukiNetworkLock* networkLock = nullptr;
|
||||||
NukiNetworkOpener* networkOpener = nullptr;
|
NukiNetworkOpener* networkOpener = nullptr;
|
||||||
BleScanner::Scanner* bleScanner = nullptr;
|
BleScanner::Scanner* bleScanner = nullptr;
|
||||||
@@ -94,6 +87,8 @@ char log_print_buffer[1024];
|
|||||||
PsychicHttpServer* psychicServer = nullptr;
|
PsychicHttpServer* psychicServer = nullptr;
|
||||||
PsychicHttpServer* psychicServerRedirect = nullptr;
|
PsychicHttpServer* psychicServerRedirect = nullptr;
|
||||||
PsychicHttpsServer* psychicSSLServer = nullptr;
|
PsychicHttpsServer* psychicSSLServer = nullptr;
|
||||||
|
PsychicWebSocketHandler* websocketHandler = nullptr;
|
||||||
|
|
||||||
NukiNetwork* network = nullptr;
|
NukiNetwork* network = nullptr;
|
||||||
WebCfgServer* webCfgServer = nullptr;
|
WebCfgServer* webCfgServer = nullptr;
|
||||||
WebCfgServer* webCfgServerSSL = nullptr;
|
WebCfgServer* webCfgServerSSL = nullptr;
|
||||||
@@ -118,6 +113,7 @@ bool webSSLStarted = false;
|
|||||||
bool lockStarted = false;
|
bool lockStarted = false;
|
||||||
bool openerStarted = false;
|
bool openerStarted = false;
|
||||||
bool bleScannerStarted = false;
|
bool bleScannerStarted = false;
|
||||||
|
bool webSerialEnabled = false;
|
||||||
uint8_t partitionType = -1;
|
uint8_t partitionType = -1;
|
||||||
|
|
||||||
int lastHTTPeventId = -1;
|
int lastHTTPeventId = -1;
|
||||||
@@ -260,13 +256,17 @@ void cbSyncTime(struct timeval *tv) {
|
|||||||
void startWebServer()
|
void startWebServer()
|
||||||
{
|
{
|
||||||
bool failed = true;
|
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");
|
Log->println("Not running on PSRAM enabled device");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!SPIFFS.begin(true)) {
|
if (!SPIFFS.begin(true))
|
||||||
|
{
|
||||||
Log->println("SPIFFS Mount Failed");
|
Log->println("SPIFFS Mount Failed");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -286,7 +286,8 @@ void startWebServer()
|
|||||||
cert[filesize] = '\0';
|
cert[filesize] = '\0';
|
||||||
|
|
||||||
File file2 = SPIFFS.open("/http_ssl.key");
|
File file2 = SPIFFS.open("/http_ssl.key");
|
||||||
if (!file2 || file2.isDirectory()) {
|
if (!file2 || file2.isDirectory())
|
||||||
|
{
|
||||||
Log->println("http_ssl.key not found");
|
Log->println("http_ssl.key not found");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -602,6 +603,15 @@ void networkTask(void *pvParameters)
|
|||||||
}
|
}
|
||||||
else
|
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)
|
if(connected && lockStarted)
|
||||||
{
|
{
|
||||||
rebootLock = networkLock->update();
|
rebootLock = networkLock->update();
|
||||||
@@ -1304,9 +1314,6 @@ void setup()
|
|||||||
Log->print("Nuki Hub build ");
|
Log->print("Nuki Hub build ");
|
||||||
Log->println(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);
|
uint32_t devIdOpener = preferences->getUInt(preference_device_id_opener);
|
||||||
|
|
||||||
deviceIdLock = new NukiDeviceId(preferences, preference_device_id_lock);
|
deviceIdLock = new NukiDeviceId(preferences, preference_device_id_lock);
|
||||||
@@ -1380,18 +1387,6 @@ void setup()
|
|||||||
{
|
{
|
||||||
startWebServer();
|
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
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -37,14 +37,22 @@ void WifiDevice::initialize()
|
|||||||
{
|
{
|
||||||
Log->println(String("Attempting to connect to saved SSID ") + String(ssid));
|
Log->println(String("Attempting to connect to saved SSID ") + String(ssid));
|
||||||
_openAP = false;
|
_openAP = false;
|
||||||
|
if(_preferences->getBool(preference_find_best_rssi, false))
|
||||||
|
{
|
||||||
|
scan(false, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
connect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log->println("No SSID or Wifi password saved, opening AP");
|
Log->println("No SSID or Wifi password saved, opening AP");
|
||||||
_openAP = true;
|
_openAP = true;
|
||||||
|
scan(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
scan(false, true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -133,6 +141,15 @@ void WifiDevice::openAP()
|
|||||||
|
|
||||||
bool WifiDevice::connect()
|
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;
|
int bestConnection = -1;
|
||||||
|
|
||||||
if(_preferences->getBool(preference_find_best_rssi, false))
|
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.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");
|
Log->print("WiFi connecting");
|
||||||
int loop = 0;
|
loop = 0;
|
||||||
while(!isConnected() && loop < 600)
|
while(!isConnected() && loop < 600)
|
||||||
{
|
{
|
||||||
Log->print(".");
|
Log->print(".");
|
||||||
|
|||||||
Reference in New Issue
Block a user