diff --git a/src/console.cpp b/src/console.cpp index 71be1fc13..fc193179c 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -718,7 +718,7 @@ void Console::load_system_commands(unsigned int context) { [](Shell & shell, const std::vector & arguments) { if (arguments.size() == 0) { EMSESP::webSettingsService.read([&](WebSettings & settings) { - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { if (!settings.sensor[i].id.isEmpty()) { shell.print(settings.sensor[i].id); shell.print(" : "); diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index a53cbff6a..1a8e96b7a 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -313,7 +313,7 @@ std::string DallasSensor::Sensor::to_string(const bool name) const { std::string str = id_string(); EMSESP::webSettingsService.read([&](WebSettings & settings) { if (settings.dallas_format == Dallas_Format::NAME || name) { - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) { str = settings.sensor[i].name.c_str(); } @@ -328,7 +328,7 @@ int16_t DallasSensor::Sensor::offset() const { std::string str = id_string(); int16_t offset = 0; // default value EMSESP::webSettingsService.read([&](WebSettings & settings) { - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) { offset = settings.sensor[i].offset; } @@ -376,7 +376,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset) EMSESP::webSettingsService.update( [&](WebSettings & settings) { // check for new name of stored id - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { if (strcmp(id, settings.sensor[i].id.c_str()) == 0) { if (strlen(name) == 0 && offset == 0) { // delete entry if name and offset is empty LOG_INFO(F("Deleting entry for sensor %s"), id); @@ -397,7 +397,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset) } // check for free place - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { if (settings.sensor[i].id.isEmpty()) { settings.sensor[i].id = id; settings.sensor[i].name = (strlen(name) == 0) ? id : name; @@ -410,7 +410,7 @@ bool DallasSensor::update(const char * idstr, const char * name, int16_t offset) } // check if there is a unused id and overwrite it - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { bool found = false; for (const auto & sensor : sensors_) { if (strcmp(sensor.id_string().c_str(), settings.sensor[i].id.c_str()) == 0) { diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index 1c223019a..5af677f52 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -67,7 +67,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { root["weblog_buffer"] = settings.weblog_buffer; root["weblog_compact"] = settings.weblog_compact; - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { char buf[20]; snprintf(buf, sizeof(buf), "sensor_id%d", i); root[buf] = settings.sensor[i].id; @@ -205,7 +205,7 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER; settings.weblog_compact = root["weblog_compact"] | EMSESP_DEFAULT_WEBLOG_COMPACT; - for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) { + for (uint8_t i = 0; i < MAX_NUM_SENSOR_NAMES; i++) { char buf[20]; snprintf(buf, sizeof(buf), "sensor_id%d", i); settings.sensor[i].id = root[buf] | EMSESP_DEFAULT_SENSOR_NAME; diff --git a/src/web/WebSettingsService.h b/src/web/WebSettingsService.h index d0403eff3..dd51f1847 100644 --- a/src/web/WebSettingsService.h +++ b/src/web/WebSettingsService.h @@ -28,7 +28,7 @@ #define EMSESP_SETTINGS_SERVICE_PATH "/rest/emsespSettings" #define EMSESP_BOARD_PROFILE_SERVICE_PATH "/rest/boardProfile" -#define NUM_SENSOR_NAMES 10 +#define MAX_NUM_SENSOR_NAMES 20 namespace emsesp { @@ -71,7 +71,7 @@ class WebSettings { String id; String name; int16_t offset; - } sensor[NUM_SENSOR_NAMES]; + } sensor[MAX_NUM_SENSOR_NAMES]; static void read(WebSettings & settings, JsonObject & root); static StateUpdateResult update(JsonObject & root, WebSettings & settings);