mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
Compare commits
12 Commits
master
...
c39eeee9cf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c39eeee9cf | ||
|
|
f2fe6036c2 | ||
|
|
40dc863530 | ||
|
|
a40413aeac | ||
|
|
9a045bfc40 | ||
|
|
d576969ea4 | ||
|
|
c78d2d0c0b | ||
|
|
b7825111bb | ||
|
|
d5691ef8f7 | ||
|
|
0213582464 | ||
|
|
396dc7f7e3 | ||
|
|
9d38525251 |
@@ -1,6 +1,6 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
class UpgradeHandler : public RequestHandler {
|
||||
class UpgradeHandler : public AsyncWebHandler {
|
||||
public:
|
||||
enum class UpgradeType {
|
||||
FIRMWARE = 0,
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
NO_FILE,
|
||||
SUCCESS,
|
||||
PROHIBITED,
|
||||
ABORTED,
|
||||
SIZE_MISMATCH,
|
||||
ERROR_ON_START,
|
||||
ERROR_ON_WRITE,
|
||||
ERROR_ON_FINISH
|
||||
@@ -22,27 +22,21 @@ public:
|
||||
UpgradeType type;
|
||||
UpgradeStatus status;
|
||||
String error;
|
||||
size_t progress = 0;
|
||||
size_t size = 0;
|
||||
} UpgradeResult;
|
||||
|
||||
typedef std::function<bool(HTTPMethod, const String&)> CanHandleCallback;
|
||||
typedef std::function<bool(const String&)> CanUploadCallback;
|
||||
typedef std::function<bool(UpgradeType)> BeforeUpgradeCallback;
|
||||
typedef std::function<void(const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
|
||||
typedef std::function<bool(AsyncWebServerRequest *request, UpgradeType)> BeforeUpgradeCallback;
|
||||
typedef std::function<void(AsyncWebServerRequest *request, const UpgradeResult&, const UpgradeResult&)> AfterUpgradeCallback;
|
||||
|
||||
UpgradeHandler(const char* uri) {
|
||||
this->uri = uri;
|
||||
}
|
||||
UpgradeHandler(AsyncURIMatcher uri) : uri(uri) {}
|
||||
|
||||
UpgradeHandler* setCanHandleCallback(CanHandleCallback callback = nullptr) {
|
||||
this->canHandleCallback = callback;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
UpgradeHandler* setCanUploadCallback(CanUploadCallback callback = nullptr) {
|
||||
this->canUploadCallback = callback;
|
||||
|
||||
return this;
|
||||
bool canHandle(AsyncWebServerRequest *request) const override final {
|
||||
if (!request->isHTTP()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->uri.matches(request);
|
||||
}
|
||||
|
||||
UpgradeHandler* setBeforeUpgradeCallback(BeforeUpgradeCallback callback = nullptr) {
|
||||
@@ -57,29 +51,9 @@ public:
|
||||
return this;
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
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 {
|
||||
void handleRequest(AsyncWebServerRequest *request) override final {
|
||||
if (this->afterUpgradeCallback) {
|
||||
this->afterUpgradeCallback(this->firmwareResult, this->filesystemResult);
|
||||
this->afterUpgradeCallback(request, this->firmwareResult, this->filesystemResult);
|
||||
}
|
||||
|
||||
this->firmwareResult.status = UpgradeStatus::NONE;
|
||||
@@ -87,129 +61,147 @@ public:
|
||||
|
||||
this->filesystemResult.status = UpgradeStatus::NONE;
|
||||
this->filesystemResult.error.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void upload(WebServer& server, const String& uri, HTTPUpload& upload) override {
|
||||
UpgradeResult* result;
|
||||
if (upload.name.equals(F("firmware"))) {
|
||||
result = &this->firmwareResult;
|
||||
void handleUpload(AsyncWebServerRequest *request, const String &fileName, size_t index, uint8_t *data, size_t dataLength, bool isFinal) override final {
|
||||
UpgradeResult* result = nullptr;
|
||||
|
||||
} else if (upload.name.equals(F("filesystem"))) {
|
||||
result = &this->filesystemResult;
|
||||
|
||||
} else {
|
||||
if (!request->hasParam(asyncsrv::T_name, true, true)) {
|
||||
// Missing content-disposition 'name' parameter
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(result->type)) {
|
||||
if (this->beforeUpgradeCallback && !this->beforeUpgradeCallback(request, result->type)) {
|
||||
result->status = UpgradeStatus::PROHIBITED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!upload.filename.length()) {
|
||||
if (!fileName.length()) {
|
||||
result->status = UpgradeStatus::NO_FILE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
if (!index) {
|
||||
// reset
|
||||
if (Update.isRunning()) {
|
||||
Update.end(false);
|
||||
Update.clearError();
|
||||
}
|
||||
|
||||
// try begin
|
||||
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) {
|
||||
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH);
|
||||
|
||||
} else if (result->type == UpgradeType::FILESYSTEM) {
|
||||
begin = Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!begin || Update.hasError()) {
|
||||
result->status = UpgradeStatus::ERROR_ON_START;
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
result->error = Update.getErrorString();
|
||||
#else
|
||||
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;
|
||||
}
|
||||
|
||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', started"), upload.filename.c_str());
|
||||
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
|
||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s', started", fileName.c_str());
|
||||
}
|
||||
|
||||
if (dataLength) {
|
||||
if (Update.write(data, dataLength) != dataLength) {
|
||||
Update.end(false);
|
||||
|
||||
result->status = UpgradeStatus::ERROR_ON_WRITE;
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
result->error = Update.getErrorString();
|
||||
#else
|
||||
result->error = Update.errorString();
|
||||
#endif
|
||||
|
||||
Log.serrorln(
|
||||
FPSTR(L_PORTAL_OTA),
|
||||
F("File '%s', on writing %d bytes: %s"),
|
||||
upload.filename.c_str(), upload.totalSize, result->error.c_str()
|
||||
FPSTR(L_PORTAL_OTA), "File '%s', on write %d bytes, %d of %d bytes",
|
||||
fileName.c_str(),
|
||||
dataLength,
|
||||
result->progress + dataLength,
|
||||
result->size
|
||||
);
|
||||
|
||||
} else {
|
||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s', writed %d bytes"), upload.filename.c_str(), upload.totalSize);
|
||||
return;
|
||||
}
|
||||
|
||||
result->progress += dataLength;
|
||||
Log.sinfoln(
|
||||
FPSTR(L_PORTAL_OTA), "File '%s', write %d bytes, %d of %d bytes",
|
||||
fileName.c_str(),
|
||||
dataLength,
|
||||
result->progress,
|
||||
result->size
|
||||
);
|
||||
}
|
||||
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (Update.end(true)) {
|
||||
result->status = UpgradeStatus::SUCCESS;
|
||||
if (result->size > 0) {
|
||||
if (result->progress > result->size || (isFinal && result->progress < result->size)) {
|
||||
Update.end(false);
|
||||
result->status = UpgradeStatus::SIZE_MISMATCH;
|
||||
|
||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), F("File '%s': finish"), upload.filename.c_str());
|
||||
|
||||
} else {
|
||||
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;
|
||||
#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);
|
||||
Log.serrorln(FPSTR(L_PORTAL_OTA), "File '%s', on finish: %s", fileName.c_str(), result->error);
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (upload.status == UPLOAD_FILE_ABORTED) {
|
||||
Update.end(false);
|
||||
result->status = UpgradeStatus::ABORTED;
|
||||
|
||||
Log.serrorln(FPSTR(L_PORTAL_OTA), F("File '%s': aborted"), upload.filename.c_str());
|
||||
result->status = UpgradeStatus::SUCCESS;
|
||||
Log.sinfoln(FPSTR(L_PORTAL_OTA), "File '%s': finish", fileName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool isRequestHandlerTrivial() const override final {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
CanHandleCallback canHandleCallback;
|
||||
CanUploadCallback canUploadCallback;
|
||||
BeforeUpgradeCallback beforeUpgradeCallback;
|
||||
AfterUpgradeCallback afterUpgradeCallback;
|
||||
const char* uri = nullptr;
|
||||
AsyncURIMatcher uri;
|
||||
|
||||
UpgradeResult firmwareResult{UpgradeType::FIRMWARE, UpgradeStatus::NONE};
|
||||
UpgradeResult filesystemResult{UpgradeType::FILESYSTEM, UpgradeStatus::NONE};
|
||||
|
||||
594
platformio.ini
594
platformio.ini
@@ -1,379 +1,275 @@
|
||||
; 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]
|
||||
;extra_configs = secrets.ini
|
||||
extra_configs = secrets.default.ini
|
||||
core_dir = .pio
|
||||
;extra_configs = secrets.ini
|
||||
extra_configs = secrets.default.ini
|
||||
core_dir = .pio
|
||||
|
||||
[env]
|
||||
version = 1.5.6
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.4.2
|
||||
;ihormelnyk/OpenTherm Library@^1.1.5
|
||||
https://github.com/Laxilef/opentherm_library#esp32_timer
|
||||
arduino-libraries/ArduinoMqttClient@^0.1.8
|
||||
lennarthennigs/ESP Telnet@^2.2.3
|
||||
gyverlibs/FileData@^1.0.3
|
||||
gyverlibs/GyverPID@^3.3.2
|
||||
gyverlibs/GyverBlinker@^1.1.1
|
||||
https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg
|
||||
laxilef/TinyLogger@^1.1.1
|
||||
build_type = ${secrets.build_type}
|
||||
build_flags =
|
||||
-mtext-section-literals
|
||||
-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 BUILD_VERSION='"${this.version}"'
|
||||
-D BUILD_ENV='"$PIOENV"'
|
||||
-D DEFAULT_SERIAL_ENABLED=${secrets.serial_enabled}
|
||||
-D DEFAULT_SERIAL_BAUD=${secrets.serial_baud}
|
||||
-D DEFAULT_TELNET_ENABLED=${secrets.telnet_enabled}
|
||||
-D DEFAULT_TELNET_PORT=${secrets.telnet_port}
|
||||
-D DEFAULT_LOG_LEVEL=${secrets.log_level}
|
||||
-D DEFAULT_HOSTNAME='"${secrets.hostname}"'
|
||||
-D DEFAULT_AP_SSID='"${secrets.ap_ssid}"'
|
||||
-D DEFAULT_AP_PASSWORD='"${secrets.ap_password}"'
|
||||
-D DEFAULT_STA_SSID='"${secrets.sta_ssid}"'
|
||||
-D DEFAULT_STA_PASSWORD='"${secrets.sta_password}"'
|
||||
-D DEFAULT_PORTAL_LOGIN='"${secrets.portal_login}"'
|
||||
-D DEFAULT_PORTAL_PASSWORD='"${secrets.portal_password}"'
|
||||
-D DEFAULT_MQTT_ENABLED=${secrets.mqtt_enabled}
|
||||
-D DEFAULT_MQTT_SERVER='"${secrets.mqtt_server}"'
|
||||
-D DEFAULT_MQTT_PORT=${secrets.mqtt_port}
|
||||
-D DEFAULT_MQTT_USER='"${secrets.mqtt_user}"'
|
||||
-D DEFAULT_MQTT_PASSWORD='"${secrets.mqtt_password}"'
|
||||
-D DEFAULT_MQTT_PREFIX='"${secrets.mqtt_prefix}"'
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
;monitor_filters = direct
|
||||
monitor_filters =
|
||||
esp32_exception_decoder
|
||||
esp8266_exception_decoder
|
||||
board_build.flash_mode = dio
|
||||
board_build.filesystem = littlefs
|
||||
check_tool = ; pvs-studio
|
||||
check_flags =
|
||||
; pvs-studio:
|
||||
; --analysis-mode=4
|
||||
; --exclude-path=./.pio/libdeps
|
||||
version = 1.5.7-passiveble
|
||||
framework = arduino
|
||||
lib_deps = ESP32Async/AsyncTCP
|
||||
;ESP32Async/ESPAsyncWebServer
|
||||
https://github.com/ESP32Async/ESPAsyncWebServer
|
||||
bblanchon/ArduinoJson@^7.4.2
|
||||
;ihormelnyk/OpenTherm Library@^1.1.5
|
||||
https://github.com/Laxilef/opentherm_library#esp32_timer
|
||||
arduino-libraries/ArduinoMqttClient@^0.1.8
|
||||
lennarthennigs/ESP Telnet@^2.2.3
|
||||
gyverlibs/FileData@^1.0.3
|
||||
gyverlibs/GyverPID@^3.3.2
|
||||
gyverlibs/GyverBlinker@^1.1.1
|
||||
https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg
|
||||
laxilef/TinyLogger@^1.1.1
|
||||
build_type = ${secrets.build_type}
|
||||
build_flags = -mtext-section-literals
|
||||
-Wno-deprecated-declarations
|
||||
-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 BUILD_VERSION='"${this.version}"'
|
||||
-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_BAUD=${secrets.serial_baud}
|
||||
-D DEFAULT_TELNET_ENABLED=${secrets.telnet_enabled}
|
||||
-D DEFAULT_TELNET_PORT=${secrets.telnet_port}
|
||||
-D DEFAULT_LOG_LEVEL=${secrets.log_level}
|
||||
-D DEFAULT_HOSTNAME='"${secrets.hostname}"'
|
||||
-D DEFAULT_AP_SSID='"${secrets.ap_ssid}"'
|
||||
-D DEFAULT_AP_PASSWORD='"${secrets.ap_password}"'
|
||||
-D DEFAULT_STA_SSID='"${secrets.sta_ssid}"'
|
||||
-D DEFAULT_STA_PASSWORD='"${secrets.sta_password}"'
|
||||
-D DEFAULT_PORTAL_LOGIN='"${secrets.portal_login}"'
|
||||
-D DEFAULT_PORTAL_PASSWORD='"${secrets.portal_password}"'
|
||||
-D DEFAULT_MQTT_ENABLED=${secrets.mqtt_enabled}
|
||||
-D DEFAULT_MQTT_SERVER='"${secrets.mqtt_server}"'
|
||||
-D DEFAULT_MQTT_PORT=${secrets.mqtt_port}
|
||||
-D DEFAULT_MQTT_USER='"${secrets.mqtt_user}"'
|
||||
-D DEFAULT_MQTT_PASSWORD='"${secrets.mqtt_password}"'
|
||||
-D DEFAULT_MQTT_PREFIX='"${secrets.mqtt_prefix}"'
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
;monitor_filters = direct
|
||||
monitor_filters = esp32_exception_decoder
|
||||
esp8266_exception_decoder
|
||||
board_build.flash_mode = dio
|
||||
board_build.filesystem = littlefs
|
||||
check_tool = ;pvs-studio
|
||||
check_flags = ;pvs-studio: --analysis-mode=4 --exclude-path=./.pio/libdeps
|
||||
|
||||
; Defaults
|
||||
[esp8266_defaults]
|
||||
platform = espressif8266@^4.2.1
|
||||
platform_packages = ${env.platform_packages}
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
nrwiersma/ESP8266Scheduler@^1.2
|
||||
lib_ignore =
|
||||
extra_scripts =
|
||||
post:tools/build.py
|
||||
build_type = ${env.build_type}
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
||||
;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
|
||||
-D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||
board_build.ldscript = eagle.flash.4m1m.ld
|
||||
check_tool = ${env.check_tool}
|
||||
check_flags = ${env.check_flags}
|
||||
platform = espressif8266@^4.2.1
|
||||
platform_packages = ${env.platform_packages}
|
||||
lib_deps = ${env.lib_deps}
|
||||
nrwiersma/ESP8266Scheduler@^1.2
|
||||
lib_ignore =
|
||||
extra_scripts = post:tools/build.py
|
||||
build_type = ${env.build_type}
|
||||
build_flags = ${env.build_flags}
|
||||
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
||||
;-D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
|
||||
-D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305
|
||||
board_build.ldscript = eagle.flash.4m1m.ld
|
||||
check_tool = ${env.check_tool}
|
||||
check_flags = ${env.check_flags}
|
||||
|
||||
[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_packages = ${env.platform_packages}
|
||||
board_build.partitions = esp32_partitions.csv
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
laxilef/ESP32Scheduler@^1.0.1
|
||||
nimble_lib = h2zero/NimBLE-Arduino@2.3.3
|
||||
lib_ignore =
|
||||
extra_scripts =
|
||||
post:tools/esp32.py
|
||||
post:tools/build.py
|
||||
build_type = ${env.build_type}
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
-D CORE_DEBUG_LEVEL=0
|
||||
-Wl,--wrap=esp_panic_handler
|
||||
check_tool = ${env.check_tool}
|
||||
check_flags = ${env.check_flags}
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.34/platform-espressif32.zip
|
||||
platform_packages = ${env.platform_packages}
|
||||
board_build.partitions = esp32_partitions.csv
|
||||
lib_deps = ${env.lib_deps}
|
||||
laxilef/ESP32Scheduler@^1.0.1
|
||||
nimble_lib = https://github.com/h2zero/NimBLE-Arduino
|
||||
lib_ignore = BluetoothSerial
|
||||
SimpleBLE
|
||||
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
|
||||
build_type = ${env.build_type}
|
||||
build_flags = ${env.build_flags}
|
||||
-D CORE_DEBUG_LEVEL=0
|
||||
-Wl,--wrap=esp_panic_handler
|
||||
check_tool = ${env.check_tool}
|
||||
check_flags = ${env.check_flags}
|
||||
|
||||
|
||||
; Boards
|
||||
[env:d1_mini]
|
||||
platform = ${esp8266_defaults.platform}
|
||||
platform_packages = ${esp8266_defaults.platform_packages}
|
||||
board = d1_mini
|
||||
lib_deps = ${esp8266_defaults.lib_deps}
|
||||
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_OUT_GPIO=5
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||
-D DEFAULT_STATUS_LED_GPIO=13
|
||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||
check_tool = ${esp8266_defaults.check_tool}
|
||||
check_flags = ${esp8266_defaults.check_flags}
|
||||
extends = esp8266_defaults
|
||||
board = d1_mini
|
||||
build_flags = ${esp8266_defaults.build_flags}
|
||||
-D DEFAULT_OT_IN_GPIO=4
|
||||
-D DEFAULT_OT_OUT_GPIO=5
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||
-D DEFAULT_STATUS_LED_GPIO=13
|
||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||
|
||||
[env:d1_mini_lite]
|
||||
platform = ${esp8266_defaults.platform}
|
||||
platform_packages = ${esp8266_defaults.platform_packages}
|
||||
board = d1_mini_lite
|
||||
lib_deps = ${esp8266_defaults.lib_deps}
|
||||
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_OUT_GPIO=5
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||
-D DEFAULT_STATUS_LED_GPIO=13
|
||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||
check_tool = ${esp8266_defaults.check_tool}
|
||||
check_flags = ${esp8266_defaults.check_flags}
|
||||
extends = esp8266_defaults
|
||||
board = d1_mini_lite
|
||||
build_flags = ${esp8266_defaults.build_flags}
|
||||
-D DEFAULT_OT_IN_GPIO=4
|
||||
-D DEFAULT_OT_OUT_GPIO=5
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||
-D DEFAULT_STATUS_LED_GPIO=13
|
||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||
|
||||
[env:d1_mini_pro]
|
||||
platform = ${esp8266_defaults.platform}
|
||||
platform_packages = ${esp8266_defaults.platform_packages}
|
||||
board = d1_mini_pro
|
||||
lib_deps = ${esp8266_defaults.lib_deps}
|
||||
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_OUT_GPIO=5
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||
-D DEFAULT_STATUS_LED_GPIO=13
|
||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||
check_tool = ${esp8266_defaults.check_tool}
|
||||
check_flags = ${esp8266_defaults.check_flags}
|
||||
extends = esp8266_defaults
|
||||
board = d1_mini_pro
|
||||
build_flags = ${esp8266_defaults.build_flags}
|
||||
-D DEFAULT_OT_IN_GPIO=4
|
||||
-D DEFAULT_OT_OUT_GPIO=5
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=14
|
||||
-D DEFAULT_STATUS_LED_GPIO=13
|
||||
-D DEFAULT_OT_RX_LED_GPIO=15
|
||||
|
||||
[env:nodemcu_8266]
|
||||
platform = ${esp8266_defaults.platform}
|
||||
platform_packages = ${esp8266_defaults.platform_packages}
|
||||
board = nodemcuv2
|
||||
lib_deps = ${esp8266_defaults.lib_deps}
|
||||
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_OUT_GPIO=15
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=4
|
||||
-D DEFAULT_STATUS_LED_GPIO=2
|
||||
-D DEFAULT_OT_RX_LED_GPIO=16
|
||||
check_tool = ${esp8266_defaults.check_tool}
|
||||
check_flags = ${esp8266_defaults.check_flags}
|
||||
extends = esp8266_defaults
|
||||
board = nodemcuv2
|
||||
build_flags = ${esp8266_defaults.build_flags}
|
||||
-D DEFAULT_OT_IN_GPIO=13
|
||||
-D DEFAULT_OT_OUT_GPIO=15
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=4
|
||||
-D DEFAULT_STATUS_LED_GPIO=2
|
||||
-D DEFAULT_OT_RX_LED_GPIO=16
|
||||
|
||||
[env:s2_mini]
|
||||
platform = ${esp32_defaults.platform}
|
||||
platform_packages = ${esp32_defaults.platform_packages}
|
||||
board = lolin_s2_mini
|
||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
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_CDC_ON_BOOT=1
|
||||
-D DEFAULT_OT_IN_GPIO=33
|
||||
-D DEFAULT_OT_OUT_GPIO=35
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=9
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=7
|
||||
-D DEFAULT_STATUS_LED_GPIO=11
|
||||
-D DEFAULT_OT_RX_LED_GPIO=12
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
extends = esp32_defaults
|
||||
board = lolin_s2_mini
|
||||
build_unflags = -DARDUINO_USB_MODE=1
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D ARDUINO_USB_MODE=0
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
-D DEFAULT_OT_IN_GPIO=33
|
||||
-D DEFAULT_OT_OUT_GPIO=35
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=9
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=7
|
||||
-D DEFAULT_STATUS_LED_GPIO=11
|
||||
-D DEFAULT_OT_RX_LED_GPIO=12
|
||||
|
||||
[env:s3_mini]
|
||||
platform = ${esp32_defaults.platform}
|
||||
platform_packages = ${esp32_defaults.platform_packages}
|
||||
board = lolin_s3_mini
|
||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
||||
lib_deps =
|
||||
${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
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_CDC_ON_BOOT=1
|
||||
-D CONFIG_BT_NIMBLE_EXT_ADV=1
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=35
|
||||
-D DEFAULT_OT_OUT_GPIO=36
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=12
|
||||
-D DEFAULT_STATUS_LED_GPIO=11
|
||||
-D DEFAULT_OT_RX_LED_GPIO=10
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
[env:s3_mini]
|
||||
extends = esp32_defaults
|
||||
board = lolin_s3_mini
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
build_unflags = -DARDUINO_USB_MODE=1
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D ARDUINO_USB_MODE=0
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
-D USE_BLE=1
|
||||
-D MYNEWT_VAL_BLE_EXT_ADV=1
|
||||
-D DEFAULT_OT_IN_GPIO=35
|
||||
-D DEFAULT_OT_OUT_GPIO=36
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=13
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=12
|
||||
-D DEFAULT_STATUS_LED_GPIO=11
|
||||
-D DEFAULT_OT_RX_LED_GPIO=10
|
||||
|
||||
[env:c3_mini]
|
||||
platform = ${esp32_defaults.platform}
|
||||
platform_packages = ${esp32_defaults.platform_packages}
|
||||
board = lolin_c3_mini
|
||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
||||
lib_deps =
|
||||
${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
||||
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 DEFAULT_OT_IN_GPIO=8
|
||||
-D DEFAULT_OT_OUT_GPIO=10
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=1
|
||||
-D DEFAULT_STATUS_LED_GPIO=4
|
||||
-D DEFAULT_OT_RX_LED_GPIO=5
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
[env:c3_mini]
|
||||
extends = esp32_defaults
|
||||
board = lolin_c3_mini
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
build_unflags = -mtext-section-literals
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=8
|
||||
-D DEFAULT_OT_OUT_GPIO=10
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=1
|
||||
-D DEFAULT_STATUS_LED_GPIO=4
|
||||
-D DEFAULT_OT_RX_LED_GPIO=5
|
||||
|
||||
[env:nodemcu_32]
|
||||
platform = ${esp32_defaults.platform}
|
||||
platform_packages = ${esp32_defaults.platform_packages}
|
||||
board = nodemcu-32s
|
||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
||||
lib_deps =
|
||||
${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
||||
build_type = ${esp32_defaults.build_type}
|
||||
build_flags =
|
||||
${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=16
|
||||
-D DEFAULT_OT_OUT_GPIO=4
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=15
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=26
|
||||
-D DEFAULT_STATUS_LED_GPIO=2
|
||||
-D DEFAULT_OT_RX_LED_GPIO=19
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
extends = esp32_defaults
|
||||
board = nodemcu-32s
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=16
|
||||
-D DEFAULT_OT_OUT_GPIO=4
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=15
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=26
|
||||
-D DEFAULT_STATUS_LED_GPIO=2
|
||||
-D DEFAULT_OT_RX_LED_GPIO=19
|
||||
|
||||
[env:nodemcu_32_160mhz]
|
||||
extends = env:nodemcu_32
|
||||
board_build.f_cpu = 160000000L ; set frequency to 160MHz
|
||||
[env:nodemcu_32_160mhz]
|
||||
extends = env:nodemcu_32
|
||||
board_build.f_cpu = 160000000L ; set frequency to 160MHz
|
||||
|
||||
[env:d1_mini32]
|
||||
platform = ${esp32_defaults.platform}
|
||||
platform_packages = ${esp32_defaults.platform_packages}
|
||||
board = wemos_d1_mini32
|
||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
||||
lib_deps =
|
||||
${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
||||
build_type = ${esp32_defaults.build_type}
|
||||
build_flags =
|
||||
${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=21
|
||||
-D DEFAULT_OT_OUT_GPIO=22
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=18
|
||||
-D DEFAULT_STATUS_LED_GPIO=2
|
||||
-D DEFAULT_OT_RX_LED_GPIO=19
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
extends = esp32_defaults
|
||||
board = wemos_d1_mini32
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=21
|
||||
-D DEFAULT_OT_OUT_GPIO=22
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=12
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=18
|
||||
-D DEFAULT_STATUS_LED_GPIO=2
|
||||
-D DEFAULT_OT_RX_LED_GPIO=19
|
||||
|
||||
[env:esp32_c6]
|
||||
platform = ${esp32_defaults.platform}
|
||||
framework = arduino, espidf
|
||||
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_ignore =
|
||||
${esp32_defaults.lib_ignore}
|
||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
||||
build_unflags =
|
||||
-mtext-section-literals
|
||||
build_type = ${esp32_defaults.build_type}
|
||||
build_flags =
|
||||
${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=15
|
||||
-D DEFAULT_OT_OUT_GPIO=23
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=0
|
||||
-D DEFAULT_STATUS_LED_GPIO=11
|
||||
-D DEFAULT_OT_RX_LED_GPIO=10
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
extends = esp32_defaults
|
||||
board = esp32-c6-devkitc-1
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
build_unflags = -mtext-section-literals
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=15
|
||||
-D DEFAULT_OT_OUT_GPIO=23
|
||||
-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
||||
-D DEFAULT_SENSOR_INDOOR_GPIO=0
|
||||
-D DEFAULT_STATUS_LED_GPIO=11
|
||||
-D DEFAULT_OT_RX_LED_GPIO=10
|
||||
|
||||
[env:otthing]
|
||||
platform = ${esp32_defaults.platform}
|
||||
platform_packages = ${esp32_defaults.platform_packages}
|
||||
board = lolin_c3_mini
|
||||
board_build.partitions = ${esp32_defaults.board_build.partitions}
|
||||
lib_deps =
|
||||
${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
lib_ignore = ${esp32_defaults.lib_ignore}
|
||||
extra_scripts = ${esp32_defaults.extra_scripts}
|
||||
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 DEFAULT_OT_IN_GPIO=3
|
||||
-D DEFAULT_OT_OUT_GPIO=1
|
||||
; -D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
||||
; -D DEFAULT_SENSOR_INDOOR_GPIO=1
|
||||
-D DEFAULT_STATUS_LED_GPIO=8
|
||||
-D DEFAULT_OT_RX_LED_GPIO=2
|
||||
-D OT_BYPASS_RELAY_GPIO=20
|
||||
check_tool = ${esp32_defaults.check_tool}
|
||||
check_flags = ${esp32_defaults.check_flags}
|
||||
[env:otthing]
|
||||
extends = esp32_defaults
|
||||
board = lolin_c3_mini
|
||||
lib_deps = ${esp32_defaults.lib_deps}
|
||||
${esp32_defaults.nimble_lib}
|
||||
build_unflags = -mtext-section-literals
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
-D USE_BLE=1
|
||||
-D DEFAULT_OT_IN_GPIO=3
|
||||
-D DEFAULT_OT_OUT_GPIO=1
|
||||
;-D DEFAULT_SENSOR_OUTDOOR_GPIO=0
|
||||
;-D DEFAULT_SENSOR_INDOOR_GPIO=1
|
||||
-D DEFAULT_STATUS_LED_GPIO=8
|
||||
-D DEFAULT_OT_RX_LED_GPIO=2
|
||||
-D OT_BYPASS_RELAY_GPIO=20
|
||||
|
||||
@@ -51,6 +51,10 @@ protected:
|
||||
return "Main";
|
||||
}
|
||||
|
||||
uint32_t getTaskStackSize() override {
|
||||
return 6000;
|
||||
}
|
||||
|
||||
/*BaseType_t getTaskCore() override {
|
||||
return 1;
|
||||
}*/
|
||||
|
||||
@@ -37,6 +37,10 @@ protected:
|
||||
const char* getTaskName() override {
|
||||
return "OpenTherm";
|
||||
}
|
||||
|
||||
uint32_t getTaskStackSize() override {
|
||||
return 7500;
|
||||
}
|
||||
|
||||
BaseType_t getTaskCore() override {
|
||||
return 1;
|
||||
|
||||
849
src/PortalTask.h
849
src/PortalTask.h
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,10 @@ protected:
|
||||
const char* getTaskName() override {
|
||||
return "Regulator";
|
||||
}
|
||||
|
||||
uint32_t getTaskStackSize() override {
|
||||
return 5000;
|
||||
}
|
||||
|
||||
/*BaseType_t getTaskCore() override {
|
||||
return 1;
|
||||
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
|
||||
static int16_t getIdByName(const char* name) {
|
||||
if (settings == nullptr) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (uint8_t id = 0; id <= getMaxSensorId(); id++) {
|
||||
@@ -163,7 +163,7 @@ public:
|
||||
|
||||
static int16_t getIdByObjectId(const char* objectId) {
|
||||
if (settings == nullptr) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
String refObjectId;
|
||||
|
||||
@@ -9,41 +9,136 @@
|
||||
extern FileData fsSensorsSettings;
|
||||
|
||||
#if USE_BLE
|
||||
class BluetoothClientCallbacks : public NimBLEClientCallbacks {
|
||||
class BluetoothScanCallbacks : public NimBLEScanCallbacks {
|
||||
public:
|
||||
BluetoothClientCallbacks(uint8_t sensorId) : sensorId(sensorId) {}
|
||||
void onDiscovered(const NimBLEAdvertisedDevice* device) override {
|
||||
auto& deviceAddress = device->getAddress();
|
||||
|
||||
void onConnect(NimBLEClient* pClient) {
|
||||
auto& sSensor = Sensors::settings[this->sensorId];
|
||||
bool found = false;
|
||||
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;
|
||||
}
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': connected to %s"),
|
||||
sensorId, sSensor.name, pClient->getPeerAddress().toString().c_str()
|
||||
);
|
||||
}
|
||||
const auto sensorAddress = NimBLEAddress(sSensor.address, deviceAddress.getType());
|
||||
if (sensorAddress.isNull() || sensorAddress != deviceAddress) {
|
||||
continue;
|
||||
}
|
||||
|
||||
void onDisconnect(NimBLEClient* pClient, int reason) {
|
||||
auto& sSensor = Sensors::settings[this->sensorId];
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': disconnected, reason %i"),
|
||||
sensorId, sSensor.name, reason
|
||||
);
|
||||
}
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
|
||||
void onConnectFail(NimBLEClient* pClient, int reason) {
|
||||
auto& sSensor = Sensors::settings[this->sensorId];
|
||||
auto& sSensor = Sensors::settings[sensorId];
|
||||
auto& rSensor = Sensors::results[sensorId];
|
||||
auto deviceName = device->getName();
|
||||
auto deviceRssi = device->getRSSI();
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to connect, reason %i"),
|
||||
sensorId, sSensor.name, reason
|
||||
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
|
||||
);
|
||||
|
||||
pClient->cancelConnect();
|
||||
}
|
||||
if (!device->haveServiceData()) {
|
||||
Log.straceln(
|
||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found service data"),
|
||||
sensorId, sSensor.name
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t sensorId;
|
||||
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
|
||||
|
||||
@@ -55,6 +150,10 @@ public:
|
||||
this->dallasSearchTime.reserve(2);
|
||||
this->dallasPolling.reserve(2);
|
||||
this->dallasLastPollingTime.reserve(2);
|
||||
|
||||
#if USE_BLE
|
||||
this->pBLEScanCallbacks = new BluetoothScanCallbacks();
|
||||
#endif
|
||||
}
|
||||
|
||||
~SensorsTask() {
|
||||
@@ -63,16 +162,17 @@ public:
|
||||
this->dallasSearchTime.clear();
|
||||
this->dallasPolling.clear();
|
||||
this->dallasLastPollingTime.clear();
|
||||
|
||||
#if USE_BLE
|
||||
delete this->pBLEScanCallbacks;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
const unsigned int disconnectedTimeout = 120000;
|
||||
const unsigned short dallasSearchInterval = 60000;
|
||||
const unsigned short dallasPollingInterval = 10000;
|
||||
const unsigned short globalPollingInterval = 15000;
|
||||
#if USE_BLE
|
||||
const unsigned int bleSetDtInterval = 7200000;
|
||||
#endif
|
||||
const unsigned int disconnectedTimeout = 180000u;
|
||||
const unsigned short dallasSearchInterval = 60000u;
|
||||
const unsigned short dallasPollingInterval = 10000u;
|
||||
const unsigned short globalPollingInterval = 15000u;
|
||||
|
||||
std::unordered_map<uint8_t, OneWire> owInstances;
|
||||
std::unordered_map<uint8_t, DallasTemperature> dallasInstances;
|
||||
@@ -80,9 +180,9 @@ protected:
|
||||
std::unordered_map<uint8_t, bool> dallasPolling;
|
||||
std::unordered_map<uint8_t, unsigned long> dallasLastPollingTime;
|
||||
#if USE_BLE
|
||||
std::unordered_map<uint8_t, NimBLEClient*> bleClients;
|
||||
std::unordered_map<uint8_t, bool> bleSubscribed;
|
||||
std::unordered_map<uint8_t, unsigned long> bleLastSetDtTime;
|
||||
NimBLEScan* pBLEScan = nullptr;
|
||||
BluetoothScanCallbacks* pBLEScanCallbacks = nullptr;
|
||||
bool activeScanBle = false;
|
||||
#endif
|
||||
unsigned long globalLastPollingTime = 0;
|
||||
|
||||
@@ -91,6 +191,10 @@ protected:
|
||||
return "Sensors";
|
||||
}
|
||||
|
||||
uint32_t getTaskStackSize() override {
|
||||
return 7500;
|
||||
}
|
||||
|
||||
BaseType_t getTaskCore() override {
|
||||
// https://github.com/h2zero/NimBLE-Arduino/issues/676
|
||||
#if USE_BLE && defined(CONFIG_BT_NIMBLE_PINNED_TO_CORE)
|
||||
@@ -131,8 +235,7 @@ protected:
|
||||
this->yield();
|
||||
|
||||
#if USE_BLE
|
||||
cleanBleInstances();
|
||||
pollingBleSensors();
|
||||
scanBleSensors();
|
||||
this->yield();
|
||||
#endif
|
||||
|
||||
@@ -444,549 +547,71 @@ protected:
|
||||
}
|
||||
|
||||
#if USE_BLE
|
||||
void cleanBleInstances() {
|
||||
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() {
|
||||
void scanBleSensors() {
|
||||
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;
|
||||
}
|
||||
|
||||
if (!NimBLEDevice::isInitialized() && millis() > 5000) {
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Initialized"));
|
||||
BLEDevice::init("");
|
||||
NimBLEDevice::setPower(9);
|
||||
NimBLEDevice::init("");
|
||||
|
||||
#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++) {
|
||||
auto& sSensor = Sensors::settings[sensorId];
|
||||
auto& rSensor = Sensors::results[sensorId];
|
||||
|
||||
if (!sSensor.enabled || sSensor.type != Sensors::Type::BLUETOOTH || sSensor.purpose == Sensors::Purpose::NOT_CONFIGURED) {
|
||||
continue;
|
||||
}
|
||||
if (this->pBLEScan == nullptr) {
|
||||
this->pBLEScan = NimBLEDevice::getScan();
|
||||
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);
|
||||
|
||||
const auto address = NimBLEAddress(sSensor.address, 0);
|
||||
if (address.isNull()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto pClient = this->getBleClient(sensorId);
|
||||
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(
|
||||
FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': trying connecting to %s..."),
|
||||
sensorId, sSensor.name, pClient->getPeerAddress().toString().c_str()
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
||||
Log.swarningln(
|
||||
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;
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Scanning initialized"));
|
||||
}
|
||||
|
||||
auto& sSensor = Sensors::settings[sensorId];
|
||||
auto& rSensor = Sensors::results[sensorId];
|
||||
if (!this->pBLEScan->isScanning()) {
|
||||
this->activeScanBle = !this->activeScanBle;
|
||||
this->pBLEScan->setActiveScan(this->activeScanBle);
|
||||
|
||||
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()
|
||||
if (this->pBLEScan->start(30000, false, false)) {
|
||||
Log.sinfoln(
|
||||
FPSTR(L_SENSORS_BLE),
|
||||
F("%s scanning started"),
|
||||
this->activeScanBle ? "Active" : "Passive"
|
||||
);
|
||||
|
||||
} 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()
|
||||
);
|
||||
}
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), F("Unable to start scanning"));
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#define ARDUINOJSON_USE_DOUBLE 0
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <FileData.h>
|
||||
@@ -216,7 +213,7 @@ void setup() {
|
||||
tRegulator = new RegulatorTask(true, 10000);
|
||||
Scheduler.start(tRegulator);
|
||||
|
||||
tPortal = new PortalTask(true, 0);
|
||||
tPortal = new PortalTask(true, 10);
|
||||
Scheduler.start(tPortal);
|
||||
|
||||
tMain = new MainTask(true, 100);
|
||||
|
||||
@@ -164,6 +164,7 @@ const char S_POWER[] PROGMEM = "power";
|
||||
const char S_PREFIX[] PROGMEM = "prefix";
|
||||
const char S_PROTOCOL_VERSION[] PROGMEM = "protocolVersion";
|
||||
const char S_PURPOSE[] PROGMEM = "purpose";
|
||||
const char S_PSRAM[] PROGMEM = "psram";
|
||||
const char S_P_FACTOR[] PROGMEM = "p_factor";
|
||||
const char S_P_MULTIPLIER[] PROGMEM = "p_multiplier";
|
||||
const char S_REAL_SIZE[] PROGMEM = "realSize";
|
||||
|
||||
@@ -62,19 +62,19 @@
|
||||
|
||||
<form action="/api/upgrade" id="upgrade">
|
||||
<fieldset class="primary">
|
||||
<label for="firmware-file">
|
||||
<label>
|
||||
<span data-i18n>upgrade.fw</span>:
|
||||
<div class="grid">
|
||||
<input type="file" name="firmware" id="firmware-file" accept=".bin">
|
||||
<button type="button" class="upgrade-firmware-result hidden" disabled></button>
|
||||
<input type="file" name="fw" accept=".bin">
|
||||
<button type="button" class="fwResult hidden" disabled></button>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label for="filesystem-file">
|
||||
<label>
|
||||
<span data-i18n>upgrade.fs</span>:
|
||||
<div class="grid">
|
||||
<input type="file" name="filesystem" id="filesystem-file" accept=".bin">
|
||||
<button type="button" class="upgrade-filesystem-result hidden" disabled></button>
|
||||
<input type="file" name="fs" accept=".bin">
|
||||
<button type="button" class="fsResult hidden" disabled></button>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
@@ -108,7 +108,123 @@
|
||||
lang.build();
|
||||
|
||||
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>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user