mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-03-14 05:36:34 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -21,24 +21,24 @@ void APSettingsService::begin() {
|
||||
|
||||
// wait 10 sec on STA disconnect before starting AP
|
||||
void APSettingsService::WiFiEvent(WiFiEvent_t event) {
|
||||
uint8_t was_connected = _connected;
|
||||
const uint8_t was_connected = _connected;
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
_connected &= ~1;
|
||||
_connected &= ~1U;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
_connected &= ~2;
|
||||
_connected &= ~2U;
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
|
||||
_connected |= 1;
|
||||
_connected |= 1U;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
case ARDUINO_EVENT_ETH_GOT_IP6:
|
||||
_connected |= 2;
|
||||
_connected |= 2U;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
}
|
||||
// wait 10 sec before starting AP
|
||||
if (was_connected && !_connected) {
|
||||
@@ -52,18 +52,19 @@ void APSettingsService::reconfigureAP() {
|
||||
}
|
||||
|
||||
void APSettingsService::loop() {
|
||||
unsigned long currentMillis = uuid::get_uptime();
|
||||
unsigned long manageElapsed = static_cast<uint32_t>(currentMillis - _lastManaged);
|
||||
if (manageElapsed >= MANAGE_NETWORK_DELAY) {
|
||||
const unsigned long currentMillis = uuid::get_uptime();
|
||||
if ((currentMillis - _lastManaged) >= MANAGE_NETWORK_DELAY) {
|
||||
_lastManaged = currentMillis;
|
||||
manageAP();
|
||||
}
|
||||
|
||||
handleDNS();
|
||||
if (_dnsServer) {
|
||||
handleDNS();
|
||||
}
|
||||
}
|
||||
|
||||
void APSettingsService::manageAP() {
|
||||
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
const WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
if (_state.provisionMode == AP_MODE_ALWAYS || (_state.provisionMode == AP_MODE_DISCONNECTED && !_connected)) {
|
||||
if (_reconfigureAp || currentWiFiMode == WIFI_OFF || currentWiFiMode == WIFI_STA) {
|
||||
startAP();
|
||||
@@ -87,8 +88,10 @@ void APSettingsService::startAP() {
|
||||
WiFi.setTxPower(WIFI_POWER_8_5dBm); // https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi
|
||||
#endif
|
||||
if (!_dnsServer) {
|
||||
IPAddress apIp = WiFi.softAPIP();
|
||||
emsesp::EMSESP::logger().info("Starting Access Point with captive portal on %s", apIp.toString().c_str());
|
||||
const IPAddress apIp = WiFi.softAPIP();
|
||||
char ipStr[16];
|
||||
snprintf(ipStr, sizeof(ipStr), "%u.%u.%u.%u", apIp[0], apIp[1], apIp[2], apIp[3]);
|
||||
emsesp::EMSESP::logger().info("Starting Access Point with captive portal on %s", ipStr);
|
||||
_dnsServer = new DNSServer;
|
||||
_dnsServer->start(DNS_PORT, "*", apIp);
|
||||
}
|
||||
@@ -111,8 +114,8 @@ void APSettingsService::handleDNS() {
|
||||
}
|
||||
|
||||
APNetworkStatus APSettingsService::getAPNetworkStatus() {
|
||||
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
bool apActive = currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA;
|
||||
const WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||
const bool apActive = (currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA);
|
||||
|
||||
if (apActive && _state.provisionMode != AP_MODE_ALWAYS && WiFi.status() == WL_CONNECTED) {
|
||||
return APNetworkStatus::LINGERING;
|
||||
@@ -135,7 +138,7 @@ void APSettings::read(const APSettings & settings, JsonObject root) {
|
||||
}
|
||||
|
||||
StateUpdateResult APSettings::update(JsonObject root, APSettings & settings) {
|
||||
APSettings newSettings = {};
|
||||
APSettings newSettings{};
|
||||
newSettings.provisionMode = static_cast<uint8_t>(root["provision_mode"] | FACTORY_AP_PROVISION_MODE);
|
||||
|
||||
switch (settings.provisionMode) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef APSettingsConfig_h
|
||||
#define APSettingsConfig_h
|
||||
#ifndef APSettingsService_h
|
||||
#define APSettingsService_h
|
||||
|
||||
#include "HttpEndpoint.h"
|
||||
#include "FSPersistence.h"
|
||||
@@ -70,9 +70,9 @@ class APSettings {
|
||||
IPAddress subnetMask;
|
||||
|
||||
bool operator==(const APSettings & settings) const {
|
||||
return provisionMode == settings.provisionMode && ssid == settings.ssid && password == settings.password && channel == settings.channel
|
||||
&& ssidHidden == settings.ssidHidden && maxClients == settings.maxClients && localIP == settings.localIP && gatewayIP == settings.gatewayIP
|
||||
&& subnetMask == settings.subnetMask;
|
||||
return provisionMode == settings.provisionMode && channel == settings.channel && ssidHidden == settings.ssidHidden
|
||||
&& maxClients == settings.maxClients && localIP == settings.localIP && gatewayIP == settings.gatewayIP
|
||||
&& subnetMask == settings.subnetMask && ssid == settings.ssid && password == settings.password;
|
||||
}
|
||||
|
||||
static void read(const APSettings & settings, JsonObject root);
|
||||
@@ -96,8 +96,8 @@ class APSettingsService : public StatefulService<APSettings> {
|
||||
|
||||
// for the management delay loop
|
||||
volatile unsigned long _lastManaged;
|
||||
volatile boolean _reconfigureAp;
|
||||
uint8_t _connected;
|
||||
volatile bool _reconfigureAp;
|
||||
volatile uint8_t _connected;
|
||||
|
||||
void reconfigureAP();
|
||||
void manageAP();
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "WWWData.h" // include auto-generated static web resources
|
||||
|
||||
static constexpr const char CACHE_CONTROL[] = "public,max-age=60";
|
||||
|
||||
ESP32React::ESP32React(AsyncWebServer * server, FS * fs)
|
||||
: _securitySettingsService(server, fs)
|
||||
, _networkSettingsService(server, fs, &_securitySettingsService)
|
||||
@@ -22,21 +24,18 @@ ESP32React::ESP32React(AsyncWebServer * server, FS * fs)
|
||||
ArRequestHandlerFunction indexHtmlHandler = nullptr;
|
||||
|
||||
WWWData::registerRoutes([server, &indexHtmlHandler](const char * uri, const String & contentType, const uint8_t * content, size_t len, const String & hash) {
|
||||
ArRequestHandlerFunction requestHandler = [contentType, content, len, hash](AsyncWebServerRequest * request) {
|
||||
AsyncWebServerResponse * response;
|
||||
String etag = "\"" + hash + "\""; // RFC9110: ETag must be enclosed in double quotes
|
||||
|
||||
// Check if the client already has the same version and respond with a 304 (Not modified)
|
||||
if (request->header("If-None-Match").equals(hash)) {
|
||||
response = request->beginResponse(304);
|
||||
} else {
|
||||
response = request->beginResponse(200, contentType, content, len);
|
||||
response->addHeader("Content-Encoding", "gzip"); // not br for brotlin only works over HTTPS
|
||||
ArRequestHandlerFunction requestHandler = [contentType, content, len, etag](AsyncWebServerRequest * request) {
|
||||
if (request->header(asyncsrv::T_INM) == etag) {
|
||||
request->send(304);
|
||||
return;
|
||||
}
|
||||
|
||||
// always send these headers - see https://datatracker.ietf.org/doc/html/rfc7232#section-4.1
|
||||
response->addHeader("ETag", hash);
|
||||
response->addHeader("Cache-Control", "no-cache"); // Requires revalidation before using cached content (ETags enable 304 responses)
|
||||
|
||||
AsyncWebServerResponse * response = request->beginResponse(200, contentType, content, len);
|
||||
response->addHeader(asyncsrv::T_Content_Encoding, asyncsrv::T_gzip, false);
|
||||
response->addHeader(asyncsrv::T_ETag, etag, false);
|
||||
response->addHeader(asyncsrv::T_Cache_Control, CACHE_CONTROL, false);
|
||||
request->send(response);
|
||||
};
|
||||
|
||||
@@ -69,11 +68,11 @@ void ESP32React::begin() {
|
||||
_networkSettingsService.read([&](NetworkSettings & networkSettings) {
|
||||
DefaultHeaders & defaultHeaders = DefaultHeaders::Instance();
|
||||
if (networkSettings.enableCORS) {
|
||||
defaultHeaders.addHeader("Access-Control-Allow-Origin", networkSettings.CORSOrigin);
|
||||
defaultHeaders.addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization");
|
||||
defaultHeaders.addHeader("Access-Control-Allow-Credentials", "true");
|
||||
defaultHeaders.addHeader(asyncsrv::T_CORS_ACAO, networkSettings.CORSOrigin);
|
||||
defaultHeaders.addHeader(asyncsrv::T_CORS_ACAH, "Accept, Content-Type, Authorization");
|
||||
defaultHeaders.addHeader(asyncsrv::T_CORS_ACAC, "true");
|
||||
}
|
||||
defaultHeaders.addHeader("Server", networkSettings.hostname);
|
||||
defaultHeaders.addHeader(asyncsrv::T_Server, networkSettings.hostname);
|
||||
});
|
||||
_apSettingsService.begin();
|
||||
_ntpSettingsService.begin();
|
||||
|
||||
@@ -10,20 +10,23 @@
|
||||
class JsonUtils {
|
||||
public:
|
||||
static void readIP(JsonObject root, const String & key, IPAddress & ip, const String & def) {
|
||||
IPAddress defaultIp = {};
|
||||
IPAddress defaultIp{};
|
||||
if (!defaultIp.fromString(def)) {
|
||||
defaultIp = INADDR_NONE;
|
||||
}
|
||||
readIP(root, key, ip, defaultIp);
|
||||
}
|
||||
static void readIP(JsonObject root, const String & key, IPAddress & ip, const IPAddress & defaultIp = INADDR_NONE) {
|
||||
if (!root[key].is<String>() || !ip.fromString(root[key].as<String>())) {
|
||||
const JsonVariant value = root[key];
|
||||
if (!value.is<String>() || !ip.fromString(value.as<const char *>())) {
|
||||
ip = defaultIp;
|
||||
}
|
||||
}
|
||||
static void writeIP(JsonObject root, const String & key, const IPAddress & ip) {
|
||||
if (IPUtils::isSet(ip)) {
|
||||
root[key] = ip.toString();
|
||||
char ipStr[16];
|
||||
snprintf(ipStr, sizeof(ipStr), "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
|
||||
root[key] = ipStr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -255,7 +255,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject root) {
|
||||
}
|
||||
|
||||
StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings) {
|
||||
MqttSettings newSettings = {};
|
||||
MqttSettings newSettings;
|
||||
bool changed = false;
|
||||
|
||||
#ifndef TASMOTA_SDK
|
||||
|
||||
@@ -125,11 +125,11 @@ class MqttSettingsService : public StatefulService<MqttSettings> {
|
||||
FSPersistence<MqttSettings> _fsPersistence;
|
||||
|
||||
// variable to help manage connection
|
||||
bool _reconfigureMqtt;
|
||||
unsigned long _disconnectedAt;
|
||||
volatile bool _reconfigureMqtt;
|
||||
volatile unsigned long _disconnectedAt;
|
||||
|
||||
// connection status
|
||||
espMqttClientTypes::DisconnectReason _disconnectReason;
|
||||
volatile espMqttClientTypes::DisconnectReason _disconnectReason;
|
||||
|
||||
// the MQTT client instance
|
||||
MqttClient * _mqttClient;
|
||||
|
||||
@@ -49,7 +49,7 @@ class NTPSettingsService : public StatefulService<NTPSettings> {
|
||||
private:
|
||||
HttpEndpoint<NTPSettings> _httpEndpoint;
|
||||
FSPersistence<NTPSettings> _fsPersistence;
|
||||
bool _connected;
|
||||
volatile bool _connected;
|
||||
|
||||
void WiFiEvent(WiFiEvent_t event);
|
||||
void configureNTP();
|
||||
|
||||
@@ -102,10 +102,10 @@ class NetworkSettingsService : public StatefulService<NetworkSettings> {
|
||||
HttpEndpoint<NetworkSettings> _httpEndpoint;
|
||||
FSPersistence<NetworkSettings> _fsPersistence;
|
||||
|
||||
unsigned long _lastConnectionAttempt;
|
||||
bool _stopping;
|
||||
volatile unsigned long _lastConnectionAttempt;
|
||||
volatile bool _stopping;
|
||||
|
||||
uint16_t connectcount_ = 0; // number of wifi reconnects
|
||||
volatile uint16_t connectcount_ = 0; // number of wifi reconnects
|
||||
|
||||
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
void mDNS_start() const;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#ifndef EMSESP_COMMAND_H_
|
||||
#define EMSESP_COMMAND_H_
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
#include "console.h"
|
||||
#include <esp32-psram.h>
|
||||
@@ -153,8 +153,8 @@ class Command {
|
||||
|
||||
class SUrlParser {
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> m_keysvalues;
|
||||
std::vector<std::string> m_folders;
|
||||
std::map<std::string, std::string> m_keysvalues;
|
||||
std::vector<std::string> m_folders;
|
||||
|
||||
public:
|
||||
SUrlParser() = default;
|
||||
@@ -166,7 +166,7 @@ class SUrlParser {
|
||||
return m_folders;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> & params() {
|
||||
std::map<std::string, std::string> & params() {
|
||||
return m_keysvalues;
|
||||
};
|
||||
|
||||
|
||||
@@ -1720,8 +1720,8 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {
|
||||
|
||||
// generate Prometheus metrics format from device values
|
||||
std::string EMSdevice::get_metrics_prometheus(const int8_t tag) {
|
||||
std::string result;
|
||||
std::unordered_map<std::string, bool> seen_metrics;
|
||||
std::string result;
|
||||
std::map<std::string, bool> seen_metrics;
|
||||
|
||||
// Helper function to check if a device value type is supported for Prometheus metrics
|
||||
auto is_supported_type = [](uint8_t type) -> bool {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "emsdevicevalue.h"
|
||||
|
||||
#include <esp32-psram.h>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
#ifndef EMSESP_EMSFACTORY_H_
|
||||
#define EMSESP_EMSFACTORY_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory> // for unique_ptr
|
||||
#include <map>
|
||||
|
||||
#include "emsdevice.h"
|
||||
// Forward declaration
|
||||
namespace emsesp {
|
||||
class EMSdevice;
|
||||
}
|
||||
|
||||
// Macro for class registration
|
||||
// Anonymous namespace is used to make the definitions here private to the current
|
||||
// compilation unit (current file). It is equivalent to the old C static keyword.
|
||||
#define REGISTER_FACTORY(derivedClass, device_type) \
|
||||
namespace { \
|
||||
auto registry_##derivedClass = ConcreteEMSFactory<derivedClass>(device_type); \
|
||||
@@ -34,30 +35,29 @@
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
class EMSdevice; // forward declaration, for gcc linking
|
||||
|
||||
class EMSFactory {
|
||||
public:
|
||||
virtual ~EMSFactory() = default;
|
||||
|
||||
// Register factory object of derived class
|
||||
// using the device_type as the unique identifier
|
||||
static auto registerFactory(const uint8_t device_type, EMSFactory * factory) -> void {
|
||||
auto & reg = EMSFactory::getRegister();
|
||||
reg[device_type] = factory;
|
||||
}
|
||||
|
||||
using FactoryMap = std::map<uint8_t, EMSFactory *>;
|
||||
|
||||
// Register factory object of derived class using the device_type as the unique identifier
|
||||
static inline auto registerFactory(const uint8_t device_type, EMSFactory * factory) -> void {
|
||||
getRegister()[device_type] = factory;
|
||||
}
|
||||
|
||||
// returns all registered classes (really only for debugging)
|
||||
static auto device_handlers() -> FactoryMap {
|
||||
return EMSFactory::getRegister();
|
||||
static inline auto device_handlers() -> const FactoryMap & {
|
||||
return getRegister();
|
||||
}
|
||||
|
||||
// Construct derived class returning an unique ptr
|
||||
static auto add(const uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * default_name, uint8_t flags, uint8_t brand)
|
||||
-> std::unique_ptr<EMSdevice> {
|
||||
return std::unique_ptr<EMSdevice>(EMSFactory::makeRaw(device_type, device_id, product_id, version, default_name, flags, brand));
|
||||
if (auto * ptr = makeRaw(device_type, device_id, product_id, version, default_name, flags, brand)) {
|
||||
return std::unique_ptr<EMSdevice>(ptr);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual auto construct(uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand) const
|
||||
@@ -65,7 +65,7 @@ class EMSFactory {
|
||||
|
||||
private:
|
||||
// Force global variable to be initialized, thus it avoids the "initialization order fiasco"
|
||||
static auto getRegister() -> FactoryMap & {
|
||||
static inline auto getRegister() -> FactoryMap & {
|
||||
static FactoryMap classRegister{};
|
||||
return classRegister;
|
||||
}
|
||||
@@ -74,11 +74,9 @@ class EMSFactory {
|
||||
// find which EMS device it is and use that class
|
||||
static auto makeRaw(const uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand)
|
||||
-> EMSdevice * {
|
||||
auto it = EMSFactory::getRegister().find(device_type);
|
||||
if (it != EMSFactory::getRegister().end()) {
|
||||
return it->second->construct(device_type, device_id, product_id, version, name, flags, brand);
|
||||
}
|
||||
return nullptr;
|
||||
const auto & reg = getRegister();
|
||||
const auto it = reg.find(device_type);
|
||||
return (it != reg.end()) ? it->second->construct(device_type, device_id, product_id, version, name, flags, brand) : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,7 +84,7 @@ template <typename DerivedClass>
|
||||
class ConcreteEMSFactory : EMSFactory {
|
||||
public:
|
||||
// Register this global object on the EMSFactory register
|
||||
ConcreteEMSFactory(const uint8_t device_type) {
|
||||
explicit ConcreteEMSFactory(const uint8_t device_type) {
|
||||
EMSFactory::registerFactory(device_type, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -344,8 +344,12 @@ bool isnum(const std::string & s) {
|
||||
std::string commands(std::string & expr, bool quotes) {
|
||||
auto expr_new = Helpers::toLower(expr);
|
||||
for (uint8_t device = 0; device < EMSdevice::DeviceType::UNKNOWN; device++) {
|
||||
std::string d = (std::string)EMSdevice::device_type_2_device_name(device) + "/";
|
||||
auto f = expr_new.find(d);
|
||||
// Optimized: build string with reserve to avoid temporary allocations
|
||||
std::string d;
|
||||
d.reserve(32); // typical device name length + "/"
|
||||
d = EMSdevice::device_type_2_device_name(device);
|
||||
d += "/";
|
||||
auto f = expr_new.find(d);
|
||||
while (f != std::string::npos) {
|
||||
// entity names are alphanumeric or _
|
||||
auto e = expr_new.find_first_not_of("/._abcdefghijklmnopqrstuvwxyz0123456789", f);
|
||||
@@ -367,9 +371,11 @@ std::string commands(std::string & expr, bool quotes) {
|
||||
JsonDocument doc_in;
|
||||
JsonObject output = doc_out.to<JsonObject>();
|
||||
JsonObject input = doc_in.to<JsonObject>();
|
||||
std::string cmd_s = "api/" + std::string(cmd);
|
||||
// Optimized: use stack buffer for small strings to avoid heap allocation
|
||||
char cmd_s[COMMAND_MAX_LENGTH + 5]; // "api/" prefix + cmd
|
||||
snprintf(cmd_s, sizeof(cmd_s), "api/%s", cmd);
|
||||
|
||||
auto return_code = Command::process(cmd_s.c_str(), true, input, output);
|
||||
auto return_code = Command::process(cmd_s, true, input, output);
|
||||
// check for no value (entity is valid but has no value set)
|
||||
if (return_code != CommandRet::OK && return_code != CommandRet::NO_VALUE) {
|
||||
return expr = "";
|
||||
@@ -725,7 +731,7 @@ std::string compute(const std::string & expr) {
|
||||
// if there is data, force a POST
|
||||
if (value.length() || Helpers::toLower(method) == "post") {
|
||||
if (value.find_first_of('{') != std::string::npos) {
|
||||
http.addHeader("Content-Type", "application/json"); // auto-set to JSON
|
||||
http.addHeader(asyncsrv::T_Content_Type, asyncsrv::T_application_json, false); // auto-set to JSON
|
||||
}
|
||||
httpResult = http.POST(value.c_str());
|
||||
} else {
|
||||
|
||||
@@ -1761,8 +1761,8 @@ void System::get_value_json(JsonObject output, const std::string & circuit, cons
|
||||
|
||||
// generate Prometheus metrics format from system values
|
||||
std::string System::get_metrics_prometheus() {
|
||||
std::string result;
|
||||
std::unordered_map<std::string, bool> seen_metrics;
|
||||
std::string result;
|
||||
std::map<std::string, bool> seen_metrics;
|
||||
|
||||
result.reserve(16000);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class Connect : public EMSdevice {
|
||||
bool set_childlock(const char * value, const int8_t id);
|
||||
bool set_icon(const char * value, const int8_t id);
|
||||
|
||||
std::vector<std::shared_ptr<Connect::RoomCircuit>> room_circuits_;
|
||||
std::vector<std::shared_ptr<Connect::RoomCircuit>, AllocatorPSRAM<std::shared_ptr<Connect::RoomCircuit>>> room_circuits_;
|
||||
|
||||
void process_OutdoorTemp(std::shared_ptr<const Telegram> telegram);
|
||||
void process_RCTime(std::shared_ptr<const Telegram> telegram);
|
||||
|
||||
@@ -59,7 +59,8 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
if (model == EMSdevice::EMS_DEVICE_FLAG_RC10) {
|
||||
monitor_typeids = {0xB1};
|
||||
set_typeids = {0xB0};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "RC10Monitor", false, MAKE_PF_CB(process_RC10Monitor));
|
||||
register_telegram_type(set_typeids[i], "RC10Set", false, MAKE_PF_CB(process_RC10Set));
|
||||
}
|
||||
@@ -70,7 +71,8 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
set_typeids = {0x3D, 0x47, 0x51, 0x5B};
|
||||
timer_typeids = {0x3F, 0x49, 0x53, 0x5D};
|
||||
timer2_typeids = {0x42, 0x4C, 0x56, 0x60};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "RC35Monitor", false, MAKE_PF_CB(process_RC35Monitor));
|
||||
register_telegram_type(set_typeids[i], "RC35Set", false, MAKE_PF_CB(process_RC35Set));
|
||||
register_telegram_type(timer_typeids[i], "RC35Timer", false, MAKE_PF_CB(process_RC35Timer));
|
||||
@@ -88,7 +90,8 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
set_typeids = {0xA8};
|
||||
curve_typeids = {0x90};
|
||||
timer_typeids = {0x8F};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "RC20Monitor", false, MAKE_PF_CB(process_RC20Monitor));
|
||||
register_telegram_type(set_typeids[i], "RC20Set", false, MAKE_PF_CB(process_RC20Set));
|
||||
register_telegram_type(curve_typeids[i], "RC20Temp", false, MAKE_PF_CB(process_RC20Temp));
|
||||
@@ -103,7 +106,8 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
if (device_id == 0x17) { // master
|
||||
monitor_typeids = {0xAE};
|
||||
set_typeids = {0xAD};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "RC20Monitor", false, MAKE_PF_CB(process_RC20Monitor_2));
|
||||
register_telegram_type(set_typeids[i], "RC20Set", false, MAKE_PF_CB(process_RC20Set_2));
|
||||
}
|
||||
@@ -117,7 +121,8 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
set_typeids = {0xA7};
|
||||
curve_typeids = {0x40};
|
||||
timer_typeids = {0x3F};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "RC30Monitor", false, MAKE_PF_CB(process_RC30Monitor));
|
||||
register_telegram_type(set_typeids[i], "RC30Set", false, MAKE_PF_CB(process_RC30Set));
|
||||
register_telegram_type(curve_typeids[i], "RC30Temp", false, MAKE_PF_CB(process_RC30Temp));
|
||||
@@ -131,15 +136,16 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
// EASY
|
||||
} else if (model == EMSdevice::EMS_DEVICE_FLAG_EASY) {
|
||||
monitor_typeids = {0x0A};
|
||||
set_typeids = {};
|
||||
set_typeids.clear();
|
||||
register_telegram_type(monitor_typeids[0], "EasyMonitor", true, MAKE_PF_CB(process_EasyMonitor));
|
||||
register_telegram_type(0x02A5, "EasyMonitor", false, MAKE_PF_CB(process_EasyMonitor));
|
||||
|
||||
// CRF
|
||||
} else if (model == EMSdevice::EMS_DEVICE_FLAG_CRF) {
|
||||
monitor_typeids = {0x02A5, 0x02A6, 0x02A7, 0x02A8};
|
||||
set_typeids = {};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
set_typeids.clear();
|
||||
const size_t size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "CRFMonitor", false, MAKE_PF_CB(process_CRFMonitor));
|
||||
}
|
||||
|
||||
@@ -163,14 +169,16 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
summer2_typeids = {0x0471, 0x0472, 0x0473, 0x0474, 0x0475, 0x0476, 0x0477, 0x0478};
|
||||
hp_typeids = {0x0467, 0x0468, 0x0469, 0x046A};
|
||||
hpmode_typeids = {0x0291, 0x0292, 0x0293, 0x0294};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t monitor_size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < monitor_size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "RC300Monitor", false, MAKE_PF_CB(process_RC300Monitor));
|
||||
register_telegram_type(set_typeids[i], "RC300Set", false, MAKE_PF_CB(process_RC300Set));
|
||||
register_telegram_type(summer_typeids[i], "RC300Summer", false, MAKE_PF_CB(process_RC300Summer));
|
||||
register_telegram_type(curve_typeids[i], "RC300Curves", false, MAKE_PF_CB(process_RC300Curve));
|
||||
register_telegram_type(summer2_typeids[i], "RC300Summer2", false, MAKE_PF_CB(process_RC300Summer2));
|
||||
}
|
||||
for (uint8_t i = 0; i < set2_typeids.size(); i++) {
|
||||
const size_t set2_size = set2_typeids.size();
|
||||
for (uint8_t i = 0; i < set2_size; i++) {
|
||||
// register_telegram_type(set2_typeids[i], "RC300Set2", false, MAKE_PF_CB(process_RC300Set2));
|
||||
register_telegram_type(set2_typeids[i], "RC300Set2", false, MAKE_PF_CB(process_PID));
|
||||
register_telegram_type(hp_typeids[i], "HPSet", false, MAKE_PF_CB(process_HPSet));
|
||||
@@ -210,19 +218,20 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
}
|
||||
|
||||
monitor_typeids = {0x016F, 0x0170, 0x0171, 0x0172};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t junkers_size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < junkers_size; i++) {
|
||||
register_telegram_type(monitor_typeids[i], "JunkersMonitor", false, MAKE_PF_CB(process_JunkersMonitor));
|
||||
}
|
||||
|
||||
if (has_flags(EMSdevice::EMS_DEVICE_FLAG_JUNKERS_OLD)) {
|
||||
// FR120, FR100
|
||||
set_typeids = {0x0179, 0x017A, 0x017B, 0x017C};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
for (uint8_t i = 0; i < junkers_size; i++) {
|
||||
register_telegram_type(set_typeids[i], "JunkersSet", false, MAKE_PF_CB(process_JunkersSet2));
|
||||
}
|
||||
} else {
|
||||
set_typeids = {0x0165, 0x0166, 0x0167, 0x0168};
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
for (uint8_t i = 0; i < junkers_size; i++) {
|
||||
register_telegram_type(set_typeids[i], "JunkersSet", false, MAKE_PF_CB(process_JunkersSet));
|
||||
}
|
||||
}
|
||||
@@ -237,10 +246,12 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
|
||||
// query all the heating circuits. This is only done once.
|
||||
// The automatic fetch will from now on only update the active heating circuits
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t monitor_size_final = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < monitor_size_final; i++) {
|
||||
EMSESP::send_read_request(monitor_typeids[i], device_id);
|
||||
}
|
||||
for (uint8_t i = 0; i < set_typeids.size(); i++) {
|
||||
const size_t set_size = set_typeids.size();
|
||||
for (uint8_t i = 0; i < set_size; i++) {
|
||||
EMSESP::send_read_request(set_typeids[i], device_id);
|
||||
}
|
||||
|
||||
@@ -293,7 +304,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search monitor message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < monitor_typeids.size(); i++) {
|
||||
const size_t monitor_size = monitor_typeids.size();
|
||||
for (uint8_t i = 0; i < monitor_size; i++) {
|
||||
if (monitor_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
toggle_ = true;
|
||||
@@ -304,7 +316,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search status message/set types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < set_typeids.size(); i++) {
|
||||
const size_t set_size = set_typeids.size();
|
||||
for (uint8_t i = 0; i < set_size; i++) {
|
||||
if (set_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -314,7 +327,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search set2 types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < set2_typeids.size(); i++) {
|
||||
const size_t set2_size = set2_typeids.size();
|
||||
for (uint8_t i = 0; i < set2_size; i++) {
|
||||
if (set2_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -324,7 +338,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search summer message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < summer_typeids.size(); i++) {
|
||||
const size_t summer_size = summer_typeids.size();
|
||||
for (uint8_t i = 0; i < summer_size; i++) {
|
||||
if (summer_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -334,7 +349,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search summer message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < summer2_typeids.size(); i++) {
|
||||
const size_t summer2_size = summer2_typeids.size();
|
||||
for (uint8_t i = 0; i < summer2_size; i++) {
|
||||
if (summer2_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -344,7 +360,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search heating_curve message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < curve_typeids.size(); i++) {
|
||||
const size_t curve_size = curve_typeids.size();
|
||||
for (uint8_t i = 0; i < curve_size; i++) {
|
||||
if (curve_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -354,7 +371,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search timer message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < timer_typeids.size(); i++) {
|
||||
const size_t timer_size = timer_typeids.size();
|
||||
for (uint8_t i = 0; i < timer_size; i++) {
|
||||
if (timer_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -364,7 +382,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search timer message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < timer2_typeids.size(); i++) {
|
||||
const size_t timer2_size = timer2_typeids.size();
|
||||
for (uint8_t i = 0; i < timer2_size; i++) {
|
||||
if (timer2_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -374,7 +393,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
|
||||
// not found, search heatpump message types
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < hp_typeids.size(); i++) {
|
||||
const size_t hp_size = hp_typeids.size();
|
||||
for (uint8_t i = 0; i < hp_size; i++) {
|
||||
if (hp_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
@@ -383,7 +403,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(std::sha
|
||||
}
|
||||
|
||||
if (hc_num == 0) {
|
||||
for (uint8_t i = 0; i < hpmode_typeids.size(); i++) {
|
||||
const size_t hpmode_size = hpmode_typeids.size();
|
||||
for (uint8_t i = 0; i < hpmode_size; i++) {
|
||||
if (hpmode_typeids[i] == telegram->type_id) {
|
||||
hc_num = i + 1;
|
||||
break;
|
||||
|
||||
@@ -247,16 +247,16 @@ class Thermostat : public EMSdevice {
|
||||
}
|
||||
|
||||
// each thermostat has a list of heating controller type IDs for reading and writing
|
||||
std::vector<uint16_t> monitor_typeids;
|
||||
std::vector<uint16_t> set_typeids;
|
||||
std::vector<uint16_t> set2_typeids;
|
||||
std::vector<uint16_t> timer_typeids;
|
||||
std::vector<uint16_t> timer2_typeids;
|
||||
std::vector<uint16_t> summer_typeids;
|
||||
std::vector<uint16_t> summer2_typeids;
|
||||
std::vector<uint16_t> curve_typeids;
|
||||
std::vector<uint16_t> hp_typeids;
|
||||
std::vector<uint16_t> hpmode_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> monitor_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> set_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> set2_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> timer_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> timer2_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> summer_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> summer2_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> curve_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> hp_typeids;
|
||||
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> hpmode_typeids;
|
||||
|
||||
// standard for all thermostats
|
||||
char status_[20]; // online or offline
|
||||
@@ -308,8 +308,8 @@ class Thermostat : public EMSdevice {
|
||||
uint8_t pvRaiseHeat_;
|
||||
uint8_t pvLowerCool_;
|
||||
|
||||
std::vector<std::shared_ptr<HeatingCircuit>> heating_circuits_; // each thermostat can have multiple heating circuits
|
||||
std::vector<std::shared_ptr<DhwCircuit>> dhw_circuits_; // each thermostat can have multiple dhw circuits
|
||||
std::vector<std::shared_ptr<HeatingCircuit>, AllocatorPSRAM<std::shared_ptr<HeatingCircuit>>> heating_circuits_; // each thermostat can have multiple heating circuits
|
||||
std::vector<std::shared_ptr<DhwCircuit>, AllocatorPSRAM<std::shared_ptr<DhwCircuit>>> dhw_circuits_; // each thermostat can have multiple dhw circuits
|
||||
|
||||
// Generic Types
|
||||
static constexpr uint16_t EMS_TYPE_RCTime = 0x06; // time
|
||||
|
||||
@@ -248,18 +248,24 @@ void WebSchedulerService::publish(const bool force) {
|
||||
snprintf(val_obj, sizeof(val_obj), "value_json['%s']", scheduleItem.name);
|
||||
snprintf(val_cond, sizeof(val_cond), "%s is defined", val_obj);
|
||||
|
||||
// Optimized: use stack buffer instead of string concatenation to avoid heap allocations
|
||||
char val_tpl[150];
|
||||
if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) {
|
||||
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + "}}";
|
||||
snprintf(val_tpl, sizeof(val_tpl), "{{%s if %s}}", val_obj, val_cond);
|
||||
} else {
|
||||
config["val_tpl"] = (std::string) "{{" + val_obj + "}}"; // omit value conditional Jinja2 template code
|
||||
snprintf(val_tpl, sizeof(val_tpl), "{{%s}}", val_obj); // omit value conditional Jinja2 template code
|
||||
}
|
||||
config["val_tpl"] = val_tpl;
|
||||
|
||||
char uniq_s[70];
|
||||
snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(scheduler), scheduleItem.name);
|
||||
|
||||
config["uniq_id"] = uniq_s;
|
||||
config["name"] = (const char *)scheduleItem.name;
|
||||
config["def_ent_id"] = std::string("switch.") + uniq_s;
|
||||
// Optimized: use stack buffer instead of string concatenation
|
||||
char def_ent_id[80];
|
||||
snprintf(def_ent_id, sizeof(def_ent_id), "switch.%s", uniq_s);
|
||||
config["def_ent_id"] = def_ent_id;
|
||||
|
||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||
char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||
@@ -331,7 +337,7 @@ bool WebSchedulerService::command(const char * name, const std::string & command
|
||||
int httpResult = 0;
|
||||
if (value.length() || method == "post") { // we have all lowercase
|
||||
if (value.find_first_of('{') != std::string::npos) {
|
||||
http.addHeader("Content-Type", "application/json"); // auto-set to JSON
|
||||
http.addHeader(asyncsrv::T_Content_Type, asyncsrv::T_application_json, false); // auto-set to JSON
|
||||
}
|
||||
httpResult = http.POST(value.c_str());
|
||||
} else {
|
||||
|
||||
@@ -496,7 +496,15 @@ void WebSettings::set_board_profile(WebSettings & settings) {
|
||||
System::load_board_profile(data, settings.board_profile.c_str());
|
||||
}
|
||||
|
||||
EMSESP::logger().info("Loaded board profile %s", settings.board_profile.c_str());
|
||||
// log board profile and PSRAM info
|
||||
#ifndef EMSESP_STANDALONE
|
||||
uint32_t psram_size = ESP.getPsramSize() / 1024; // in KB
|
||||
if (psram_size > 0) {
|
||||
EMSESP::logger().info("Loaded board profile %s, PSRAM: %lu KB", settings.board_profile.c_str(), psram_size);
|
||||
} else {
|
||||
EMSESP::logger().info("Loaded board profile %s, PSRAM: not available", settings.board_profile.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
// apply the new board profile settings
|
||||
// 0=led, 1=dallas, 2=rx, 3=tx, 4=button, 5=phy_type, 6=eth_power, 7=eth_phy_addr, 8=eth_clock_mode, 9=led_type
|
||||
|
||||
Reference in New Issue
Block a user