move some vectors to psram, fix syslog start/stop

This commit is contained in:
MichaelDvP
2025-12-04 19:57:01 +01:00
parent dd0ab8f962
commit 1d03056784
28 changed files with 3172 additions and 70 deletions

View File

@@ -25,6 +25,10 @@
#include <uuid/log.h>
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
namespace emsesp {
// names, same order as AnalogType, see list_sensortype in local_common.h
@@ -146,7 +150,11 @@ class AnalogSensor {
bool updated_values();
// return back reference to the sensor list, used by other classes
#ifndef EMSESP_STANDALONE
std::vector<Sensor, AllocatorPSRAM<Sensor>> sensors() const {
#else
std::vector<Sensor> sensors() const {
#endif
return sensors_;
}
@@ -174,9 +182,9 @@ class AnalogSensor {
return sensors_.size();
}
bool update(uint8_t gpio, std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted, bool is_system);
bool get_value_info(JsonObject output, const char * cmd, const int8_t id = -1);
void store_counters();
bool update(uint8_t gpio, std::string & name, double offset, double factor, uint8_t uom, int8_t type, bool deleted, bool is_system);
bool get_value_info(JsonObject output, const char * cmd, const int8_t id = -1);
void store_counters();
static std::vector<uint8_t> exclude_types() {
return exclude_types_;
}
@@ -191,13 +199,17 @@ class AnalogSensor {
static constexpr uint32_t MEASURE_ANALOG_INTERVAL = 500;
static uuid::log::Logger logger_;
void remove_ha_topic(const int8_t type, const uint8_t id) const;
bool command_setvalue(const char * value, const int8_t gpio);
void measure();
void addSensorJson(JsonObject output, const Sensor & sensor);
void get_value_json(JsonObject output, const Sensor & sensor);
void remove_ha_topic(const int8_t type, const uint8_t id) const;
bool command_setvalue(const char * value, const int8_t gpio);
void measure();
void addSensorJson(JsonObject output, const Sensor & sensor);
void get_value_json(JsonObject output, const Sensor & sensor);
#ifndef EMSESP_STANDALONE
std::vector<Sensor, AllocatorPSRAM<Sensor>> sensors_; // our list of sensors
#else
std::vector<Sensor> sensors_; // our list of sensors
#endif
static std::vector<uint8_t> exclude_types_;
bool analog_enabled_;

View File

@@ -25,6 +25,9 @@
#include "helpers.h"
#include "emsdevicevalue.h"
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
#include <unordered_map>
namespace emsesp {
@@ -549,13 +552,21 @@ class EMSdevice {
}
};
std::vector<uint16_t> handlers_ignored_;
#ifndef EMSESP_STANDALONE
std::vector<uint16_t, AllocatorPSRAM<uint16_t>> handlers_ignored_, handlers_broadcasted_, handlers_config_;
#else
std::vector<uint16_t> handlers_ignored_, handlers_broadcasted_, handlers_config_;
#endif
#if defined(EMSESP_STANDALONE) || defined(EMSESP_TEST)
public: // so we can call it from WebCustomizationService::load_test_data() and EMSESP::dump_all_entities()
#endif
#ifndef EMSESP_STANDALONE
std::vector<TelegramFunction, AllocatorPSRAM<TelegramFunction>> telegram_functions_; // each EMS device has its own set of registered telegram types
std::vector<DeviceValue, AllocatorPSRAM<DeviceValue>> devicevalues_; // all the device values
#else
std::vector<TelegramFunction> telegram_functions_; // each EMS device has its own set of registered telegram types
std::vector<DeviceValue> devicevalues_; // all the device values
#endif
};
} // namespace emsesp

View File

@@ -29,22 +29,28 @@ static_assert(uuid::console::thread_safe, "uuid-console must be thread-safe");
namespace emsesp {
// Static member definitions
#ifndef EMSESP_STANDALONE
std::vector<std::unique_ptr<EMSdevice>, AllocatorPSRAM<std::unique_ptr<EMSdevice>>> EMSESP::emsdevices{};
std::vector<EMSESP::Device_record, AllocatorPSRAM<EMSESP::Device_record>> EMSESP::device_library_;
#else
std::vector<std::unique_ptr<EMSdevice>> EMSESP::emsdevices{};
std::vector<EMSESP::Device_record> EMSESP::device_library_;
uuid::log::Logger EMSESP::logger_{F_(emsesp), uuid::log::Facility::KERN};
uint16_t EMSESP::watch_id_ = WATCH_ID_NONE;
uint8_t EMSESP::watch_ = 0;
uint16_t EMSESP::read_id_ = WATCH_ID_NONE;
bool EMSESP::read_next_ = false;
uint16_t EMSESP::publish_id_ = 0;
uint16_t EMSESP::response_id_ = 0;
bool EMSESP::tap_water_active_ = false;
uint8_t EMSESP::publish_all_idx_ = 0;
uint8_t EMSESP::unique_id_count_ = 0;
bool EMSESP::trace_raw_ = false;
uint16_t EMSESP::wait_validate_ = 0;
bool EMSESP::wait_km_ = false;
uint32_t EMSESP::last_fetch_ = 0;
#endif
uuid::log::Logger EMSESP::logger_{F_(emsesp), uuid::log::Facility::KERN};
uint16_t EMSESP::watch_id_ = WATCH_ID_NONE;
uint8_t EMSESP::watch_ = 0;
uint16_t EMSESP::read_id_ = WATCH_ID_NONE;
bool EMSESP::read_next_ = false;
uint16_t EMSESP::publish_id_ = 0;
uint16_t EMSESP::response_id_ = 0;
bool EMSESP::tap_water_active_ = false;
uint8_t EMSESP::publish_all_idx_ = 0;
uint8_t EMSESP::unique_id_count_ = 0;
bool EMSESP::trace_raw_ = false;
uint16_t EMSESP::wait_validate_ = 0;
bool EMSESP::wait_km_ = false;
uint32_t EMSESP::last_fetch_ = 0;
AsyncWebServer webServer(80);
@@ -78,10 +84,6 @@ uuid::log::Logger EMSESP::logger() {
return logger_;
}
#ifndef EMSESP_STANDALONE
uuid::syslog::SyslogService System::syslog_;
#endif
// The services
RxService EMSESP::rxservice_; // incoming Telegram Rx handler
TxService EMSESP::txservice_; // outgoing Telegram Tx handler

View File

@@ -72,6 +72,9 @@
#include "command.h"
#include "../emsesp_version.h"
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
// Load external modules
class Module {}; // forward declaration
@@ -220,8 +223,11 @@ class EMSESP {
static void scan_devices();
static void clear_all_devices();
#ifndef EMSESP_STANDALONE
static std::vector<std::unique_ptr<EMSdevice>, AllocatorPSRAM<std::unique_ptr<EMSdevice>>> emsdevices;
#else
static std::vector<std::unique_ptr<EMSdevice>> emsdevices;
#endif
// services
static Mqtt mqtt_;
static Modbus * modbus_;
@@ -266,8 +272,11 @@ class EMSESP {
const char * default_name;
uint8_t flags;
};
#ifndef EMSESP_STANDALONE
static std::vector<Device_record, AllocatorPSRAM<Device_record>> device_library_;
#else
static std::vector<Device_record> device_library_;
#endif
static uint16_t watch_id_;
static uint8_t watch_;
static uint16_t read_id_;

View File

@@ -83,15 +83,24 @@ const char * const languages[] = {EMSESP_LOCALE_EN,
static constexpr uint8_t NUM_LANGUAGES = sizeof(languages) / sizeof(const char *);
#ifndef EMSESP_STANDALONE
uuid::syslog::SyslogService System::syslog_;
#endif
uuid::log::Logger System::logger_{F_(system), uuid::log::Facility::KERN};
// init statics
PButton System::myPButton_;
bool System::test_set_all_active_ = false;
uint32_t System::max_alloc_mem_;
uint32_t System::heap_mem_;
PButton System::myPButton_;
bool System::test_set_all_active_ = false;
uint32_t System::max_alloc_mem_;
uint32_t System::heap_mem_;
#ifndef EMSESP_STANDALONE
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::valid_system_gpios_;
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::used_gpios_;
#else
std::vector<uint8_t> System::valid_system_gpios_;
std::vector<uint8_t> System::used_gpios_;
#endif
// find the index of the language
// 0 = EN, 1 = DE, etc...
@@ -366,21 +375,19 @@ void System::syslog_init() {
#ifndef EMSESP_STANDALONE
if (syslog_enabled_) {
// start & configure syslog
EMSESP::logger().info("Starting Syslog service");
syslog_.start();
syslog_.log_level((uuid::log::Level)syslog_level_);
syslog_.mark_interval(syslog_mark_interval_);
syslog_.destination(syslog_host_.c_str(), syslog_port_);
syslog_.hostname(hostname().c_str());
syslog_.hostname(hostname());
EMSESP::logger().info("Starting Syslog service");
} else if (syslog_.started()) {
// in case service is still running, this flushes the queue
// https://github.com/emsesp/EMS-ESP/issues/496
EMSESP::logger().info("Stopping Syslog");
syslog_.log_level((uuid::log::Level)-1); // stop server
syslog_.loop();
syslog_.log_level(uuid::log::Level::OFF); // stop server
syslog_.mark_interval(0);
syslog_.destination("");
// syslog_.destination("");
}
if (Mqtt::publish_single()) {
if (Mqtt::publish_single2cmd()) {
@@ -1638,7 +1645,8 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
});
// NTP status
node = output["ntp"].to<JsonObject>();
node = output["ntp"].to<JsonObject>();
node["NTPstatus"] = EMSESP::system_.ntp_connected() ? "connected" : "disconnected";
EMSESP::esp32React.getNTPSettingsService()->read([&](const NTPSettings & settings) {
#ifndef EMSESP_STANDALONE
node["enabled"] = settings.enabled;
@@ -2270,8 +2278,13 @@ uint8_t System::systemStatus() {
}
// takes a string range like "6-11, 1, 23, 24-48" which has optional ranges and single values and converts to a vector of ints
#ifndef EMSESP_STANDALONE
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::string_range_to_vector(const std::string & range) {
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> gpios;
#else
std::vector<uint8_t> System::string_range_to_vector(const std::string & range) {
std::vector<uint8_t> gpios;
std::vector<uint8_t> gpios;
#endif
std::string::size_type pos = 0;
std::string::size_type prev = 0;

View File

@@ -31,6 +31,7 @@
#include <esp_wifi.h>
#include <ETH.h>
#include <uuid/syslog.h>
#include <esp32-psram.h>
#endif
#include <uuid/log.h>
@@ -394,11 +395,17 @@ class System {
void led_monitor();
void system_check();
#ifndef EMSESP_STANDALONE
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range);
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> used_gpios_; // list of GPIOs used by the application
#else
static std::vector<uint8_t> string_range_to_vector(const std::string & range);
static std::vector<uint8_t> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used
static std::vector<uint8_t> used_gpios_; // list of GPIOs used by the application
#endif
int8_t wifi_quality(int8_t dBm);
uint8_t healthcheck_ = HEALTHCHECK_NO_NETWORK | HEALTHCHECK_NO_BUS; // start with all flags set, no wifi and no ems bus connection

View File

@@ -31,6 +31,9 @@
#endif
#include "helpers.h"
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
#define MAX_RX_TELEGRAMS 100 // size of Rx queue
#define MAX_TX_TELEGRAMS 160 // size of Tx queue
@@ -287,7 +290,11 @@ class RxService : public EMSbus {
}
};
#ifndef EMSESP_STANDALONE
std::deque<QueuedRxTelegram, AllocatorPSRAM<QueuedRxTelegram>> queue() const {
#else
std::deque<QueuedRxTelegram> queue() const {
#endif
return rx_telegrams_;
}
@@ -298,7 +305,11 @@ class RxService : public EMSbus {
uint32_t telegram_count_ = 0; // # Rx received
uint32_t telegram_error_count_ = 0; // # Rx CRC errors
std::shared_ptr<const Telegram> rx_telegram; // the incoming Rx telegram
std::deque<QueuedRxTelegram> rx_telegrams_; // the Rx Queue
#ifndef EMSESP_STANDALONE
std::deque<QueuedRxTelegram, AllocatorPSRAM<QueuedRxTelegram>> rx_telegrams_; // the Rx Queue
#else
std::deque<QueuedRxTelegram> rx_telegrams_; // the Rx Queue
#endif
};
class TxService : public EMSbus {
@@ -419,7 +430,11 @@ class TxService : public EMSbus {
}
};
#ifndef EMSESP_STANDALONE
std::deque<QueuedTxTelegram, AllocatorPSRAM<QueuedTxTelegram>> queue() const {
#else
std::deque<QueuedTxTelegram> queue() const {
#endif
return tx_telegrams_;
}
@@ -431,7 +446,11 @@ class TxService : public EMSbus {
static constexpr uint32_t POST_SEND_DELAY = 2000;
private:
#ifndef EMSESP_STANDALONE
std::deque<QueuedTxTelegram, AllocatorPSRAM<QueuedTxTelegram>> tx_telegrams_; // the Tx queue
#else
std::deque<QueuedTxTelegram> tx_telegrams_; // the Tx queue
#endif
uint32_t telegram_read_count_ = 0; // # Tx successful reads
uint32_t telegram_write_count_ = 0; // # Tx successful writes

View File

@@ -29,6 +29,7 @@
#ifndef EMSESP_STANDALONE
#include <OneWire.h>
#include <esp32-psram.h>
#endif
namespace emsesp {
@@ -94,7 +95,11 @@ class TemperatureSensor {
bool get_value_info(JsonObject output, const char * cmd, const int8_t id = -1);
// return back reference to the sensor list, used by other classes
#ifndef EMSESP_STANDALONE
std::vector<Sensor, AllocatorPSRAM<Sensor>> sensors() const {
#else
std::vector<Sensor> sensors() const {
#endif
return sensors_;
}
@@ -165,15 +170,16 @@ class TemperatureSensor {
void get_value_json(JsonObject output, const Sensor & sensor);
void remove_ha_topic(const std::string & id);
std::vector<Sensor> sensors_; // our list of active sensors
#ifndef EMSESP_STANDALONE
std::vector<Sensor, AllocatorPSRAM<Sensor>> sensors_; // our list of active sensors
OneWire bus_;
uint32_t last_activity_ = uuid::get_uptime();
State state_ = State::IDLE;
int8_t scancnt_ = SCAN_START;
uint8_t firstscan_ = 0;
int8_t scanretry_ = 0;
#else
std::vector<Sensor> sensors_; // our list of active sensors
#endif
uint8_t dallas_gpio_ = 0;

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.3-dev.34"
#define EMSESP_APP_VERSION "3.7.3-dev.35"

View File

@@ -16,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../core/telegram.h"
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
#ifndef WebCustomEntityService_h
#define WebCustomEntityService_h
@@ -45,7 +48,11 @@ class CustomEntityItem {
class WebCustomEntity {
public:
#ifndef EMSESP_STANDALONE
std::list<CustomEntityItem, AllocatorPSRAM<CustomEntityItem>> customEntityItems;
#else
std::list<CustomEntityItem> customEntityItems;
#endif
static void read(WebCustomEntity & webEntity, JsonObject root);
static StateUpdateResult update(JsonObject root, WebCustomEntity & webEntity);
@@ -82,8 +89,11 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
void getEntities(AsyncWebServerRequest * request);
#ifndef EMSESP_STANDALONE
std::list<CustomEntityItem, AllocatorPSRAM<CustomEntityItem>> * customEntityItems_; // pointer to the list of entity items
#else
std::list<CustomEntityItem> * customEntityItems_; // pointer to the list of entity items
#endif
bool ha_registered_ = false;
};

View File

@@ -18,6 +18,9 @@
#ifndef WebCustomizationService_h
#define WebCustomizationService_h
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
#define EMSESP_CUSTOMIZATION_FILE "/config/emsespCustomization.json"
@@ -70,11 +73,17 @@ class EntityCustomization {
class WebCustomization {
public:
#ifndef EMSESP_STANDALONE
std::list<SensorCustomization, AllocatorPSRAM<SensorCustomization>> sensorCustomizations; // for sensor names and offsets
std::list<AnalogCustomization, AllocatorPSRAM<AnalogCustomization>> analogCustomizations; // for analog sensors
std::list<EntityCustomization, AllocatorPSRAM<EntityCustomization>> entityCustomizations; // for a list of entities that have a special mask set
#else
std::list<SensorCustomization> sensorCustomizations; // for sensor names and offsets
std::list<AnalogCustomization> analogCustomizations; // for analog sensors
std::list<EntityCustomization> entityCustomizations; // for a list of entities that have a special mask set
static void read(WebCustomization & customizations, JsonObject root);
static StateUpdateResult update(JsonObject root, WebCustomization & customizations);
#endif
static void read(WebCustomization & customizations, JsonObject root);
static StateUpdateResult update(JsonObject root, WebCustomization & customizations);
private:
static bool _start;

View File

@@ -21,6 +21,9 @@
#define EMSESP_EVENT_SOURCE_LOG_PATH "/es/log"
#define EMSESP_LOG_SETTINGS_PATH "/rest/logSettings"
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
using ::uuid::console::Shell;
@@ -65,12 +68,16 @@ class WebLogService : public uuid::log::Handler {
char * messagetime(char * out, const uint64_t t, const size_t bufsize);
size_t maximum_log_messages_ = MAX_LOG_MESSAGES; // Maximum number of log messages to buffer before they are output
size_t limit_log_messages_ = 1; // dynamic limit
unsigned long log_message_id_ = 0; // The next identifier to use for queued log messages
unsigned long log_message_id_tail_ = 0; // last event shown on the screen after fetch
std::deque<QueuedLogMessage> log_messages_; // Queued log messages, in the order they were received
bool compact_ = true;
#ifndef EMSESP_STANDALONE
std::deque<QueuedLogMessage, AllocatorPSRAM<QueuedLogMessage>> log_messages_; // Queued log messages, in the order they were received
#else
std::deque<QueuedLogMessage> log_messages_; // Queued log messages, in the order they were received
#endif
size_t maximum_log_messages_ = MAX_LOG_MESSAGES; // Maximum number of log messages to buffer before they are output
size_t limit_log_messages_ = 1; // dynamic limit
unsigned long log_message_id_ = 0; // The next identifier to use for queued log messages
unsigned long log_message_id_tail_ = 0; // last event shown on the screen after fetch
bool compact_ = true;
};
} // namespace emsesp

View File

@@ -16,6 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EMSESP_STANDALONE
#include <esp32-psram.h>
#endif
#ifndef WebSchedulerService_h
#define WebSchedulerService_h
@@ -63,8 +67,11 @@ class ScheduleItem {
class WebScheduler {
public:
#ifndef EMSESP_STANDALONE
std::list<ScheduleItem, AllocatorPSRAM<ScheduleItem>> scheduleItems;
#else
std::list<ScheduleItem> scheduleItems;
#endif
static void read(WebScheduler & webScheduler, JsonObject root);
static StateUpdateResult update(JsonObject root, WebScheduler & webScheduler);
};
@@ -104,10 +111,15 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
HttpEndpoint<WebScheduler> _httpEndpoint;
FSPersistence<WebScheduler> _fsPersistence;
bool ha_registered_ = false;
std::list<ScheduleItem> * scheduleItems_; // pointer to the list of schedule events
bool ha_registered_ = false;
std::deque<ScheduleItem *> cmd_changed_;
#ifndef EMSESP_STANDALONE
std::list<ScheduleItem, AllocatorPSRAM<ScheduleItem>> * scheduleItems_; // pointer to the list of schedule events
std::list<ScheduleItem *, AllocatorPSRAM<ScheduleItem *>> cmd_changed_; // pointer to commands in list that are triggert by change
#else
std::list<ScheduleItem> * scheduleItems_; // pointer to the list of schedule events
std::list<ScheduleItem *> cmd_changed_; // pointer to commands in list that are triggert by change
#endif
};
} // namespace emsesp