mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
changes to make it compile standalone
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm> // for count_if
|
#include <algorithm> // for count_if
|
||||||
|
|
||||||
|
#include "WString.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define IPAddress std::string
|
#define IPAddress std::string
|
||||||
@@ -129,7 +131,12 @@ class Print {
|
|||||||
size_t println(unsigned long value) {
|
size_t println(unsigned long value) {
|
||||||
return print(std::to_string(value).c_str()) + println();
|
return print(std::to_string(value).c_str()) + println();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void flush(){};
|
virtual void flush(){};
|
||||||
|
|
||||||
|
size_t print(const String & str) {
|
||||||
|
return print(str.c_str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Stream : public Print {
|
class Stream : public Print {
|
||||||
@@ -206,6 +213,6 @@ void yield(void);
|
|||||||
void setup(void);
|
void setup(void);
|
||||||
void loop(void);
|
void loop(void);
|
||||||
|
|
||||||
#include "WString.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class DummySettings {
|
|||||||
uint16_t publish_time_mixer = 10;
|
uint16_t publish_time_mixer = 10;
|
||||||
uint16_t publish_time_other = 10;
|
uint16_t publish_time_other = 10;
|
||||||
uint16_t publish_time_sensor = 10;
|
uint16_t publish_time_sensor = 10;
|
||||||
|
bool enableIPv6 = false;
|
||||||
|
|
||||||
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
||||||
|
|
||||||
@@ -80,6 +81,7 @@ class DummySettingsService : public StatefulService<DummySettings> {
|
|||||||
#define NetworkSettings DummySettings
|
#define NetworkSettings DummySettings
|
||||||
#define SecuritySettings DummySettings
|
#define SecuritySettings DummySettings
|
||||||
#define MqttSettings DummySettings
|
#define MqttSettings DummySettings
|
||||||
|
#define NTPSettings DummySettings
|
||||||
|
|
||||||
class ESP8266React {
|
class ESP8266React {
|
||||||
public:
|
public:
|
||||||
@@ -110,6 +112,10 @@ class ESP8266React {
|
|||||||
return &_settings;
|
return &_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatefulService<DummySettings> * getNTPSettingsService() {
|
||||||
|
return &_settings;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DummySettingsService _settings;
|
DummySettingsService _settings;
|
||||||
SecuritySettingsService _securitySettingsService;
|
SecuritySettingsService _securitySettingsService;
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ inline bool operator==(const std::string & lhs, const ::String & rhs) {
|
|||||||
return lhs == rhs.c_str();
|
return lhs == rhs.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(const ::String & lhs, const ::String & rhs) {
|
||||||
|
return lhs.c_str() != rhs.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize);
|
size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize);
|
||||||
size_t strlcat(char * dst, const char * src, size_t siz);
|
size_t strlcat(char * dst, const char * src, size_t siz);
|
||||||
|
|
||||||
|
|||||||
@@ -1200,6 +1200,7 @@ void EMSESP::start() {
|
|||||||
shower_.start(); // initialize shower timer and shower alert
|
shower_.start(); // initialize shower timer and shower alert
|
||||||
dallassensor_.start(); // dallas external sensors
|
dallassensor_.start(); // dallas external sensors
|
||||||
webServer.begin(); // start web server
|
webServer.begin(); // start web server
|
||||||
|
webLogService.start(); // start web log service
|
||||||
|
|
||||||
emsdevices.reserve(5); // reserve space for initially 5 devices to avoid mem frag issues
|
emsdevices.reserve(5); // reserve space for initially 5 devices to avoid mem frag issues
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ void WebDevicesService::write_sensor(AsyncWebServerRequest * request, JsonVarian
|
|||||||
|
|
||||||
strlcpy(name, id.c_str(), sizeof(name));
|
strlcpy(name, id.c_str(), sizeof(name));
|
||||||
if (no > 0 && no < 100) {
|
if (no > 0 && no < 100) {
|
||||||
itoa(no, nostr, 10);
|
Helpers::itoa(nostr, no, 10);
|
||||||
char * c = strchr(name, ' '); // find space
|
char * c = strchr(name, ' '); // find space
|
||||||
if (c != nullptr) {
|
if (c != nullptr) {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
|
|||||||
@@ -38,15 +38,13 @@ WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * security
|
|||||||
|
|
||||||
// for setting a level
|
// for setting a level
|
||||||
server->addHandler(&_setLevel);
|
server->addHandler(&_setLevel);
|
||||||
|
|
||||||
// start event source service
|
|
||||||
start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebLogService::forbidden(AsyncWebServerRequest * request) {
|
void WebLogService::forbidden(AsyncWebServerRequest * request) {
|
||||||
request->send(403);
|
request->send(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start event source service
|
||||||
void WebLogService::start() {
|
void WebLogService::start() {
|
||||||
uuid::log::Logger::register_handler(this, uuid::log::Level::INFO); // default is INFO
|
uuid::log::Logger::register_handler(this, uuid::log::Level::INFO); // default is INFO
|
||||||
}
|
}
|
||||||
@@ -81,7 +79,7 @@ void WebLogService::operator<<(std::shared_ptr<uuid::log::Message> message) {
|
|||||||
}
|
}
|
||||||
log_messages_.emplace_back(log_message_id_++, std::move(message));
|
log_messages_.emplace_back(log_message_id_++, std::move(message));
|
||||||
EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) {
|
EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) {
|
||||||
if (!settings.enabled || (time(nullptr) < 1500000000UL)) {
|
if (!settings.enabled || (time(nullptr) < 1500000000L)) {
|
||||||
time_offset_ = 0;
|
time_offset_ = 0;
|
||||||
} else if (!time_offset_) {
|
} else if (!time_offset_) {
|
||||||
time_offset_ = time(nullptr) - uuid::get_uptime_sec();
|
time_offset_ = time(nullptr) - uuid::get_uptime_sec();
|
||||||
|
|||||||
@@ -134,11 +134,13 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
settings.syslog_mark_interval = root["syslog_mark_interval"] | EMSESP_DEFAULT_SYSLOG_MARK_INTERVAL;
|
settings.syslog_mark_interval = root["syslog_mark_interval"] | EMSESP_DEFAULT_SYSLOG_MARK_INTERVAL;
|
||||||
check_flag(prev, settings.syslog_mark_interval, ChangeFlags::SYSLOG);
|
check_flag(prev, settings.syslog_mark_interval, ChangeFlags::SYSLOG);
|
||||||
|
|
||||||
|
#ifndef EMSESP_STANDALONE
|
||||||
String old_syslog_host = settings.syslog_host;
|
String old_syslog_host = settings.syslog_host;
|
||||||
settings.syslog_host = root["syslog_host"] | EMSESP_DEFAULT_SYSLOG_HOST;
|
settings.syslog_host = root["syslog_host"] | EMSESP_DEFAULT_SYSLOG_HOST;
|
||||||
if (!old_syslog_host.equals(settings.syslog_host)) {
|
if (!old_syslog_host.equals(settings.syslog_host)) {
|
||||||
add_flags(ChangeFlags::SYSLOG);
|
add_flags(ChangeFlags::SYSLOG);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
prev = settings.syslog_port;
|
prev = settings.syslog_port;
|
||||||
settings.syslog_port = root["syslog_port"] | EMSESP_DEFAULT_SYSLOG_PORT;
|
settings.syslog_port = root["syslog_port"] | EMSESP_DEFAULT_SYSLOG_PORT;
|
||||||
@@ -184,7 +186,8 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
// these need reboots to be applied
|
// these need reboots to be applied
|
||||||
settings.ems_bus_id = root["ems_bus_id"] | EMSESP_DEFAULT_EMS_BUS_ID;
|
settings.ems_bus_id = root["ems_bus_id"] | EMSESP_DEFAULT_EMS_BUS_ID;
|
||||||
settings.master_thermostat = root["master_thermostat"] | EMSESP_DEFAULT_MASTER_THERMOSTAT;
|
settings.master_thermostat = root["master_thermostat"] | EMSESP_DEFAULT_MASTER_THERMOSTAT;
|
||||||
settings.low_clock = root["low_clock"] | false;;
|
settings.low_clock = root["low_clock"] | false;
|
||||||
|
;
|
||||||
|
|
||||||
// doesn't need any follow-up actions
|
// doesn't need any follow-up actions
|
||||||
settings.notoken_api = root["notoken_api"] | EMSESP_DEFAULT_NOTOKEN_API;
|
settings.notoken_api = root["notoken_api"] | EMSESP_DEFAULT_NOTOKEN_API;
|
||||||
@@ -193,10 +196,10 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
|
|||||||
settings.dallas_format = root["dallas_format"] | EMSESP_DEFAULT_DALLAS_FORMAT;
|
settings.dallas_format = root["dallas_format"] | EMSESP_DEFAULT_DALLAS_FORMAT;
|
||||||
EMSESP::dallassensor_.dallas_format(settings.dallas_format);
|
EMSESP::dallassensor_.dallas_format(settings.dallas_format);
|
||||||
|
|
||||||
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
|
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
|
||||||
EMSESP::bool_format(settings.bool_format);
|
EMSESP::bool_format(settings.bool_format);
|
||||||
|
|
||||||
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
|
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
|
||||||
EMSESP::enum_format(settings.enum_format);
|
EMSESP::enum_format(settings.enum_format);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user