mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-12 11:14:28 +05:00
Compare commits
12 Commits
hyst
...
passive_bl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c39eeee9cf | ||
|
|
f2fe6036c2 | ||
|
|
40dc863530 | ||
|
|
a40413aeac | ||
|
|
9a045bfc40 | ||
|
|
d576969ea4 | ||
|
|
c78d2d0c0b | ||
|
|
b7825111bb | ||
|
|
d5691ef8f7 | ||
|
|
0213582464 | ||
|
|
396dc7f7e3 | ||
|
|
9d38525251 |
@@ -1,6 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
class UpgradeHandler : public RequestHandler {
|
class UpgradeHandler : public AsyncWebHandler {
|
||||||
public:
|
public:
|
||||||
enum class UpgradeType {
|
enum class UpgradeType {
|
||||||
FIRMWARE = 0,
|
FIRMWARE = 0,
|
||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
NO_FILE,
|
NO_FILE,
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
PROHIBITED,
|
PROHIBITED,
|
||||||
ABORTED,
|
SIZE_MISMATCH,
|
||||||
ERROR_ON_START,
|
ERROR_ON_START,
|
||||||
ERROR_ON_WRITE,
|
ERROR_ON_WRITE,
|
||||||
ERROR_ON_FINISH
|
ERROR_ON_FINISH
|
||||||
@@ -22,27 +22,21 @@ public:
|
|||||||
UpgradeType type;
|
UpgradeType type;
|
||||||
UpgradeStatus status;
|
UpgradeStatus status;
|
||||||
String error;
|
String error;
|
||||||
|
size_t progress = 0;
|
||||||
|
size_t size = 0;
|
||||||
} UpgradeResult;
|
} UpgradeResult;
|
||||||
|
|
||||||
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
|
typedef std::function<bool(AsyncWebServerRequest *request, UpgradeType)> BeforeUpgradeCallback;
|
||||||
typedef std::function<bool(const String&)> CanUploadCallback;
|
typedef std::function<void(AsyncWebServerRequest *request, const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
|
||||||
typedef std::function<bool(UpgradeType)> BeforeUpgradeCallback;
|
|
||||||
typedef std::function<void(const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
|
|
||||||
|
|
||||||
UpgradeHandler(const char* uri) {
|
UpgradeHandler(AsyncURIMatcher uri) : uri(uri) {}
|
||||||
this->uri = uri;
|
|
||||||
|
bool canHandle(AsyncWebServerRequest *request) const override final {
|
||||||
|
if (!request->isHTTP()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeHandler* setCanHandleCallback(CanHandleCallback callback = nullptr) {
|
return this->uri.matches(request);
|
||||||
this->canHandleCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpgradeHandler* setCanUploadCallback(CanUploadCallback callback = nullptr) {
|
|
||||||
this->canUploadCallback = callback;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeHandler* setBeforeUpgradeCallback(BeforeUpgradeCallback callback = nullptr) {
|
UpgradeHandler* setBeforeUpgradeCallback(BeforeUpgradeCallback callback = nullptr) {
|
||||||
@@ -57,29 +51,9 @@ public:
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
void handleRequest(AsyncWebServerRequest *request) override final {
|
||||||
bool canHandle(WebServer &server, HTTPMethod method, const String &uri) override {
|
|
||||||
return this->canHandle(method, uri);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool canHandle(HTTPMethod method, const String& uri) override {
|
|
||||||
return method == HTTP_POST && uri.equals(this->uri) && (!this->canHandleCallback || this->canHandleCallback(method, uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
bool canUpload(WebServer &server, const String &uri) override {
|
|
||||||
return this->canUpload(uri);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool canUpload(const String& uri) override {
|
|
||||||
return uri.equals(this->uri) && (!this->canUploadCallback || this->canUploadCallback(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool handle(WebServer& server, HTTPMethod method, const String& uri) override {
|
|
||||||
if (this->afterUpgradeCallback) {
|
if (this->afterUpgradeCallback) {
|
||||||
this->afterUpgradeCallback(this->firmwareResult, this->filesystemResult);
|
this->afterUpgradeCallback(request, this->firmwareResult, this->filesystemResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->firmwareResult.status = UpgradeStatus::NONE;
|
this->firmwareResult.status = UpgradeStatus::NONE;
|
||||||
@@ -87,129 +61,147 @@ public:
|
|||||||
|
|
||||||
this->filesystemResult.status = UpgradeStatus::NONE;
|
this->filesystemResult.status = UpgradeStatus::NONE;
|
||||||
this->filesystemResult.error.clear();
|
this->filesystemResult.error.clear();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void upload(WebServer& server, const String& uri, HTTPUpload& upload) override {
|
void handleUpload(AsyncWebServerRequest *request, const String &fileName, size_t index, uint8_t *data, size_t dataLength, bool isFinal) override final {
|
||||||
UpgradeResult* result;
|
UpgradeResult* result = nullptr;
|
||||||
if (upload.name.equals(F("firmware"))) {
|
|
||||||
result = &this->firmwareResult;
|
|
||||||
|
|
||||||
} else if (upload.name.equals(F("filesystem"))) {
|
if (!request->hasParam(asyncsrv::T_name, true, true)) {
|
||||||
result = &this->filesystemResult;
|
// Missing content-disposition 'name' parameter
|
||||||
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& pName = request->getParam(asyncsrv::T_name, true, true)->value();
|
||||||
|
if (pName.equals("fw")) {
|
||||||
|
result = &this->firmwareResult;
|
||||||
|
|
||||||
|
if (!index) {
|
||||||
|
result->progress = 0;
|
||||||
|
result->size = request->hasParam("fw_size", true)
|
||||||
|
? request->getParam("fw_size", true)->value().toInt()
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (pName.equals("fs")) {
|
||||||
|
result = &this->filesystemResult;
|
||||||
|
|
||||||
|
if (!index) {
|
||||||
|
result->progress = 0;
|
||||||
|
result->size = request->hasParam("fs_size", true)
|
||||||
|
? request->getParam("fs_size", true)->value().toInt()
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Unknown parameter name
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check result status
|
||||||
if (result->status != UpgradeStatus::NONE) {
|
if (result->status != UpgradeStatus::NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(result->type)) {
|
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(request, result->type)) {
|
||||||
result->status = UpgradeStatus::PROHIBITED;
|
result->status = UpgradeStatus::PROHIBITED;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!upload.filename.length()) {
|
if (!fileName.length()) {
|
||||||
result->status = UpgradeStatus::NO_FILE;
|
result->status = UpgradeStatus::NO_FILE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (upload.status == UPLOAD_FILE_START) {
|
if (!index) {
|
||||||
// reset
|
// reset
|
||||||
if (Update.isRunning()) {
|
if (Update.isRunning()) {
|
||||||
Update.end(false);
|
Update.end(false);
|
||||||
Update.clearError();
|
Update.clearError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try begin
|
||||||
bool begin = false;
|
bool begin = false;
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
Update.runAsync(true);
|
|
||||||
|
|
||||||
if (result->type == UpgradeType::FIRMWARE) {
|
|
||||||
begin = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000, U_FLASH);
|
|
||||||
|
|
||||||
} else if (result->type == UpgradeType::FILESYSTEM) {
|
|
||||||
close_all_fs();
|
|
||||||
begin = Update.begin((size_t)FS_end - (size_t)FS_start, U_FS);
|
|
||||||
}
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
|
||||||
if (result->type == UpgradeType::FIRMWARE) {
|
if (result->type == UpgradeType::FIRMWARE) {
|
||||||
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
|
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
|
||||||
|
|
||||||
} else if (result->type == UpgradeType::FILESYSTEM) {
|
} else if (result->type == UpgradeType::FILESYSTEM) {
|
||||||
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS);
|
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!begin || Update.hasError()) {
|
if (!begin || Update.hasError()) {
|
||||||
result->status = UpgradeStatus::ERROR_ON_START;
|
result->status = UpgradeStatus::ERROR_ON_START;
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
result->error = Update.getErrorString();
|
|
||||||
#else
|
|
||||||
result->error = Update.errorString();
|
result->error = Update.errorString();
|
||||||
#endif
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s', on start: %s"), upload.filename.c_str(), result->error.c_str());
|
Log.serrorln(FPSTR(L_PORTAL_OTA), "File '%s', on start: %s", fileName.c_str(), result->error.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', started"), upload.filename.c_str());
|
Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s', started", fileName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
if (dataLength) {
|
||||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
if (Update.write(data, dataLength) != dataLength) {
|
||||||
Update.end(false);
|
Update.end(false);
|
||||||
|
|
||||||
result->status = UpgradeStatus::ERROR_ON_WRITE;
|
result->status = UpgradeStatus::ERROR_ON_WRITE;
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
result->error = Update.getErrorString();
|
|
||||||
#else
|
|
||||||
result->error = Update.errorString();
|
result->error = Update.errorString();
|
||||||
#endif
|
|
||||||
|
|
||||||
Log.serrorln(
|
Log.serrorln(
|
||||||
FPSTR(L_PORTAL_OTA),
|
FPSTR(L_PORTAL_OTA), "File '%s', on write %d bytes, %d of %d bytes",
|
||||||
F("File '%s', on writing %d bytes: %s"),
|
fileName.c_str(),
|
||||||
upload.filename.c_str(), upload.totalSize, result->error.c_str()
|
dataLength,
|
||||||
|
result->progress + dataLength,
|
||||||
|
result->size
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
} else {
|
|
||||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', writed %d bytes"), upload.filename.c_str(), upload.totalSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (upload.status == UPLOAD_FILE_END) {
|
result->progress += dataLength;
|
||||||
if (Update.end(true)) {
|
Log.sinfoln(
|
||||||
result->status = UpgradeStatus::SUCCESS;
|
FPSTR(L_PORTAL_OTA), "File '%s', write %d bytes, %d of %d bytes",
|
||||||
|
fileName.c_str(),
|
||||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s': finish"), upload.filename.c_str());
|
dataLength,
|
||||||
|
result->progress,
|
||||||
} else {
|
result->size
|
||||||
result->status = UpgradeStatus::ERROR_ON_FINISH;
|
);
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
result->error = Update.getErrorString();
|
|
||||||
#else
|
|
||||||
result->error = Update.errorString();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s', on finish: %s"), upload.filename.c_str(), result->error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (upload.status == UPLOAD_FILE_ABORTED) {
|
if (result->size > 0) {
|
||||||
|
if (result->progress > result->size || (isFinal && result->progress < result->size)) {
|
||||||
Update.end(false);
|
Update.end(false);
|
||||||
result->status = UpgradeStatus::ABORTED;
|
result->status = UpgradeStatus::SIZE_MISMATCH;
|
||||||
|
|
||||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s': aborted"), upload.filename.c_str());
|
Log.serrorln(
|
||||||
|
FPSTR(L_PORTAL_OTA), "File '%s', size mismatch: %d of %d bytes",
|
||||||
|
fileName.c_str(),
|
||||||
|
result->progress,
|
||||||
|
result->size
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isFinal) {
|
||||||
|
if (!Update.end(true)) {
|
||||||
|
result->status = UpgradeStatus::ERROR_ON_FINISH;
|
||||||
|
result->error = Update.errorString();
|
||||||
|
|
||||||
|
Log.serrorln(FPSTR(L_PORTAL_OTA), "File '%s', on finish: %s", fileName.c_str(), result->error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result->status = UpgradeStatus::SUCCESS;
|
||||||
|
Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s': finish", fileName.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isRequestHandlerTrivial() const override final {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CanHandleCallback canHandleCallback;
|
|
||||||
CanUploadCallback canUploadCallback;
|
|
||||||
BeforeUpgradeCallback beforeUpgradeCallback;
|
BeforeUpgradeCallback beforeUpgradeCallback;
|
||||||
AfterUpgradeCallback afterUpgradeCallback;
|
AfterUpgradeCallback afterUpgradeCallback;
|
||||||
const char* uri = nullptr;
|
AsyncURIMatcher uri;
|
||||||
|
|
||||||
UpgradeResult firmwareResult{UpgradeType::FIRMWARE, UpgradeStatus::NONE};
|
UpgradeResult firmwareResult{UpgradeType::FIRMWARE, UpgradeStatus::NONE};
|
||||||
UpgradeResult filesystemResult{UpgradeType::FILESYSTEM, UpgradeStatus::NONE};
|
UpgradeResult filesystemResult{UpgradeType::FILESYSTEM, UpgradeStatus::NONE};
|
||||||
|
|||||||
266
platformio.ini
266
platformio.ini
@@ -1,22 +1,14 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
;extra_configs = secrets.ini
|
;extra_configs = secrets.ini
|
||||||
extra_configs = secrets.default.ini
|
extra_configs = secrets.default.ini
|
||||||
core_dir = .pio
|
core_dir = .pio
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
version = 1.5.6
|
version = 1.5.7-passiveble
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps = ESP32Async/AsyncTCP
|
||||||
|
;ESP32Async/ESPAsyncWebServer
|
||||||
|
https://github.com/ESP32Async/ESPAsyncWebServer
|
||||||
bblanchon/ArduinoJson@^7.4.2
|
bblanchon/ArduinoJson@^7.4.2
|
||||||
;ihormelnyk/OpenTherm Library@^1.1.5
|
;ihormelnyk/OpenTherm Library@^1.1.5
|
||||||
https://github.com/Laxilef/opentherm_library#esp32_timer
|
https://github.com/Laxilef/opentherm_library#esp32_timer
|
||||||
@@ -28,12 +20,15 @@ lib_deps =
|
|||||||
https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg
|
https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg
|
||||||
laxilef/TinyLogger@^1.1.1
|
laxilef/TinyLogger@^1.1.1
|
||||||
build_type = ${secrets.build_type}
|
build_type = ${secrets.build_type}
|
||||||
build_flags =
|
build_flags = -mtext-section-literals
|
||||||
-mtext-section-literals
|
-Wno-deprecated-declarations
|
||||||
-D MQTT_CLIENT_STD_FUNCTION_CALLBACK=1
|
-D MQTT_CLIENT_STD_FUNCTION_CALLBACK=1
|
||||||
;-D DEBUG_ESP_CORE -D DEBUG_ESP_WIFI -D DEBUG_ESP_HTTP_SERVER -D DEBUG_ESP_PORT=Serial
|
;-D DEBUG_ESP_CORE -D DEBUG_ESP_WIFI -D DEBUG_ESP_HTTP_SERVER -D DEBUG_ESP_PORT=Serial
|
||||||
-D BUILD_VERSION='"${this.version}"'
|
-D BUILD_VERSION='"${this.version}"'
|
||||||
-D BUILD_ENV='"$PIOENV"'
|
-D BUILD_ENV='"$PIOENV"'
|
||||||
|
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
|
||||||
|
-D ARDUINOJSON_USE_DOUBLE=0
|
||||||
|
-D ARDUINOJSON_USE_LONG_LONG=0
|
||||||
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
|
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
|
||||||
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
|
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
|
||||||
-D DEFAULT_TELNET_ENABLED=${secrets.telnet_enabled}
|
-D DEFAULT_TELNET_ENABLED=${secrets.telnet_enabled}
|
||||||
@@ -55,30 +50,23 @@ build_flags =
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
;monitor_filters = direct
|
;monitor_filters = direct
|
||||||
monitor_filters =
|
monitor_filters = esp32_exception_decoder
|
||||||
esp32_exception_decoder
|
|
||||||
esp8266_exception_decoder
|
esp8266_exception_decoder
|
||||||
board_build.flash_mode = dio
|
board_build.flash_mode = dio
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
check_tool = ;pvs-studio
|
check_tool = ;pvs-studio
|
||||||
check_flags =
|
check_flags = ;pvs-studio: --analysis-mode=4 --exclude-path=./.pio/libdeps
|
||||||
; pvs-studio:
|
|
||||||
; --analysis-mode=4
|
|
||||||
; --exclude-path=./.pio/libdeps
|
|
||||||
|
|
||||||
; Defaults
|
; Defaults
|
||||||
[esp8266_defaults]
|
[esp8266_defaults]
|
||||||
platform = espressif8266@^4.2.1
|
platform = espressif8266@^4.2.1
|
||||||
platform_packages = ${env.platform_packages}
|
platform_packages = ${env.platform_packages}
|
||||||
lib_deps =
|
lib_deps = ${env.lib_deps}
|
||||||
${env.lib_deps}
|
|
||||||
nrwiersma/ESP8266Scheduler@^1.2
|
nrwiersma/ESP8266Scheduler@^1.2
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
extra_scripts =
|
extra_scripts = post:tools/build.py
|
||||||
post:tools/build.py
|
|
||||||
build_type = ${env.build_type}
|
build_type = ${env.build_type}
|
||||||
build_flags =
|
build_flags = ${env.build_flags}
|
||||||
${env.build_flags}
|
|
||||||
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
||||||
;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
|
;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
|
||||||
-D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
-D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||||
@@ -87,25 +75,44 @@ check_tool = ${env.check_tool}
|
|||||||
check_flags = ${env.check_flags}
|
check_flags = ${env.check_flags}
|
||||||
|
|
||||||
[esp32_defaults]
|
[esp32_defaults]
|
||||||
;platform = espressif32@^6.7
|
|
||||||
;platform = https://github.com/platformio/platform-espressif32.git
|
|
||||||
;platform_packages =
|
|
||||||
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.5
|
|
||||||
; framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-lib-builder/releases/download/idf-release_v5.1/esp32-arduino-libs-idf-release_v5.1-33fbade6.zip
|
|
||||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.34/platform-espressif32.zip
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.34/platform-espressif32.zip
|
||||||
platform_packages = ${env.platform_packages}
|
platform_packages = ${env.platform_packages}
|
||||||
board_build.partitions = esp32_partitions.csv
|
board_build.partitions = esp32_partitions.csv
|
||||||
lib_deps =
|
lib_deps = ${env.lib_deps}
|
||||||
${env.lib_deps}
|
|
||||||
laxilef/ESP32Scheduler@^1.0.1
|
laxilef/ESP32Scheduler@^1.0.1
|
||||||
nimble_lib = h2zero/NimBLE-Arduino@2.3.3
|
nimble_lib = https://github.com/h2zero/NimBLE-Arduino
|
||||||
lib_ignore =
|
lib_ignore = BluetoothSerial
|
||||||
extra_scripts =
|
SimpleBLE
|
||||||
post:tools/esp32.py
|
ESP RainMaker
|
||||||
|
RainMaker
|
||||||
|
ESP Insights
|
||||||
|
Insights
|
||||||
|
Zigbee
|
||||||
|
Matter
|
||||||
|
OpenThread
|
||||||
|
dsp
|
||||||
|
custom_component_remove = espressif/esp_hosted
|
||||||
|
espressif/esp_wifi_remote
|
||||||
|
espressif/esp-dsp
|
||||||
|
espressif/esp_modem
|
||||||
|
espressif/esp_rainmaker
|
||||||
|
espressif/rmaker_common
|
||||||
|
espressif/esp_insights
|
||||||
|
espressif/esp_diag_data_store
|
||||||
|
espressif/esp_diagnostics
|
||||||
|
espressif/libsodium
|
||||||
|
espressif/esp-modbus
|
||||||
|
espressif/esp-cbor
|
||||||
|
espressif/esp-sr
|
||||||
|
espressif/esp32-camera
|
||||||
|
espressif/qrcode
|
||||||
|
espressif/esp-zboss-lib
|
||||||
|
espressif/esp-zigbee-lib
|
||||||
|
chmorgan/esp-libhelix-mp3
|
||||||
|
extra_scripts = post:tools/esp32.py
|
||||||
post:tools/build.py
|
post:tools/build.py
|
||||||
build_type = ${env.build_type}
|
build_type = ${env.build_type}
|
||||||
build_flags =
|
build_flags = ${env.build_flags}
|
||||||
${env.build_flags}
|
|
||||||
-D CORE_DEBUG_LEVEL=0
|
-D CORE_DEBUG_LEVEL=0
|
||||||
-Wl,--wrap=esp_panic_handler
|
-Wl,--wrap=esp_panic_handler
|
||||||
check_tool = ${env.check_tool}
|
check_tool = ${env.check_tool}
|
||||||
@@ -114,98 +121,54 @@ check_flags = ${env.check_flags}
|
|||||||
|
|
||||||
; Boards
|
; Boards
|
||||||
[env:d1_mini]
|
[env:d1_mini]
|
||||||
platform = ${esp8266_defaults.platform}
|
extends = esp8266_defaults
|
||||||
platform_packages = ${esp8266_defaults.platform_packages}
|
|
||||||
board = d1_mini
|
board = d1_mini
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
build_flags = ${esp8266_defaults.build_flags}
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_type = ${esp8266_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=4
|
-D DEFAULT_OT_IN_GPIO=4
|
||||||
-D DEFAULT_OT_OUT_GPIO=5
|
-D DEFAULT_OT_OUT_GPIO=5
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||||
-D DEFAULT_STATUS_LED_GPIO=13
|
-D DEFAULT_STATUS_LED_GPIO=13
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||||
check_tool = ${esp8266_defaults.check_tool}
|
|
||||||
check_flags = ${esp8266_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:d1_mini_lite]
|
[env:d1_mini_lite]
|
||||||
platform = ${esp8266_defaults.platform}
|
extends = esp8266_defaults
|
||||||
platform_packages = ${esp8266_defaults.platform_packages}
|
|
||||||
board = d1_mini_lite
|
board = d1_mini_lite
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
build_flags = ${esp8266_defaults.build_flags}
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_type = ${esp8266_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=4
|
-D DEFAULT_OT_IN_GPIO=4
|
||||||
-D DEFAULT_OT_OUT_GPIO=5
|
-D DEFAULT_OT_OUT_GPIO=5
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||||
-D DEFAULT_STATUS_LED_GPIO=13
|
-D DEFAULT_STATUS_LED_GPIO=13
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||||
check_tool = ${esp8266_defaults.check_tool}
|
|
||||||
check_flags = ${esp8266_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:d1_mini_pro]
|
[env:d1_mini_pro]
|
||||||
platform = ${esp8266_defaults.platform}
|
extends = esp8266_defaults
|
||||||
platform_packages = ${esp8266_defaults.platform_packages}
|
|
||||||
board = d1_mini_pro
|
board = d1_mini_pro
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
build_flags = ${esp8266_defaults.build_flags}
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_type = ${esp8266_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=4
|
-D DEFAULT_OT_IN_GPIO=4
|
||||||
-D DEFAULT_OT_OUT_GPIO=5
|
-D DEFAULT_OT_OUT_GPIO=5
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||||
-D DEFAULT_STATUS_LED_GPIO=13
|
-D DEFAULT_STATUS_LED_GPIO=13
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||||
check_tool = ${esp8266_defaults.check_tool}
|
|
||||||
check_flags = ${esp8266_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:nodemcu_8266]
|
[env:nodemcu_8266]
|
||||||
platform = ${esp8266_defaults.platform}
|
extends = esp8266_defaults
|
||||||
platform_packages = ${esp8266_defaults.platform_packages}
|
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
lib_deps = ${esp8266_defaults.lib_deps}
|
build_flags = ${esp8266_defaults.build_flags}
|
||||||
lib_ignore = ${esp8266_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp8266_defaults.extra_scripts}
|
|
||||||
board_build.ldscript = ${esp8266_defaults.board_build.ldscript}
|
|
||||||
build_type = ${esp8266_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp8266_defaults.build_flags}
|
|
||||||
-D DEFAULT_OT_IN_GPIO=13
|
-D DEFAULT_OT_IN_GPIO=13
|
||||||
-D DEFAULT_OT_OUT_GPIO=15
|
-D DEFAULT_OT_OUT_GPIO=15
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=4
|
-D DEFAULT_SENSOR_INDOOR_GPIO=4
|
||||||
-D DEFAULT_STATUS_LED_GPIO=2
|
-D DEFAULT_STATUS_LED_GPIO=2
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=16
|
-D DEFAULT_OT_RX_LED_GPIO=16
|
||||||
check_tool = ${esp8266_defaults.check_tool}
|
|
||||||
check_flags = ${esp8266_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:s2_mini]
|
[env:s2_mini]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = lolin_s2_mini
|
board = lolin_s2_mini
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
build_unflags = -DARDUINO_USB_MODE=1
|
||||||
lib_deps = ${esp32_defaults.lib_deps}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_unflags =
|
|
||||||
-DARDUINO_USB_MODE=1
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D ARDUINO_USB_MODE=0
|
-D ARDUINO_USB_MODE=0
|
||||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||||
-D DEFAULT_OT_IN_GPIO=33
|
-D DEFAULT_OT_IN_GPIO=33
|
||||||
@@ -214,53 +177,32 @@ build_flags =
|
|||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=7
|
-D DEFAULT_SENSOR_INDOOR_GPIO=7
|
||||||
-D DEFAULT_STATUS_LED_GPIO=11
|
-D DEFAULT_STATUS_LED_GPIO=11
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=12
|
-D DEFAULT_OT_RX_LED_GPIO=12
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:s3_mini]
|
[env:s3_mini]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = lolin_s3_mini
|
board = lolin_s3_mini
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
lib_deps = ${esp32_defaults.lib_deps}
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
${esp32_defaults.nimble_lib}
|
${esp32_defaults.nimble_lib}
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
build_unflags = -DARDUINO_USB_MODE=1
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
build_unflags =
|
|
||||||
-DARDUINO_USB_MODE=1
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D ARDUINO_USB_MODE=0
|
-D ARDUINO_USB_MODE=0
|
||||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||||
-D CONFIG_BT_NIMBLE_EXT_ADV=1
|
|
||||||
-D USE_BLE=1
|
-D USE_BLE=1
|
||||||
|
-D MYNEWT_VAL_BLE_EXT_ADV=1
|
||||||
-D DEFAULT_OT_IN_GPIO=35
|
-D DEFAULT_OT_IN_GPIO=35
|
||||||
-D DEFAULT_OT_OUT_GPIO=36
|
-D DEFAULT_OT_OUT_GPIO=36
|
||||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
|
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
|
||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=12
|
-D DEFAULT_SENSOR_INDOOR_GPIO=12
|
||||||
-D DEFAULT_STATUS_LED_GPIO=11
|
-D DEFAULT_STATUS_LED_GPIO=11
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=10
|
-D DEFAULT_OT_RX_LED_GPIO=10
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:c3_mini]
|
[env:c3_mini]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = lolin_c3_mini
|
board = lolin_c3_mini
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
lib_deps = ${esp32_defaults.lib_deps}
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
${esp32_defaults.nimble_lib}
|
${esp32_defaults.nimble_lib}
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
build_unflags = -mtext-section-literals
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
build_unflags =
|
|
||||||
-mtext-section-literals
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D CONFIG_BT_NIMBLE_EXT_ADV=1
|
|
||||||
-D USE_BLE=1
|
-D USE_BLE=1
|
||||||
-D DEFAULT_OT_IN_GPIO=8
|
-D DEFAULT_OT_IN_GPIO=8
|
||||||
-D DEFAULT_OT_OUT_GPIO=10
|
-D DEFAULT_OT_OUT_GPIO=10
|
||||||
@@ -268,22 +210,13 @@ build_flags =
|
|||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=1
|
-D DEFAULT_SENSOR_INDOOR_GPIO=1
|
||||||
-D DEFAULT_STATUS_LED_GPIO=4
|
-D DEFAULT_STATUS_LED_GPIO=4
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=5
|
-D DEFAULT_OT_RX_LED_GPIO=5
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:nodemcu_32]
|
[env:nodemcu_32]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = nodemcu-32s
|
board = nodemcu-32s
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
lib_deps = ${esp32_defaults.lib_deps}
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
${esp32_defaults.nimble_lib}
|
${esp32_defaults.nimble_lib}
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
-D USE_BLE=1
|
||||||
-D DEFAULT_OT_IN_GPIO=16
|
-D DEFAULT_OT_IN_GPIO=16
|
||||||
-D DEFAULT_OT_OUT_GPIO=4
|
-D DEFAULT_OT_OUT_GPIO=4
|
||||||
@@ -291,26 +224,17 @@ build_flags =
|
|||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=26
|
-D DEFAULT_SENSOR_INDOOR_GPIO=26
|
||||||
-D DEFAULT_STATUS_LED_GPIO=2
|
-D DEFAULT_STATUS_LED_GPIO=2
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=19
|
-D DEFAULT_OT_RX_LED_GPIO=19
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:nodemcu_32_160mhz]
|
[env:nodemcu_32_160mhz]
|
||||||
extends = env:nodemcu_32
|
extends = env:nodemcu_32
|
||||||
board_build.f_cpu = 160000000L ; set frequency to 160MHz
|
board_build.f_cpu = 160000000L ; set frequency to 160MHz
|
||||||
|
|
||||||
[env:d1_mini32]
|
[env:d1_mini32]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = wemos_d1_mini32
|
board = wemos_d1_mini32
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
lib_deps = ${esp32_defaults.lib_deps}
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
${esp32_defaults.nimble_lib}
|
${esp32_defaults.nimble_lib}
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
-D USE_BLE=1
|
||||||
-D DEFAULT_OT_IN_GPIO=21
|
-D DEFAULT_OT_IN_GPIO=21
|
||||||
-D DEFAULT_OT_OUT_GPIO=22
|
-D DEFAULT_OT_OUT_GPIO=22
|
||||||
@@ -318,29 +242,14 @@ build_flags =
|
|||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=18
|
-D DEFAULT_SENSOR_INDOOR_GPIO=18
|
||||||
-D DEFAULT_STATUS_LED_GPIO=2
|
-D DEFAULT_STATUS_LED_GPIO=2
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=19
|
-D DEFAULT_OT_RX_LED_GPIO=19
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:esp32_c6]
|
[env:esp32_c6]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
framework = arduino, espidf
|
board = esp32-c6-devkitc-1
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = esp32-c6-devkitm-1
|
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
|
||||||
board_build.embed_txtfiles =
|
|
||||||
managed_components/espressif__esp_insights/server_certs/https_server.crt
|
|
||||||
managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt
|
|
||||||
managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt
|
|
||||||
managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt
|
|
||||||
lib_deps = ${esp32_defaults.lib_deps}
|
lib_deps = ${esp32_defaults.lib_deps}
|
||||||
lib_ignore =
|
${esp32_defaults.nimble_lib}
|
||||||
${esp32_defaults.lib_ignore}
|
build_unflags = -mtext-section-literals
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
build_unflags =
|
|
||||||
-mtext-section-literals
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D USE_BLE=1
|
-D USE_BLE=1
|
||||||
-D DEFAULT_OT_IN_GPIO=15
|
-D DEFAULT_OT_IN_GPIO=15
|
||||||
-D DEFAULT_OT_OUT_GPIO=23
|
-D DEFAULT_OT_OUT_GPIO=23
|
||||||
@@ -348,25 +257,14 @@ build_flags =
|
|||||||
-D DEFAULT_SENSOR_INDOOR_GPIO=0
|
-D DEFAULT_SENSOR_INDOOR_GPIO=0
|
||||||
-D DEFAULT_STATUS_LED_GPIO=11
|
-D DEFAULT_STATUS_LED_GPIO=11
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=10
|
-D DEFAULT_OT_RX_LED_GPIO=10
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|
||||||
[env:otthing]
|
[env:otthing]
|
||||||
platform = ${esp32_defaults.platform}
|
extends = esp32_defaults
|
||||||
platform_packages = ${esp32_defaults.platform_packages}
|
|
||||||
board = lolin_c3_mini
|
board = lolin_c3_mini
|
||||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
lib_deps = ${esp32_defaults.lib_deps}
|
||||||
lib_deps =
|
|
||||||
${esp32_defaults.lib_deps}
|
|
||||||
${esp32_defaults.nimble_lib}
|
${esp32_defaults.nimble_lib}
|
||||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
build_unflags = -mtext-section-literals
|
||||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
build_flags = ${esp32_defaults.build_flags}
|
||||||
build_unflags =
|
|
||||||
-mtext-section-literals
|
|
||||||
build_type = ${esp32_defaults.build_type}
|
|
||||||
build_flags =
|
|
||||||
${esp32_defaults.build_flags}
|
|
||||||
-D CONFIG_BT_NIMBLE_EXT_ADV=1
|
|
||||||
-D USE_BLE=1
|
-D USE_BLE=1
|
||||||
-D DEFAULT_OT_IN_GPIO=3
|
-D DEFAULT_OT_IN_GPIO=3
|
||||||
-D DEFAULT_OT_OUT_GPIO=1
|
-D DEFAULT_OT_OUT_GPIO=1
|
||||||
@@ -375,5 +273,3 @@ build_flags =
|
|||||||
-D DEFAULT_STATUS_LED_GPIO=8
|
-D DEFAULT_STATUS_LED_GPIO=8
|
||||||
-D DEFAULT_OT_RX_LED_GPIO=2
|
-D DEFAULT_OT_RX_LED_GPIO=2
|
||||||
-D OT_BYPASS_RELAY_GPIO=20
|
-D OT_BYPASS_RELAY_GPIO=20
|
||||||
check_tool = ${esp32_defaults.check_tool}
|
|
||||||
check_flags = ${esp32_defaults.check_flags}
|
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ protected:
|
|||||||
return "Main";
|
return "Main";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getTaskStackSize() override {
|
||||||
|
return 6000;
|
||||||
|
}
|
||||||
|
|
||||||
/*BaseType_t getTaskCore() override {
|
/*BaseType_t getTaskCore() override {
|
||||||
return 1;
|
return 1;
|
||||||
}*/
|
}*/
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ protected:
|
|||||||
return "OpenTherm";
|
return "OpenTherm";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getTaskStackSize() override {
|
||||||
|
return 7500;
|
||||||
|
}
|
||||||
|
|
||||||
BaseType_t getTaskCore() override {
|
BaseType_t getTaskCore() override {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
817
src/PortalTask.h
817
src/PortalTask.h
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,10 @@ protected:
|
|||||||
return "Regulator";
|
return "Regulator";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getTaskStackSize() override {
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
/*BaseType_t getTaskCore() override {
|
/*BaseType_t getTaskCore() override {
|
||||||
return 1;
|
return 1;
|
||||||
}*/
|
}*/
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ public:
|
|||||||
|
|
||||||
static int16_t getIdByName(const char* name) {
|
static int16_t getIdByName(const char* name) {
|
||||||
if (settings == nullptr) {
|
if (settings == nullptr) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t id = 0; id <= getMaxSensorId(); id++) {
|
for (uint8_t id = 0; id <= getMaxSensorId(); id++) {
|
||||||
@@ -163,7 +163,7 @@ public:
|
|||||||
|
|
||||||
static int16_t getIdByObjectId(const char* objectId) {
|
static int16_t getIdByObjectId(const char* objectId) {
|
||||||
if (settings == nullptr) {
|
if (settings == nullptr) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String refObjectId;
|
String refObjectId;
|
||||||
|
|||||||
@@ -9,41 +9,136 @@
|
|||||||
extern FileData fsSensorsSettings;
|
extern FileData fsSensorsSettings;
|
||||||
|
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
class BluetoothClientCallbacks : public NimBLEClientCallbacks {
|
class BluetoothScanCallbacks : public NimBLEScanCallbacks {
|
||||||
public:
|
public:
|
||||||
BluetoothClientCallbacks(uint8_t sensorId) : sensorId(sensorId) {}
|
void onDiscovered(const NimBLEAdvertisedDevice* device) override {
|
||||||
|
auto& deviceAddress = device->getAddress();
|
||||||
|
|
||||||
void onConnect(NimBLEClient* pClient) {
|
bool found = false;
|
||||||
auto& sSensor = Sensors::settings[this->sensorId];
|
|
||||||
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': connected to %s"),
|
|
||||||
sensorId, sSensor.name, pClient->getPeerAddress().toString().c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onDisconnect(NimBLEClient* pClient, int reason) {
|
|
||||||
auto& sSensor = Sensors::settings[this->sensorId];
|
|
||||||
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': disconnected, reason %i"),
|
|
||||||
sensorId, sSensor.name, reason
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onConnectFail(NimBLEClient* pClient, int reason) {
|
|
||||||
auto& sSensor = Sensors::settings[this->sensorId];
|
|
||||||
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to connect, reason %i"),
|
|
||||||
sensorId, sSensor.name, reason
|
|
||||||
);
|
|
||||||
|
|
||||||
pClient->cancelConnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint8_t sensorId;
|
uint8_t sensorId;
|
||||||
|
for (sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
||||||
|
auto& sSensor = Sensors::settings[sensorId];
|
||||||
|
if (!sSensor.enabled || sSensor.type != Sensors::Type::BLUETOOTH || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto sensorAddress = NimBLEAddress(sSensor.address, deviceAddress.getType());
|
||||||
|
if (sensorAddress.isNull() || sensorAddress != deviceAddress) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& sSensor = Sensors::settings[sensorId];
|
||||||
|
auto& rSensor = Sensors::results[sensorId];
|
||||||
|
auto deviceName = device->getName();
|
||||||
|
auto deviceRssi = device->getRSSI();
|
||||||
|
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': discovered device %s, name: %s, RSSI: %hhd"),
|
||||||
|
sensorId, sSensor.name,
|
||||||
|
deviceAddress.toString().c_str(), deviceName.c_str(), deviceRssi
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!device->haveServiceData()) {
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found service data"),
|
||||||
|
sensorId, sSensor.name
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto serviceDataCount = device->getServiceDataCount();
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found %hhu service data"),
|
||||||
|
sensorId, sSensor.name, serviceDataCount
|
||||||
|
);
|
||||||
|
|
||||||
|
NimBLEUUID serviceUuid((uint16_t) 0x181A);
|
||||||
|
auto serviceData = device->getServiceData(serviceUuid);
|
||||||
|
if (!serviceData.size()) {
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': NOT found %s env service data"),
|
||||||
|
sensorId, sSensor.name, serviceUuid.toString().c_str()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found %s env service data"),
|
||||||
|
sensorId, sSensor.name, serviceUuid.toString().c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
float temperature, humidity;
|
||||||
|
uint16_t batteryMv;
|
||||||
|
uint8_t batteryLevel;
|
||||||
|
|
||||||
|
if (serviceData.size() == 13) {
|
||||||
|
// atc1441 format
|
||||||
|
|
||||||
|
// Temperature (2 bytes, big-endian)
|
||||||
|
temperature = (
|
||||||
|
(static_cast<uint8_t>(serviceData[6]) << 8) | static_cast<uint8_t>(serviceData[7])
|
||||||
|
) * 0.1f;
|
||||||
|
|
||||||
|
// Humidity (1 byte)
|
||||||
|
humidity = static_cast<uint8_t>(serviceData[8]);
|
||||||
|
|
||||||
|
// Battery mV (2 bytes, big-endian)
|
||||||
|
batteryMv = (static_cast<uint8_t>(serviceData[10]) << 8) | static_cast<uint8_t>(serviceData[11]);
|
||||||
|
|
||||||
|
// Battery level (1 byte)
|
||||||
|
batteryLevel = static_cast<uint8_t>(serviceData[9]);
|
||||||
|
|
||||||
|
} else if (serviceData.size() == 15) {
|
||||||
|
// custom pvvx format
|
||||||
|
|
||||||
|
// Temperature (2 bytes, little-endian)
|
||||||
|
temperature = (
|
||||||
|
(static_cast<uint8_t>(serviceData[7]) << 8) | static_cast<uint8_t>(serviceData[6])
|
||||||
|
) * 0.01f;
|
||||||
|
|
||||||
|
// Humidity (2 bytes, little-endian)
|
||||||
|
humidity = (
|
||||||
|
(static_cast<uint8_t>(serviceData[9]) << 8) | static_cast<uint8_t>(serviceData[8])
|
||||||
|
) * 0.01f;
|
||||||
|
|
||||||
|
// Battery mV (2 bytes, little-endian)
|
||||||
|
batteryMv = (static_cast<uint8_t>(serviceData[11]) << 8) | static_cast<uint8_t>(serviceData[10]);
|
||||||
|
|
||||||
|
// Battery level (1 byte)
|
||||||
|
batteryLevel = static_cast<uint8_t>(serviceData[12]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// unknown format
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': unknown data format (size: %i)"),
|
||||||
|
sensorId, sSensor.name, serviceData.size()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.straceln(
|
||||||
|
FPSTR(L_SENSORS_BLE),
|
||||||
|
F("Sensor #%hhu '%s', received temp: %.2f; humidity: %.2f, battery voltage: %hu, battery level: %hhu"),
|
||||||
|
sensorId, sSensor.name,
|
||||||
|
temperature, humidity, batteryMv, batteryLevel
|
||||||
|
);
|
||||||
|
|
||||||
|
// update data
|
||||||
|
Sensors::setValueById(sensorId, temperature, Sensors::ValueType::TEMPERATURE, true, true);
|
||||||
|
Sensors::setValueById(sensorId, humidity, Sensors::ValueType::HUMIDITY, true, true);
|
||||||
|
Sensors::setValueById(sensorId, batteryLevel, Sensors::ValueType::BATTERY, true, true);
|
||||||
|
|
||||||
|
// update rssi
|
||||||
|
Sensors::setValueById(sensorId, deviceRssi, Sensors::ValueType::RSSI, false, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -55,6 +150,10 @@ public:
|
|||||||
this->dallasSearchTime.reserve(2);
|
this->dallasSearchTime.reserve(2);
|
||||||
this->dallasPolling.reserve(2);
|
this->dallasPolling.reserve(2);
|
||||||
this->dallasLastPollingTime.reserve(2);
|
this->dallasLastPollingTime.reserve(2);
|
||||||
|
|
||||||
|
#if USE_BLE
|
||||||
|
this->pBLEScanCallbacks = new BluetoothScanCallbacks();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~SensorsTask() {
|
~SensorsTask() {
|
||||||
@@ -63,16 +162,17 @@ public:
|
|||||||
this->dallasSearchTime.clear();
|
this->dallasSearchTime.clear();
|
||||||
this->dallasPolling.clear();
|
this->dallasPolling.clear();
|
||||||
this->dallasLastPollingTime.clear();
|
this->dallasLastPollingTime.clear();
|
||||||
|
|
||||||
|
#if USE_BLE
|
||||||
|
delete this->pBLEScanCallbacks;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const unsigned int disconnectedTimeout = 120000;
|
const unsigned int disconnectedTimeout = 180000u;
|
||||||
const unsigned short dallasSearchInterval = 60000;
|
const unsigned short dallasSearchInterval = 60000u;
|
||||||
const unsigned short dallasPollingInterval = 10000;
|
const unsigned short dallasPollingInterval = 10000u;
|
||||||
const unsigned short globalPollingInterval = 15000;
|
const unsigned short globalPollingInterval = 15000u;
|
||||||
#if USE_BLE
|
|
||||||
const unsigned int bleSetDtInterval = 7200000;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::unordered_map<uint8_t, OneWire> owInstances;
|
std::unordered_map<uint8_t, OneWire> owInstances;
|
||||||
std::unordered_map<uint8_t, DallasTemperature> dallasInstances;
|
std::unordered_map<uint8_t, DallasTemperature> dallasInstances;
|
||||||
@@ -80,9 +180,9 @@ protected:
|
|||||||
std::unordered_map<uint8_t, bool> dallasPolling;
|
std::unordered_map<uint8_t, bool> dallasPolling;
|
||||||
std::unordered_map<uint8_t, unsigned long> dallasLastPollingTime;
|
std::unordered_map<uint8_t, unsigned long> dallasLastPollingTime;
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
std::unordered_map<uint8_t, NimBLEClient*> bleClients;
|
NimBLEScan* pBLEScan = nullptr;
|
||||||
std::unordered_map<uint8_t, bool> bleSubscribed;
|
BluetoothScanCallbacks* pBLEScanCallbacks = nullptr;
|
||||||
std::unordered_map<uint8_t, unsigned long> bleLastSetDtTime;
|
bool activeScanBle = false;
|
||||||
#endif
|
#endif
|
||||||
unsigned long globalLastPollingTime = 0;
|
unsigned long globalLastPollingTime = 0;
|
||||||
|
|
||||||
@@ -91,6 +191,10 @@ protected:
|
|||||||
return "Sensors";
|
return "Sensors";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getTaskStackSize() override {
|
||||||
|
return 7500;
|
||||||
|
}
|
||||||
|
|
||||||
BaseType_t getTaskCore() override {
|
BaseType_t getTaskCore() override {
|
||||||
// https://github.com/h2zero/NimBLE-Arduino/issues/676
|
// https://github.com/h2zero/NimBLE-Arduino/issues/676
|
||||||
#if USE_BLE && defined(CONFIG_BT_NIMBLE_PINNED_TO_CORE)
|
#if USE_BLE && defined(CONFIG_BT_NIMBLE_PINNED_TO_CORE)
|
||||||
@@ -131,8 +235,7 @@ protected:
|
|||||||
this->yield();
|
this->yield();
|
||||||
|
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
cleanBleInstances();
|
scanBleSensors();
|
||||||
pollingBleSensors();
|
|
||||||
this->yield();
|
this->yield();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -444,550 +547,72 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
void cleanBleInstances() {
|
void scanBleSensors() {
|
||||||
if (!NimBLEDevice::isInitialized()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& [sensorId, pClient]: this->bleClients) {
|
|
||||||
if (pClient == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
const auto sAddress = NimBLEAddress(sSensor.address, 0);
|
|
||||||
|
|
||||||
if (sAddress.isNull() || !sSensor.enabled || sSensor.type != Sensors::Type::BLUETOOTH || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s', deleted unused client"),
|
|
||||||
sensorId, sSensor.name
|
|
||||||
);
|
|
||||||
|
|
||||||
NimBLEDevice::deleteClient(pClient);
|
|
||||||
pClient = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pollingBleSensors() {
|
|
||||||
if (!Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true)) {
|
if (!Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true)) {
|
||||||
|
if (NimBLEDevice::isInitialized()) {
|
||||||
|
if (this->pBLEScan != nullptr) {
|
||||||
|
if (this->pBLEScan->isScanning()) {
|
||||||
|
this->pBLEScan->stop();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this->pBLEScan = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->pBLEScan == nullptr) {
|
||||||
|
if (NimBLEDevice::deinit(true)) {
|
||||||
|
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Deinitialized"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.swarningln(FPSTR(L_SENSORS_BLE), F("Unable to deinitialize!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NimBLEDevice::isInitialized() && millis() > 5000) {
|
if (!NimBLEDevice::isInitialized() && millis() > 5000) {
|
||||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Initialized"));
|
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Initialized"));
|
||||||
BLEDevice::init("");
|
NimBLEDevice::init("");
|
||||||
NimBLEDevice::setPower(9);
|
|
||||||
|
#ifdef ESP_PWR_LVL_P20
|
||||||
|
NimBLEDevice::setPower(ESP_PWR_LVL_P20);
|
||||||
|
#elifdef ESP_PWR_LVL_P9
|
||||||
|
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) {
|
if (this->pBLEScan == nullptr) {
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
this->pBLEScan = NimBLEDevice::getScan();
|
||||||
auto& rSensor = Sensors::results[sensorId];
|
this->pBLEScan->setScanCallbacks(this->pBLEScanCallbacks);
|
||||||
|
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||||
|
this->pBLEScan->setPhy(NimBLEScan::Phy::SCAN_ALL);
|
||||||
|
#endif
|
||||||
|
this->pBLEScan->setDuplicateFilter(false);
|
||||||
|
this->pBLEScan->setMaxResults(0);
|
||||||
|
this->pBLEScan->setInterval(10000);
|
||||||
|
this->pBLEScan->setWindow(10000);
|
||||||
|
|
||||||
if (!sSensor.enabled || sSensor.type != Sensors::Type::BLUETOOTH || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Scanning initialized"));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto address = NimBLEAddress(sSensor.address, 0);
|
if (!this->pBLEScan->isScanning()) {
|
||||||
if (address.isNull()) {
|
this->activeScanBle = !this->activeScanBle;
|
||||||
continue;
|
this->pBLEScan->setActiveScan(this->activeScanBle);
|
||||||
}
|
|
||||||
|
|
||||||
auto pClient = this->getBleClient(sensorId);
|
if (this->pBLEScan->start(30000, false, false)) {
|
||||||
if (pClient == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pClient->getPeerAddress() != address) {
|
|
||||||
if (pClient->isConnected()) {
|
|
||||||
if (!pClient->disconnect()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pClient->setPeerAddress(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pClient->isConnected()) {
|
|
||||||
this->bleSubscribed[sensorId] = false;
|
|
||||||
this->bleLastSetDtTime[sensorId] = 0;
|
|
||||||
|
|
||||||
if (pClient->connect(false, true, true)) {
|
|
||||||
Log.sinfoln(
|
Log.sinfoln(
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': trying connecting to %s..."),
|
FPSTR(L_SENSORS_BLE),
|
||||||
sensorId, sSensor.name, pClient->getPeerAddress().toString().c_str()
|
F("%s scanning started"),
|
||||||
);
|
this->activeScanBle ? "Active" : "Passive"
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->bleSubscribed[sensorId]) {
|
|
||||||
if (this->subscribeToBleDevice(sensorId, pClient)) {
|
|
||||||
this->bleSubscribed[sensorId] = true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->bleSubscribed[sensorId] = false;
|
|
||||||
pClient->disconnect();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark connected
|
|
||||||
Sensors::setConnectionStatusById(sensorId, true, true);
|
|
||||||
|
|
||||||
if (!this->bleLastSetDtTime[sensorId] || millis() - this->bleLastSetDtTime[sensorId] > this->bleSetDtInterval) {
|
|
||||||
struct tm ti;
|
|
||||||
|
|
||||||
if (getLocalTime(&ti)) {
|
|
||||||
if (this->setDateOnBleSensor(pClient, &ti)) {
|
|
||||||
Log.sinfoln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s', successfully set date: %02d.%02d.%04d %02d:%02d:%02d"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
ti.tm_mday, ti.tm_mon + 1, ti.tm_year + 1900, ti.tm_hour, ti.tm_min, ti.tm_sec
|
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.swarningln(
|
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Unable to start scanning"));
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s', failed set date: %02d.%02d.%04d %02d:%02d:%02d"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
ti.tm_mday, ti.tm_mon + 1, ti.tm_year + 1900, ti.tm_hour, ti.tm_min, ti.tm_sec
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->bleLastSetDtTime[sensorId] = millis();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
NimBLEClient* getBleClient(const uint8_t sensorId) {
|
|
||||||
if (!NimBLEDevice::isInitialized()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
auto& rSensor = Sensors::results[sensorId];
|
|
||||||
|
|
||||||
if (!sSensor.enabled || sSensor.type != Sensors::Type::BLUETOOTH || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->bleClients[sensorId] && this->bleClients[sensorId] != nullptr) {
|
|
||||||
return this->bleClients[sensorId];
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pClient = NimBLEDevice::createClient();
|
|
||||||
if (pClient == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//pClient->setConnectionParams(BLE_GAP_CONN_ITVL_MS(10), BLE_GAP_CONN_ITVL_MS(100), 10, 150);
|
|
||||||
pClient->setConnectTimeout(30000);
|
|
||||||
pClient->setSelfDelete(false, false);
|
|
||||||
pClient->setClientCallbacks(new BluetoothClientCallbacks(sensorId), true);
|
|
||||||
|
|
||||||
this->bleClients[sensorId] = pClient;
|
|
||||||
|
|
||||||
return pClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool subscribeToBleDevice(const uint8_t sensorId, NimBLEClient* pClient) {
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
auto pAddress = pClient->getPeerAddress().toString();
|
|
||||||
|
|
||||||
NimBLERemoteService* pService = nullptr;
|
|
||||||
NimBLERemoteCharacteristic* pChar = nullptr;
|
|
||||||
|
|
||||||
// ENV Service (0x181A)
|
|
||||||
NimBLEUUID serviceUuid((uint16_t) 0x181AU);
|
|
||||||
pService = pClient->getService(serviceUuid);
|
|
||||||
if (!pService) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to find env service (%s) on device %s"),
|
|
||||||
sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found env service (%s) on device %s"),
|
|
||||||
sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 0x2A6E - Notify temperature x0.01C (pvvx)
|
|
||||||
bool tempNotifyCreated = false;
|
|
||||||
if (!tempNotifyCreated) {
|
|
||||||
NimBLEUUID charUuid((uint16_t) 0x2A6E);
|
|
||||||
pChar = pService->getCharacteristic(charUuid);
|
|
||||||
|
|
||||||
if (pChar && (pChar->canNotify() || pChar->canIndicate())) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found temp char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
pChar->unsubscribe();
|
|
||||||
tempNotifyCreated = pChar->subscribe(
|
|
||||||
pChar->canNotify(),
|
|
||||||
[sensorId](NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) {
|
|
||||||
if (pChar == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NimBLERemoteService* pService = pChar->getRemoteService();
|
|
||||||
if (pService == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NimBLEClient* pClient = pService->getClient();
|
|
||||||
if (pClient == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
|
|
||||||
if (length != 2) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': invalid notification data at temp char (%s) on device %s"),
|
|
||||||
sensorId,
|
|
||||||
sSensor.name,
|
|
||||||
pChar->getUUID().toString().c_str(),
|
|
||||||
pClient->getPeerAddress().toString().c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawTemp = (pChar->getValue<int16_t>() * 0.01f);
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': received temp: %.2f"),
|
|
||||||
sensorId, sSensor.name, rawTemp
|
|
||||||
);
|
|
||||||
|
|
||||||
// set temp
|
|
||||||
Sensors::setValueById(sensorId, rawTemp, Sensors::ValueType::TEMPERATURE, true, true);
|
|
||||||
|
|
||||||
// update rssi
|
|
||||||
Sensors::setValueById(sensorId, pClient->getRssi(), Sensors::ValueType::RSSI, false, false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (tempNotifyCreated) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to temp char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to temp char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 0x2A1F - Notify temperature x0.1C (atc1441/pvvx)
|
|
||||||
if (!tempNotifyCreated) {
|
|
||||||
NimBLEUUID charUuid((uint16_t) 0x2A1F);
|
|
||||||
pChar = pService->getCharacteristic(charUuid);
|
|
||||||
|
|
||||||
if (pChar && (pChar->canNotify() || pChar->canIndicate())) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found temp char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
pChar->unsubscribe();
|
|
||||||
tempNotifyCreated = pChar->subscribe(
|
|
||||||
pChar->canNotify(),
|
|
||||||
[sensorId](NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) {
|
|
||||||
if (pChar == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NimBLERemoteService* pService = pChar->getRemoteService();
|
|
||||||
if (pService == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NimBLEClient* pClient = pService->getClient();
|
|
||||||
if (pClient == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
|
|
||||||
if (length != 2) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': invalid notification data at temp char (%s) on device %s"),
|
|
||||||
sensorId,
|
|
||||||
sSensor.name,
|
|
||||||
pChar->getUUID().toString().c_str(),
|
|
||||||
pClient->getPeerAddress().toString().c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawTemp = (pChar->getValue<int16_t>() * 0.1f);
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': received temp: %.2f"),
|
|
||||||
sensorId, sSensor.name, rawTemp
|
|
||||||
);
|
|
||||||
|
|
||||||
// set temp
|
|
||||||
Sensors::setValueById(sensorId, rawTemp, Sensors::ValueType::TEMPERATURE, true, true);
|
|
||||||
|
|
||||||
// update rssi
|
|
||||||
Sensors::setValueById(sensorId, pClient->getRssi(), Sensors::ValueType::RSSI, false, false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (tempNotifyCreated) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to temp char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to temp char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tempNotifyCreated) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found supported temp chars in env service on device %s"),
|
|
||||||
sensorId, sSensor.name, pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
pClient->disconnect();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 0x2A6F - Notify about humidity x0.01% (pvvx)
|
|
||||||
{
|
|
||||||
bool humidityNotifyCreated = false;
|
|
||||||
if (!humidityNotifyCreated) {
|
|
||||||
NimBLEUUID charUuid((uint16_t) 0x2A6F);
|
|
||||||
pChar = pService->getCharacteristic(charUuid);
|
|
||||||
|
|
||||||
if (pChar && (pChar->canNotify() || pChar->canIndicate())) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found humidity char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
pChar->unsubscribe();
|
|
||||||
humidityNotifyCreated = pChar->subscribe(
|
|
||||||
pChar->canNotify(),
|
|
||||||
[sensorId](NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) {
|
|
||||||
if (pChar == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NimBLERemoteService* pService = pChar->getRemoteService();
|
|
||||||
if (pService == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NimBLEClient* pClient = pService->getClient();
|
|
||||||
if (pClient == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
|
|
||||||
if (length != 2) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': invalid notification data at humidity char (%s) on device %s"),
|
|
||||||
sensorId,
|
|
||||||
sSensor.name,
|
|
||||||
pChar->getUUID().toString().c_str(),
|
|
||||||
pClient->getPeerAddress().toString().c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float rawHumidity = (pChar->getValue<uint16_t>() * 0.01f);
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': received humidity: %.2f"),
|
|
||||||
sensorId, sSensor.name, rawHumidity
|
|
||||||
);
|
|
||||||
|
|
||||||
// set humidity
|
|
||||||
Sensors::setValueById(sensorId, rawHumidity, Sensors::ValueType::HUMIDITY, true, true);
|
|
||||||
|
|
||||||
// update rssi
|
|
||||||
Sensors::setValueById(sensorId, pClient->getRssi(), Sensors::ValueType::RSSI, false, false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (humidityNotifyCreated) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to humidity char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to humidity char (%s) in env service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!humidityNotifyCreated) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found supported humidity chars in env service on device %s"),
|
|
||||||
sensorId, sSensor.name, pAddress.c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Battery Service (0x180F)
|
|
||||||
{
|
|
||||||
NimBLEUUID serviceUuid((uint16_t) 0x180F);
|
|
||||||
pService = pClient->getService(serviceUuid);
|
|
||||||
if (!pService) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to find battery service (%s) on device %s"),
|
|
||||||
sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found battery service (%s) on device %s"),
|
|
||||||
sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 0x2A19 - Notify the battery charge level 0..99% (pvvx)
|
|
||||||
bool batteryNotifyCreated = false;
|
|
||||||
if (!batteryNotifyCreated) {
|
|
||||||
NimBLEUUID charUuid((uint16_t) 0x2A19);
|
|
||||||
pChar = pService->getCharacteristic(charUuid);
|
|
||||||
|
|
||||||
if (pChar && (pChar->canNotify() || pChar->canIndicate())) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found battery char (%s) in battery service on device %s"),
|
|
||||||
sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
pChar->unsubscribe();
|
|
||||||
batteryNotifyCreated = pChar->subscribe(
|
|
||||||
pChar->canNotify(),
|
|
||||||
[sensorId](NimBLERemoteCharacteristic* pChar, uint8_t* pData, size_t length, bool isNotify) {
|
|
||||||
if (pChar == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NimBLERemoteService* pService = pChar->getRemoteService();
|
|
||||||
if (pService == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NimBLEClient* pClient = pService->getClient();
|
|
||||||
if (pClient == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& sSensor = Sensors::settings[sensorId];
|
|
||||||
|
|
||||||
if (length != 1) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': invalid notification data at battery char (%s) on device %s"),
|
|
||||||
sensorId,
|
|
||||||
sSensor.name,
|
|
||||||
pChar->getUUID().toString().c_str(),
|
|
||||||
pClient->getPeerAddress().toString().c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rawBattery = pChar->getValue<uint8_t>();
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE),
|
|
||||||
F("Sensor #%hhu '%s': received battery: %hhu"),
|
|
||||||
sensorId, sSensor.name, rawBattery
|
|
||||||
);
|
|
||||||
|
|
||||||
// set battery
|
|
||||||
Sensors::setValueById(sensorId, rawBattery, Sensors::ValueType::BATTERY, true, true);
|
|
||||||
|
|
||||||
// update rssi
|
|
||||||
Sensors::setValueById(sensorId, pClient->getRssi(), Sensors::ValueType::RSSI, false, false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (batteryNotifyCreated) {
|
|
||||||
Log.straceln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to battery char (%s) in battery service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to battery char (%s) in battery service on device %s"),
|
|
||||||
sensorId, sSensor.name,
|
|
||||||
charUuid.toString().c_str(), pAddress.c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!batteryNotifyCreated) {
|
|
||||||
Log.swarningln(
|
|
||||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found supported battery chars in battery service on device %s"),
|
|
||||||
sensorId, sSensor.name, pAddress.c_str()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setDateOnBleSensor(NimBLEClient* pClient, const struct tm *ptm) {
|
|
||||||
auto ts = mkgmtime(ptm);
|
|
||||||
|
|
||||||
uint8_t data[5] = {};
|
|
||||||
data[0] = 0x23;
|
|
||||||
data[1] = ts & 0xff;
|
|
||||||
data[2] = (ts >> 8) & 0xff;
|
|
||||||
data[3] = (ts >> 16) & 0xff;
|
|
||||||
data[4] = (ts >> 24) & 0xff;
|
|
||||||
|
|
||||||
return pClient->setValue(
|
|
||||||
NimBLEUUID((uint16_t) 0x1f10),
|
|
||||||
NimBLEUUID((uint16_t) 0x1f1f),
|
|
||||||
NimBLEAttValue(data, sizeof(data))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void updateConnectionStatus() {
|
void updateConnectionStatus() {
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#define ARDUINOJSON_USE_DOUBLE 0
|
|
||||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <FileData.h>
|
#include <FileData.h>
|
||||||
@@ -216,7 +213,7 @@ void setup() {
|
|||||||
tRegulator = new RegulatorTask(true, 10000);
|
tRegulator = new RegulatorTask(true, 10000);
|
||||||
Scheduler.start(tRegulator);
|
Scheduler.start(tRegulator);
|
||||||
|
|
||||||
tPortal = new PortalTask(true, 0);
|
tPortal = new PortalTask(true, 10);
|
||||||
Scheduler.start(tPortal);
|
Scheduler.start(tPortal);
|
||||||
|
|
||||||
tMain = new MainTask(true, 100);
|
tMain = new MainTask(true, 100);
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ const char S_POWER[] PROGMEM = "power";
|
|||||||
const char S_PREFIX[] PROGMEM = "prefix";
|
const char S_PREFIX[] PROGMEM = "prefix";
|
||||||
const char S_PROTOCOL_VERSION[] PROGMEM = "protocolVersion";
|
const char S_PROTOCOL_VERSION[] PROGMEM = "protocolVersion";
|
||||||
const char S_PURPOSE[] PROGMEM = "purpose";
|
const char S_PURPOSE[] PROGMEM = "purpose";
|
||||||
|
const char S_PSRAM[] PROGMEM = "psram";
|
||||||
const char S_P_FACTOR[] PROGMEM = "p_factor";
|
const char S_P_FACTOR[] PROGMEM = "p_factor";
|
||||||
const char S_P_MULTIPLIER[] PROGMEM = "p_multiplier";
|
const char S_P_MULTIPLIER[] PROGMEM = "p_multiplier";
|
||||||
const char S_REAL_SIZE[] PROGMEM = "realSize";
|
const char S_REAL_SIZE[] PROGMEM = "realSize";
|
||||||
|
|||||||
@@ -62,19 +62,19 @@
|
|||||||
|
|
||||||
<form action="/api/upgrade" id="upgrade">
|
<form action="/api/upgrade" id="upgrade">
|
||||||
<fieldset class="primary">
|
<fieldset class="primary">
|
||||||
<label for="firmware-file">
|
<label>
|
||||||
<span data-i18n>upgrade.fw</span>:
|
<span data-i18n>upgrade.fw</span>:
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<input type="file" name="firmware" id="firmware-file" accept=".bin">
|
<input type="file" name="fw" accept=".bin">
|
||||||
<button type="button" class="upgrade-firmware-result hidden" disabled></button>
|
<button type="button" class="fwResult hidden" disabled></button>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label for="filesystem-file">
|
<label>
|
||||||
<span data-i18n>upgrade.fs</span>:
|
<span data-i18n>upgrade.fs</span>:
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<input type="file" name="filesystem" id="filesystem-file" accept=".bin">
|
<input type="file" name="fs" accept=".bin">
|
||||||
<button type="button" class="upgrade-filesystem-result hidden" disabled></button>
|
<button type="button" class="fsResult hidden" disabled></button>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@@ -108,7 +108,123 @@
|
|||||||
lang.build();
|
lang.build();
|
||||||
|
|
||||||
setupRestoreBackupForm('#restore');
|
setupRestoreBackupForm('#restore');
|
||||||
setupUpgradeForm('#upgrade');
|
|
||||||
|
const upgradeForm = document.querySelector('#upgrade');
|
||||||
|
if (upgradeForm) {
|
||||||
|
upgradeForm.reset();
|
||||||
|
const statusToText = (status) => {
|
||||||
|
switch (status) {
|
||||||
|
case 0:
|
||||||
|
return "None";
|
||||||
|
case 1:
|
||||||
|
return "No file";
|
||||||
|
case 2:
|
||||||
|
return "Success";
|
||||||
|
case 3:
|
||||||
|
return "Prohibited";
|
||||||
|
case 4:
|
||||||
|
return "Size mismatch";
|
||||||
|
case 5:
|
||||||
|
return "Error on start";
|
||||||
|
case 6:
|
||||||
|
return "Error on write";
|
||||||
|
case 7:
|
||||||
|
return "Error on finish";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
upgradeForm.addEventListener('submit', async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
hide('.fwResult');
|
||||||
|
hide('.fsResult');
|
||||||
|
|
||||||
|
let button = upgradeForm.querySelector('button[type="submit"]');
|
||||||
|
button.textContent = i18n('button.uploading');
|
||||||
|
button.setAttribute('disabled', true);
|
||||||
|
button.setAttribute('aria-busy', true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let fd = new FormData();
|
||||||
|
|
||||||
|
const fw = upgradeForm.querySelector("[name='fw']").files;
|
||||||
|
if (fw.length > 0) {
|
||||||
|
fd.append("fw_size", fw[0].size);
|
||||||
|
fd.append("fw", fw[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fs = upgradeForm.querySelector("[name='fs']").files;
|
||||||
|
if (fs.length > 0) {
|
||||||
|
fd.append("fs_size", fs[0].size);
|
||||||
|
fd.append("fs", fs[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await fetch(upgradeForm.action, {
|
||||||
|
method: "POST",
|
||||||
|
cache: "no-cache",
|
||||||
|
credentials: "include",
|
||||||
|
body: fd
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status != 202 && response.status != 406) {
|
||||||
|
throw new Error('Response not valid');
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
let resItem = upgradeForm.querySelector('.fwResult');
|
||||||
|
if (resItem && result.firmware.status > 1) {
|
||||||
|
resItem.textContent = statusToText(result.firmware.status);
|
||||||
|
resItem.classList.remove('hidden');
|
||||||
|
|
||||||
|
if (result.firmware.status == 2) {
|
||||||
|
resItem.classList.remove('failed');
|
||||||
|
resItem.classList.add('success');
|
||||||
|
} else {
|
||||||
|
resItem.classList.remove('success');
|
||||||
|
resItem.classList.add('failed');
|
||||||
|
|
||||||
|
if (result.firmware.error != "") {
|
||||||
|
resItem.textContent += `: ${result.firmware.error}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resItem = upgradeForm.querySelector('.fsResult');
|
||||||
|
if (resItem && result.filesystem.status > 1) {
|
||||||
|
resItem.textContent = statusToText(result.filesystem.status);
|
||||||
|
resItem.classList.remove('hidden');
|
||||||
|
|
||||||
|
if (result.filesystem.status == 2) {
|
||||||
|
resItem.classList.remove('failed');
|
||||||
|
resItem.classList.add('success');
|
||||||
|
} else {
|
||||||
|
resItem.classList.remove('success');
|
||||||
|
resItem.classList.add('failed');
|
||||||
|
|
||||||
|
if (result.filesystem.error != "") {
|
||||||
|
resItem.textContent += `: ${result.filesystem.error}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
button.textContent = i18n('button.error');
|
||||||
|
button.classList.add('failed');
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => {
|
||||||
|
button.removeAttribute('aria-busy');
|
||||||
|
button.removeAttribute('disabled');
|
||||||
|
button.classList.remove('success', 'failed');
|
||||||
|
button.textContent = i18n(button.dataset.i18n);
|
||||||
|
upgradeForm.reset();
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user