mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 09:19:51 +03:00
Merge branch 'dev' into dev2
This commit is contained in:
@@ -661,7 +661,7 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
|
||||
// this is for a specific sensor
|
||||
// make a copy of the string command for parsing, and lowercase it
|
||||
char sensor_name[COMMAND_MAX_LENGTH] = {'\0'};
|
||||
char * attribute_s = nullptr;
|
||||
char * attribute_s = nullptr;
|
||||
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));
|
||||
|
||||
// check specific attribute to fetch instead of the complete record
|
||||
|
||||
@@ -198,9 +198,17 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
});
|
||||
});
|
||||
|
||||
commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(restart)}, [](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
to_app(shell).system_.system_restart();
|
||||
});
|
||||
commands->add_command(ShellContext::MAIN,
|
||||
CommandFlags::ADMIN,
|
||||
string_vector{F_(restart)},
|
||||
string_vector{F_(partitionname_optional)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
if (arguments.size()) {
|
||||
to_app(shell).system_.system_restart(arguments.front().c_str());
|
||||
} else {
|
||||
to_app(shell).system_.system_restart();
|
||||
}
|
||||
});
|
||||
|
||||
commands->add_command(ShellContext::MAIN,
|
||||
CommandFlags::ADMIN,
|
||||
@@ -238,7 +246,8 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
networkSettings.password = password2.c_str();
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
shell.println("WiFi password updated");
|
||||
shell.println("WiFi password updated. Reconnecting...");
|
||||
to_app(shell).system_.wifi_reconnect();
|
||||
} else {
|
||||
shell.println("Passwords do not match");
|
||||
}
|
||||
@@ -271,7 +280,8 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
networkSettings.ssid = arguments.front().c_str();
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
shell.println("WiFi ssid updated");
|
||||
shell.println("WiFi ssid updated. Reconnecting...");
|
||||
to_app(shell).system_.wifi_reconnect();
|
||||
});
|
||||
|
||||
|
||||
@@ -342,6 +352,43 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
to_app(shell).uart_init();
|
||||
});
|
||||
|
||||
commands->add_command(ShellContext::MAIN,
|
||||
CommandFlags::ADMIN,
|
||||
string_vector{F_(set), F_(service)},
|
||||
string_vector{F_(service_mandatory), F_(enable_mandatory)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
if (arguments.back() == "enable" || arguments.back() == "disable") {
|
||||
bool enable = arguments.back() == "enable";
|
||||
if (arguments.front() == "mqtt") {
|
||||
to_app(shell).esp8266React.getMqttSettingsService()->update([&](MqttSettings & Settings) {
|
||||
Settings.enabled = enable;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (arguments.front() == "ota") {
|
||||
to_app(shell).esp8266React.getOTASettingsService()->update([&](OTASettings & Settings) {
|
||||
Settings.enabled = enable;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (arguments.front() == "ntp") {
|
||||
to_app(shell).esp8266React.getNTPSettingsService()->update([&](NTPSettings & Settings) {
|
||||
Settings.enabled = enable;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (arguments.front() == "ap") {
|
||||
to_app(shell).esp8266React.getAPSettingsService()->update([&](APSettings & Settings) {
|
||||
Settings.provisionMode = enable ? 0 : 2;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else {
|
||||
shell.printfln("unknown service: %s", arguments.front().c_str());
|
||||
return;
|
||||
}
|
||||
shell.printfln("service '%s' %sd", arguments.front().c_str(), arguments.back().c_str());
|
||||
} else {
|
||||
shell.println("Must be `enable` or `disable`");
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// EMS device commands
|
||||
//
|
||||
@@ -594,13 +641,15 @@ void EMSESPShell::stopped() {
|
||||
// show welcome banner
|
||||
void EMSESPShell::display_banner() {
|
||||
println();
|
||||
printfln("┌───────────────────────────────────────┐");
|
||||
printfln("│ %sEMS-ESP version %-12s%s │", COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_BOLD_OFF);
|
||||
printfln("│ %s%shttps://github.com/emsesp/EMS-ESP32%s │", COLOR_BRIGHT_GREEN, COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("│ │");
|
||||
printfln("│ type %shelp%s to show available commands │", COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("│ use %ssu%s to access Admin commands │", COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("└───────────────────────────────────────┘");
|
||||
printfln("┌──────────────────────────────────────────┐");
|
||||
printfln("│ %sEMS-ESP version %-12s%s │", COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_BOLD_OFF);
|
||||
printfln("│ │");
|
||||
printfln("│ %shelp%s to show available commands │", COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("│ %ssu%s to access admin commands │", COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("│ │");
|
||||
printfln("│ %s%shttps://github.com/emsesp/EMS-ESP32%s │", COLOR_BRIGHT_GREEN, COLOR_UNDERLINE, COLOR_RESET);
|
||||
printfln("│ │");
|
||||
printfln("└──────────────────────────────────────────┘");
|
||||
println();
|
||||
|
||||
// set console name
|
||||
|
||||
@@ -239,7 +239,8 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(const ui
|
||||
return heating_circuit;
|
||||
}
|
||||
}
|
||||
LOG_DEBUG("Heating circuit not fond on device 0x%02X", device_id());
|
||||
|
||||
LOG_DEBUG("Heating circuit not found on device 0x%02X", device_id());
|
||||
return nullptr; // not found
|
||||
}
|
||||
|
||||
@@ -3023,7 +3024,7 @@ bool Thermostat::set_controlmode(const char * value, const int8_t id) {
|
||||
}
|
||||
} else if (model() == EMSdevice::EMS_DEVICE_FLAG_RC100) {
|
||||
if (Helpers::value2enum(value, set, FL_(enum_controlmode))) {
|
||||
write_command(curve_typeids[hc->hc()], 0, set, curve_typeids[hc->hc()]);
|
||||
write_command(curve_typeids[hc->hc()], 0, set + 1, curve_typeids[hc->hc()]);
|
||||
return true;
|
||||
}
|
||||
} else if (model() == EMSdevice::EMS_DEVICE_FLAG_BC400 || model() == EMSdevice::EMS_DEVICE_FLAG_RC300) {
|
||||
@@ -4506,9 +4507,11 @@ void Thermostat::register_device_values() {
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(EMSESP_STANDALONE_DUMP)
|
||||
#if defined(EMSESP_STANDALONE)
|
||||
// if we're just dumping out values, create a single dummy hc
|
||||
register_device_values_hc(std::make_shared<Thermostat::HeatingCircuit>(1, this->model())); // hc=1
|
||||
auto new_hc = std::make_shared<Thermostat::HeatingCircuit>(1, this->model()); // hc = 1
|
||||
heating_circuits_.push_back(new_hc);
|
||||
register_device_values_hc(new_hc);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4598,8 +4601,13 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
|
||||
MAKE_CF_CB(set_summermode));
|
||||
register_device_value(tag, &hc->summermode, DeviceValueType::ENUM, FL_(enum_summer), FL_(summermode), DeviceValueUOM::NONE);
|
||||
register_device_value(tag, &hc->hpoperatingstate, DeviceValueType::ENUM, FL_(enum_operatingstate), FL_(hpoperatingstate), DeviceValueUOM::NONE);
|
||||
register_device_value(
|
||||
tag, &hc->controlmode, DeviceValueType::ENUM, FL_(enum_controlmode1), FL_(controlmode), DeviceValueUOM::NONE, MAKE_CF_CB(set_controlmode));
|
||||
if (model == EMSdevice::EMS_DEVICE_FLAG_RC100) {
|
||||
register_device_value(
|
||||
tag, &hc->controlmode, DeviceValueType::ENUM, FL_(enum_controlmode), FL_(controlmode), DeviceValueUOM::NONE, MAKE_CF_CB(set_controlmode));
|
||||
} else {
|
||||
register_device_value(
|
||||
tag, &hc->controlmode, DeviceValueType::ENUM, FL_(enum_controlmode1), FL_(controlmode), DeviceValueUOM::NONE, MAKE_CF_CB(set_controlmode));
|
||||
}
|
||||
register_device_value(tag, &hc->program, DeviceValueType::ENUM, FL_(enum_progMode), FL_(program), DeviceValueUOM::NONE, MAKE_CF_CB(set_program));
|
||||
register_device_value(tag,
|
||||
&hc->tempautotemp,
|
||||
|
||||
@@ -1833,8 +1833,11 @@ bool EMSdevice::handle_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
#if defined(EMSESP_DEBUG)
|
||||
EMSESP::logger().debug("This telegram (%s) is not recognized by the EMS bus", tf.telegram_type_name_);
|
||||
#endif
|
||||
// removing fetch causes issue: https://github.com/emsesp/EMS-ESP32/issues/1420
|
||||
// tf.fetch_ = false;
|
||||
// removing fetch after start causes issue: https://github.com/emsesp/EMS-ESP32/issues/1420
|
||||
// continue retry the first 5 minutes, then disable (added 15.3.2024)
|
||||
if (uuid::get_uptime_sec() > 600) {
|
||||
tf.fetch_ = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (telegram->message_length > 0) {
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
|
||||
#include "emsesp.h"
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
#include "esp_ota_ops.h"
|
||||
#endif
|
||||
|
||||
static_assert(uuid::thread_safe, "uuid-common must be thread-safe");
|
||||
static_assert(uuid::log::thread_safe, "uuid-log must be thread-safe");
|
||||
static_assert(uuid::console::thread_safe, "uuid-console must be thread-safe");
|
||||
@@ -1496,11 +1500,14 @@ void EMSESP::start() {
|
||||
|
||||
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
|
||||
|
||||
if (!nvs_.begin("ems-esp", false, "nvs1")) { // try new partition on 16M flash first
|
||||
nvs_.begin("ems-esp", false, "nvs"); // fallback to first nvs
|
||||
if (!nvs_.begin("ems-esp", false, "nvs1")) { // try bigger nvs partition on 16M flash first
|
||||
nvs_.begin("ems-esp", false, "nvs"); // fallback to small nvs
|
||||
}
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
LOG_INFO("Starting EMS-ESP version %s from partition %s", EMSESP_APP_VERSION, esp_ota_get_running_partition()->label); // welcome message
|
||||
#else
|
||||
LOG_INFO("Starting EMS-ESP version %s", EMSESP_APP_VERSION); // welcome message
|
||||
#endif
|
||||
LOG_DEBUG("System is running in Debug mode");
|
||||
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ MAKE_WORD(users)
|
||||
MAKE_WORD(publish)
|
||||
MAKE_WORD(board_profile)
|
||||
MAKE_WORD(setvalue)
|
||||
MAKE_WORD(service)
|
||||
|
||||
// for commands
|
||||
MAKE_WORD(call)
|
||||
@@ -142,6 +143,7 @@ MAKE_WORD_CUSTOM(asterisks, "********")
|
||||
MAKE_WORD_CUSTOM(n_mandatory, "<n>")
|
||||
MAKE_WORD_CUSTOM(sensorid_optional, "[sensor ID]")
|
||||
MAKE_WORD_CUSTOM(id_optional, "[id|hc]")
|
||||
MAKE_WORD_CUSTOM(partitionname_optional, "[partitionsname]")
|
||||
MAKE_WORD_CUSTOM(data_optional, "[data]")
|
||||
MAKE_WORD_CUSTOM(nvs_optional, "[nvs]")
|
||||
MAKE_WORD_CUSTOM(offset_optional, "[offset]")
|
||||
@@ -157,6 +159,8 @@ MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ")
|
||||
MAKE_WORD_CUSTOM(new_password_prompt2, "Retype new password: ")
|
||||
MAKE_WORD_CUSTOM(password_prompt, "Password: ")
|
||||
MAKE_WORD_CUSTOM(unset, "<unset>")
|
||||
MAKE_WORD_CUSTOM(enable_mandatory, "<enable | disable>")
|
||||
MAKE_WORD_CUSTOM(service_mandatory, "<ota | ap | mqtt | ntp>")
|
||||
|
||||
// more common names that don't need translations
|
||||
MAKE_NOTRANSLATION(1x3min, "1x3min")
|
||||
@@ -327,7 +331,7 @@ MAKE_ENUM(enum_reducemode1, FL_(outdoor), FL_(room), FL_(reduce)) // RC310 value
|
||||
MAKE_ENUM(enum_nofrostmode, FL_(off), FL_(outdoor), FL_(room))
|
||||
MAKE_ENUM(enum_nofrostmode1, FL_(room), FL_(outdoor), FL_(room_outdoor))
|
||||
|
||||
MAKE_ENUM(enum_controlmode, FL_(off), FL_(optimized), FL_(simple), FL_(mpc), FL_(room), FL_(power), FL_(constant))
|
||||
MAKE_ENUM(enum_controlmode, FL_(optimized), FL_(simple), FL_(na), FL_(room), FL_(power))
|
||||
MAKE_ENUM(enum_controlmode1, FL_(weather_compensated), FL_(outside_basepoint), FL_(na), FL_(room), FL_(power), FL_(constant)) // RC310 1-4
|
||||
MAKE_ENUM(enum_controlmode2, FL_(outdoor), FL_(room))
|
||||
MAKE_ENUM(enum_controlmode3, FL_(off), FL_(unmixed), FL_(unmixedIPM), FL_(mixed))
|
||||
|
||||
@@ -264,12 +264,40 @@ void System::store_nvs_values() {
|
||||
}
|
||||
|
||||
// restart EMS-ESP
|
||||
void System::system_restart() {
|
||||
LOG_INFO("Restarting EMS-ESP...");
|
||||
void System::system_restart(const char * partitionname) {
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (partitionname != nullptr) {
|
||||
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||
if (partition && strcmp(partition->label, partitionname) == 0) {
|
||||
esp_ota_set_boot_partition(partition);
|
||||
} else if (strcmp(esp_ota_get_running_partition()->label, partitionname) != 0) {
|
||||
partition = esp_ota_get_next_update_partition(NULL);
|
||||
if (!partition) {
|
||||
LOG_ERROR("Partition '%s' not found", partitionname);
|
||||
return;
|
||||
}
|
||||
if (strcmp(partition->label, partitionname) != 0 && strcmp(partitionname, "boot") != 0) {
|
||||
partition = esp_ota_get_next_update_partition(partition);
|
||||
if (!partition || strcmp(partition->label, partitionname)) {
|
||||
LOG_ERROR("Partition '%s' not found", partitionname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
uint64_t buffer;
|
||||
esp_partition_read(partition, 0, &buffer, 8);
|
||||
if (buffer == 0xFFFFFFFFFFFFFFFF) { // partition empty
|
||||
LOG_ERROR("Partition '%s' is empty, not bootable", partition->label);
|
||||
return;
|
||||
}
|
||||
esp_ota_set_boot_partition(partition);
|
||||
}
|
||||
LOG_INFO("Restarting EMS-ESP from partition '%s'", partitionname);
|
||||
} else {
|
||||
LOG_INFO("Restarting EMS-ESP...");
|
||||
}
|
||||
store_nvs_values();
|
||||
Shell::loop_all();
|
||||
delay(1000); // wait a second
|
||||
#ifndef EMSESP_STANDALONE
|
||||
ESP.restart();
|
||||
#endif
|
||||
}
|
||||
@@ -462,7 +490,8 @@ void System::button_OnDblClick(PButton & b) {
|
||||
|
||||
// button long press
|
||||
void System::button_OnLongPress(PButton & b) {
|
||||
LOG_NOTICE("Button pressed - long press");
|
||||
LOG_NOTICE("Button pressed - long press - restart other partition");
|
||||
EMSESP::system_.system_restart("boot");
|
||||
}
|
||||
|
||||
// button indefinite press
|
||||
@@ -1517,9 +1546,13 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
|
||||
return true;
|
||||
}
|
||||
|
||||
// restart command - perform a hard reset by setting flag
|
||||
// restart command - perform a hard reset
|
||||
bool System::command_restart(const char * value, const int8_t id) {
|
||||
restart_requested(true);
|
||||
if (value != nullptr && value[0] == '\0') {
|
||||
EMSESP::system_.system_restart(value);
|
||||
} else {
|
||||
EMSESP::system_.system_restart();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class System {
|
||||
std::string reset_reason(uint8_t cpu) const;
|
||||
|
||||
void store_nvs_values();
|
||||
void system_restart();
|
||||
void system_restart(const char * partition = nullptr);
|
||||
void format(uuid::console::Shell & shell);
|
||||
void upload_status(bool in_progress);
|
||||
bool upload_status();
|
||||
|
||||
@@ -378,7 +378,7 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
|
||||
// this is for a specific sensor
|
||||
// make a copy of the string command for parsing, and lowercase it
|
||||
char sensor_name[COMMAND_MAX_LENGTH] = {'\0'};
|
||||
char * attribute_s = nullptr;
|
||||
char * attribute_s = nullptr;
|
||||
strlcpy(sensor_name, Helpers::toLower(cmd).c_str(), sizeof(sensor_name));
|
||||
|
||||
// check for a specific attribute to fetch instead of the complete record
|
||||
|
||||
@@ -301,7 +301,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
|
||||
if (command == "add") {
|
||||
shell.printfln("Testing Adding a device (product_id %d), with all values...", id2);
|
||||
test("add", id1, id2); // e.g. 8 172
|
||||
test("add", id1, id2); // e.g. "test add 0x8 172"
|
||||
shell.invoke_command("show values");
|
||||
ok = true;
|
||||
}
|
||||
@@ -342,13 +342,13 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
AsyncWebServerRequest request;
|
||||
request.method(HTTP_GET);
|
||||
request.url("/api/custom");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/custom/test_custom");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/custom/test_read_only");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/custom/test_ram");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
shell.invoke_command("call custom info");
|
||||
|
||||
#endif
|
||||
@@ -365,7 +365,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
AsyncWebServerRequest request;
|
||||
request.method(HTTP_GET);
|
||||
request.url("/api/scheduler");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
shell.invoke_command("call scheduler info");
|
||||
#endif
|
||||
ok = true;
|
||||
@@ -379,7 +379,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
AsyncWebServerRequest request;
|
||||
request.method(HTTP_GET);
|
||||
request.url("/api/boiler/coldshot");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
#else
|
||||
shell.invoke_command("call boiler coldshot");
|
||||
#endif
|
||||
@@ -777,11 +777,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
AsyncWebServerRequest request;
|
||||
request.method(HTTP_GET);
|
||||
request.url("/api/temperaturesensor/commands");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/temperaturesensor/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/temperaturesensor/01-0203-0405-0607");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
|
||||
ok = true;
|
||||
}
|
||||
@@ -827,12 +827,12 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
AsyncWebServerRequest request;
|
||||
request.method(HTTP_GET);
|
||||
request.url("/api/analogsensor/commands");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/analogsensor/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/analogsensor/test_analog1");
|
||||
request.url("/api/analogsensor/36");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
|
||||
// test renaming it
|
||||
// bool update(uint8_t id, const std::string & name, int16_t offset, float factor, uint8_t uom, uint8_t type);
|
||||
@@ -948,19 +948,19 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
request.method(HTTP_GET);
|
||||
|
||||
request.url("/api/boiler/values");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/wwcirc");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/wwcirc/fullname");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/selburnpow/value");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/wwchargetype/writeable");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/flamecurr/value");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/flamecurr/bad");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
ok = true;
|
||||
}
|
||||
|
||||
@@ -995,7 +995,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(doc, odata);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api/thermostat/wwmode");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
ok = true;
|
||||
}
|
||||
|
||||
@@ -1019,76 +1019,76 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
|
||||
/*
|
||||
requestX.url("/api"); // should fail
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api/thermostat/seltemp");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api/thermostat/mode/auto");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api/thermostat"); // check if defaults to info
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
requestX.url("/api/thermostat/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
requestX.url("/api/thermostat/values");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
|
||||
requestX.url("/api/thermostat/mode");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api/system"); // check if defaults to info
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
requestX.url("/api/system/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
requestX.url("/api/thermostat"); // check if defaults to values
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
requestX.url("/api/thermostat/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
requestX.url("/api/thermostat/seltemp");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api/system/restart");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api/temperaturesensor/xxxx");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
emsesp::EMSESP::logger().notice("****");
|
||||
requestX.url("/api/temperaturesensor/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
requestX.url("/api"); // should fail
|
||||
EMSESP::webAPIService.webAPIService_get(&requestX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX);
|
||||
*/
|
||||
|
||||
requestX.method(HTTP_POST);
|
||||
@@ -1098,7 +1098,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(docX, dataX);
|
||||
jsonX = docX.as<JsonVariant>();
|
||||
requestX.url("/api");
|
||||
EMSESP::webAPIService.webAPIService_post(&requestX, jsonX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX, jsonX);
|
||||
return;
|
||||
*/
|
||||
|
||||
@@ -1109,7 +1109,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
jsonX = docX.as<JsonVariant>();
|
||||
// requestX.url("/api/system/send");
|
||||
requestX.url("/api/thermostat");
|
||||
EMSESP::webAPIService.webAPIService_post(&requestX, jsonX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX, jsonX);
|
||||
return;
|
||||
*/
|
||||
|
||||
@@ -1118,7 +1118,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(docX, dataX);
|
||||
jsonX = docX.as<JsonVariant>();
|
||||
requestX.url("/api/thermostat/mode/auto"); // should fail
|
||||
EMSESP::webAPIService.webAPIService_post(&requestX, jsonX);
|
||||
EMSESP::webAPIService.webAPIService(&requestX, jsonX);
|
||||
return;
|
||||
*/
|
||||
|
||||
@@ -1185,21 +1185,21 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
request.method(HTTP_GET);
|
||||
|
||||
request.url("/api/thermostat"); // check if defaults to info
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/thermostat/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/thermostat/values");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/thermostat/seltemp");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/system/commands");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/system/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/syspress");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/boiler/wwcurflow");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
|
||||
// POST tests
|
||||
request.method(HTTP_POST);
|
||||
@@ -1211,28 +1211,28 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(doc, data1);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api/thermostat");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
|
||||
// 2
|
||||
char data2[] = "{\"value\":12}";
|
||||
deserializeJson(doc, data2);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api/thermostat/seltemp");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
|
||||
// 3
|
||||
char data3[] = "{\"device\":\"thermostat\", \"cmd\":\"seltemp\",\"value\":13}";
|
||||
deserializeJson(doc, data3);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
|
||||
// 4 - system call
|
||||
char data4[] = "{\"value\":\"0B 88 19 19 02\"}";
|
||||
deserializeJson(doc, data4);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api/system/send");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
|
||||
// 5 - test write value
|
||||
// device=3 cmd=hc2/seltemp value=44
|
||||
@@ -1240,7 +1240,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(doc, data5);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
|
||||
// write value from web - testing hc2/seltemp
|
||||
char data6[] = "{\"id\":2,\"devicevalue\":{\"v\":\"44\",\"u\":1,\"n\":\"hc2 selected room temperature\",\"c\":\"hc2/seltemp\"}";
|
||||
@@ -1254,7 +1254,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(doc, data7);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
|
||||
emsesp::EMSESP::logger().warning("* these next ones should fail *");
|
||||
|
||||
@@ -1270,7 +1270,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
deserializeJson(doc, data9);
|
||||
json = doc.as<JsonVariant>();
|
||||
request.url("/api/thermostat/mode/auto");
|
||||
EMSESP::webAPIService.webAPIService_post(&request, json);
|
||||
EMSESP::webAPIService.webAPIService(&request, json);
|
||||
ok = true;
|
||||
}
|
||||
|
||||
@@ -1811,11 +1811,11 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
// test API
|
||||
AsyncWebServerRequest request;
|
||||
request.url("/api/mixer");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/mixer/hc1/pumpstatus");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
request.url("/api/mixer/wwc2/pumpstatus");
|
||||
EMSESP::webAPIService.webAPIService_get(&request);
|
||||
EMSESP::webAPIService.webAPIService(&request);
|
||||
ok = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.6.5-test.16a"
|
||||
#define EMSESP_APP_VERSION "3.6.5-test.18"
|
||||
|
||||
@@ -24,12 +24,11 @@ uint32_t WebAPIService::api_count_ = 0;
|
||||
uint16_t WebAPIService::api_fails_ = 0;
|
||||
|
||||
WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: _securityManager(securityManager)
|
||||
, _apiHandler(EMSESP_API_SERVICE_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService_post(request, json); }) { // for POSTs
|
||||
server->on(EMSESP_API_SERVICE_PATH, HTTP_GET, [this](AsyncWebServerRequest * request) { webAPIService_get(request); }); // for GETs
|
||||
server->addHandler(&_apiHandler);
|
||||
: _securityManager(securityManager) {
|
||||
// API
|
||||
server->on(EMSESP_API_SERVICE_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); });
|
||||
|
||||
// for settings
|
||||
// settings
|
||||
server->on(GET_SETTINGS_PATH,
|
||||
HTTP_GET,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getSettings(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
@@ -47,31 +46,30 @@ WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * security
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getEntities(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
}
|
||||
|
||||
// HTTP GET
|
||||
// GET /{device}
|
||||
// GET /{device}/{entity}
|
||||
void WebAPIService::webAPIService_get(AsyncWebServerRequest * request) {
|
||||
// has no body JSON so create dummy as empty input object
|
||||
JsonDocument input_doc;
|
||||
JsonObject input = input_doc.to<JsonObject>();
|
||||
parse(request, input);
|
||||
}
|
||||
|
||||
// For HTTP POSTS with an optional JSON body
|
||||
// HTTP_POST | HTTP_PUT | HTTP_PATCH
|
||||
// POST /{device}[/{hc|id}][/{name}]
|
||||
void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVariant json) {
|
||||
// POST|GET /{device}
|
||||
// POST|GET /{device}/{entity}
|
||||
void WebAPIService::webAPIService(AsyncWebServerRequest * request, JsonVariant json) {
|
||||
JsonObject input;
|
||||
// if no body then treat it as a secure GET
|
||||
if (!json.is<JsonObject>()) {
|
||||
webAPIService_get(request);
|
||||
return;
|
||||
if ((request->method() == HTTP_GET) || (!json.is<JsonObject>())) {
|
||||
// HTTP GET
|
||||
JsonDocument input_doc; // has no body JSON so create dummy as empty input object
|
||||
input = input_doc.to<JsonObject>();
|
||||
} else {
|
||||
// HTTP_POST | HTTP_PUT | HTTP_PATCH
|
||||
input = json.as<JsonObject>(); // extract values from the json. these will be used as default values
|
||||
}
|
||||
|
||||
// extract values from the json. these will be used as default values
|
||||
auto && input = json.as<JsonObject>();
|
||||
parse(request, input);
|
||||
}
|
||||
|
||||
#ifdef EMSESP_TEST
|
||||
// for test.cpp so we can invoke GETs to test the API
|
||||
void WebAPIService::webAPIService(AsyncWebServerRequest * request) {
|
||||
JsonDocument input_doc;
|
||||
parse(request, input_doc.to<JsonObject>());
|
||||
}
|
||||
#endif
|
||||
|
||||
// parse the URL looking for query or path parameters
|
||||
// reporting back any errors
|
||||
void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
||||
@@ -84,7 +82,7 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
||||
|
||||
// check for query parameters first, the old style from v2
|
||||
// api?device={device}&cmd={name}&data={value}&id={hc}
|
||||
if (request->url() == "/api") {
|
||||
if (request->url() == EMSESP_API_SERVICE_PATH) {
|
||||
// get the device
|
||||
if (request->hasParam(F_(device))) {
|
||||
input["device"] = request->getParam(F_(device))->value().c_str();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#define WebAPIService_h
|
||||
|
||||
#define EMSESP_API_SERVICE_PATH "/api"
|
||||
|
||||
#define GET_SETTINGS_PATH "/rest/getSettings"
|
||||
#define GET_CUSTOMIZATIONS_PATH "/rest/getCustomizations"
|
||||
#define GET_SCHEDULE_PATH "/rest/getSchedule"
|
||||
@@ -31,8 +32,12 @@ class WebAPIService {
|
||||
public:
|
||||
WebAPIService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||
|
||||
void webAPIService_post(AsyncWebServerRequest * request, JsonVariant json); // for POSTs
|
||||
void webAPIService_get(AsyncWebServerRequest * request); // for GETs
|
||||
void webAPIService(AsyncWebServerRequest * request, JsonVariant json);
|
||||
|
||||
#ifdef EMSESP_TEST
|
||||
// for test.cpp
|
||||
void webAPIService(AsyncWebServerRequest * request);
|
||||
#endif
|
||||
|
||||
static uint32_t api_count() {
|
||||
return api_count_;
|
||||
@@ -43,14 +48,12 @@ class WebAPIService {
|
||||
}
|
||||
|
||||
private:
|
||||
SecurityManager * _securityManager;
|
||||
AsyncCallbackJsonWebHandler _apiHandler; // for POSTs
|
||||
SecurityManager * _securityManager;
|
||||
|
||||
static uint32_t api_count_;
|
||||
static uint16_t api_fails_;
|
||||
|
||||
void parse(AsyncWebServerRequest * request, JsonObject input);
|
||||
|
||||
void getSettings(AsyncWebServerRequest * request);
|
||||
void getCustomizations(AsyncWebServerRequest * request);
|
||||
void getSchedule(AsyncWebServerRequest * request);
|
||||
|
||||
@@ -23,10 +23,7 @@ namespace emsesp {
|
||||
bool WebCustomization::_start = true;
|
||||
|
||||
WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||
: _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE)
|
||||
, _masked_entities_handler(CUSTOMIZATION_ENTITIES_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { customization_entities(request, json); },
|
||||
AuthenticationPredicates::IS_AUTHENTICATED)) {
|
||||
: _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE) {
|
||||
server->on(DEVICE_ENTITIES_PATH,
|
||||
HTTP_GET,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { device_entities(request); }, AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
@@ -39,9 +36,9 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f
|
||||
HTTP_POST,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { reset_customization(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
|
||||
_masked_entities_handler.setMethod(HTTP_POST);
|
||||
_masked_entities_handler.setMaxContentLength(2048);
|
||||
server->addHandler(&_masked_entities_handler);
|
||||
server->on(CUSTOMIZATION_ENTITIES_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { customization_entities(request, json); },
|
||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
}
|
||||
|
||||
// this creates the customization file, saving it to the FS
|
||||
|
||||
@@ -101,8 +101,6 @@ class WebCustomizationService : public StatefulService<WebCustomization> {
|
||||
// POST
|
||||
void customization_entities(AsyncWebServerRequest * request, JsonVariant json);
|
||||
void reset_customization(AsyncWebServerRequest * request); // command
|
||||
|
||||
AsyncCallbackJsonWebHandler _masked_entities_handler;
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -21,16 +21,18 @@
|
||||
namespace emsesp {
|
||||
|
||||
WebDataService::WebDataService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: _write_value_handler(WRITE_DEVICE_VALUE_SERVICE_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_device_value(request, json); },
|
||||
AuthenticationPredicates::IS_ADMIN))
|
||||
, _write_temperature_handler(WRITE_TEMPERATURE_SENSOR_SERVICE_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request,
|
||||
JsonVariant json) { write_temperature_sensor(request, json); },
|
||||
AuthenticationPredicates::IS_ADMIN))
|
||||
, _write_analog_handler(WRITE_ANALOG_SENSOR_SERVICE_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_analog_sensor(request, json); },
|
||||
AuthenticationPredicates::IS_ADMIN)) {
|
||||
|
||||
{
|
||||
// write endpoints
|
||||
server->on(WRITE_DEVICE_VALUE_SERVICE_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_device_value(request, json); },
|
||||
AuthenticationPredicates::IS_ADMIN));
|
||||
server->on(WRITE_TEMPERATURE_SENSOR_SERVICE_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_temperature_sensor(request, json); },
|
||||
AuthenticationPredicates::IS_ADMIN));
|
||||
server->on(WRITE_ANALOG_SENSOR_SERVICE_PATH,
|
||||
securityManager->wrapCallback([this](AsyncWebServerRequest * request, JsonVariant json) { write_analog_sensor(request, json); },
|
||||
AuthenticationPredicates::IS_ADMIN));
|
||||
// GET's
|
||||
server->on(DEVICE_DATA_SERVICE_PATH,
|
||||
HTTP_GET,
|
||||
@@ -49,19 +51,6 @@ WebDataService::WebDataService(AsyncWebServer * server, SecurityManager * securi
|
||||
server->on(SCAN_DEVICES_SERVICE_PATH,
|
||||
HTTP_POST,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { scan_devices(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
|
||||
|
||||
_write_value_handler.setMethod(HTTP_POST);
|
||||
_write_value_handler.setMaxContentLength(256);
|
||||
server->addHandler(&_write_value_handler);
|
||||
|
||||
_write_temperature_handler.setMethod(HTTP_POST);
|
||||
_write_temperature_handler.setMaxContentLength(256);
|
||||
server->addHandler(&_write_temperature_handler);
|
||||
|
||||
_write_analog_handler.setMethod(HTTP_POST);
|
||||
_write_analog_handler.setMaxContentLength(256);
|
||||
server->addHandler(&_write_analog_handler);
|
||||
}
|
||||
|
||||
// scan devices service
|
||||
|
||||
@@ -51,8 +51,6 @@ class WebDataService {
|
||||
void write_temperature_sensor(AsyncWebServerRequest * request, JsonVariant json);
|
||||
void write_analog_sensor(AsyncWebServerRequest * request, JsonVariant json);
|
||||
void scan_devices(AsyncWebServerRequest * request); // command
|
||||
|
||||
AsyncCallbackJsonWebHandler _write_value_handler, _write_temperature_handler, _write_analog_handler;
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -21,17 +21,14 @@
|
||||
namespace emsesp {
|
||||
|
||||
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: events_(EVENT_SOURCE_LOG_PATH)
|
||||
, setValues_(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { setValues(request, json); }) {
|
||||
events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_ADMIN));
|
||||
|
||||
// get settings
|
||||
server->on(LOG_SETTINGS_PATH, HTTP_GET, [this](AsyncWebServerRequest * request) { getValues(request); });
|
||||
: events_(EVENT_SOURCE_LOG_PATH) {
|
||||
// get & set settings
|
||||
server->on(LOG_SETTINGS_PATH, [this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); });
|
||||
|
||||
// for bring back the whole log - is a command, hence a POST
|
||||
server->on(FETCH_LOG_PATH, HTTP_POST, [this](AsyncWebServerRequest * request) { fetchLog(request); });
|
||||
|
||||
server->addHandler(&setValues_);
|
||||
events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_ADMIN));
|
||||
server->addHandler(&events_);
|
||||
}
|
||||
|
||||
@@ -204,11 +201,20 @@ void WebLogService::fetchLog(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
// sets the values like level after a POST
|
||||
void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json) {
|
||||
if (!json.is<JsonObject>()) {
|
||||
void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant json) {
|
||||
if ((request->method() == HTTP_GET) || (!json.is<JsonObject>())) {
|
||||
// GET - return the values
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
root["level"] = log_level();
|
||||
root["max_messages"] = maximum_log_messages();
|
||||
root["compact"] = compact();
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
return;
|
||||
}
|
||||
|
||||
// POST - write the settings
|
||||
auto && body = json.as<JsonObject>();
|
||||
|
||||
uuid::log::Level level = body["level"];
|
||||
@@ -223,15 +229,4 @@ void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json)
|
||||
request->send(200); // OK
|
||||
}
|
||||
|
||||
// return the current value settings after a GET
|
||||
void WebLogService::getValues(AsyncWebServerRequest * request) {
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject root = response->getRoot();
|
||||
root["level"] = log_level();
|
||||
root["max_messages"] = maximum_log_messages();
|
||||
root["compact"] = compact();
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
} // namespace emsesp
|
||||
@@ -60,14 +60,10 @@ class WebLogService : public uuid::log::Handler {
|
||||
|
||||
void transmit(const QueuedLogMessage & message);
|
||||
void fetchLog(AsyncWebServerRequest * request);
|
||||
void getValues(AsyncWebServerRequest * request);
|
||||
void getSetValues(AsyncWebServerRequest * request, JsonVariant json);
|
||||
|
||||
char * messagetime(char * out, const uint64_t t, const size_t bufsize);
|
||||
|
||||
void setValues(AsyncWebServerRequest * request, JsonVariant json);
|
||||
|
||||
AsyncCallbackJsonWebHandler setValues_; // for POSTs
|
||||
|
||||
uint64_t last_transmit_ = 0; // Last transmit time
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user