mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
minor changes, added gpio command - #445
This commit is contained in:
@@ -666,7 +666,7 @@ void Boiler::process_UBAMaintenanceData(std::shared_ptr<const Telegram> telegram
|
|||||||
|
|
||||||
// Set the warm water temperature 0x33
|
// Set the warm water temperature 0x33
|
||||||
void Boiler::set_warmwater_temp(const char * value, const int8_t id) {
|
void Boiler::set_warmwater_temp(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -678,7 +678,7 @@ void Boiler::set_warmwater_temp(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// flow temp
|
// flow temp
|
||||||
void Boiler::set_flow_temp(const char * value, const int8_t id) {
|
void Boiler::set_flow_temp(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -689,7 +689,7 @@ void Boiler::set_flow_temp(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set min boiler output
|
// set min boiler output
|
||||||
void Boiler::set_min_power(const char * value, const int8_t id) {
|
void Boiler::set_min_power(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -699,7 +699,7 @@ void Boiler::set_min_power(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set max temp
|
// set max temp
|
||||||
void Boiler::set_max_power(const char * value, const int8_t id) {
|
void Boiler::set_max_power(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -710,7 +710,7 @@ void Boiler::set_max_power(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set oiler on hysteresis
|
// set oiler on hysteresis
|
||||||
void Boiler::set_hyst_on(const char * value, const int8_t id) {
|
void Boiler::set_hyst_on(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -721,7 +721,7 @@ void Boiler::set_hyst_on(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set boiler off hysteresis
|
// set boiler off hysteresis
|
||||||
void Boiler::set_hyst_off(const char * value, const int8_t id) {
|
void Boiler::set_hyst_off(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -732,7 +732,7 @@ void Boiler::set_hyst_off(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set min burner period
|
// set min burner period
|
||||||
void Boiler::set_burn_period(const char * value, const int8_t id) {
|
void Boiler::set_burn_period(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -743,7 +743,7 @@ void Boiler::set_burn_period(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set pump delay
|
// set pump delay
|
||||||
void Boiler::set_pump_delay(const char * value, const int8_t id) {
|
void Boiler::set_pump_delay(const char * value, const int8_t id) {
|
||||||
uint8_t v = 0;
|
int v = 0;
|
||||||
if (!Helpers::value2number(value, v)) {
|
if (!Helpers::value2number(value, v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1154,7 +1154,7 @@ void Thermostat::console_commands(Shell & shell, unsigned int context) {
|
|||||||
|
|
||||||
// 0xA5 - Set minimum external temperature
|
// 0xA5 - Set minimum external temperature
|
||||||
void Thermostat::set_settings_minexttemp(const char * value, const int8_t id) {
|
void Thermostat::set_settings_minexttemp(const char * value, const int8_t id) {
|
||||||
int8_t mt = 0;
|
int mt = 0;
|
||||||
if (!Helpers::value2number(value, mt)) {
|
if (!Helpers::value2number(value, mt)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1166,7 +1166,7 @@ void Thermostat::set_settings_minexttemp(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// 0xA5 - Clock offset
|
// 0xA5 - Clock offset
|
||||||
void Thermostat::set_settings_clockoffset(const char * value, const int8_t id) {
|
void Thermostat::set_settings_clockoffset(const char * value, const int8_t id) {
|
||||||
int8_t co = 0;
|
int co = 0;
|
||||||
if (!Helpers::value2number(value, co)) {
|
if (!Helpers::value2number(value, co)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1178,7 +1178,7 @@ void Thermostat::set_settings_clockoffset(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// 0xA5 - Calibrate internal temperature
|
// 0xA5 - Calibrate internal temperature
|
||||||
void Thermostat::set_settings_calinttemp(const char * value, const int8_t id) {
|
void Thermostat::set_settings_calinttemp(const char * value, const int8_t id) {
|
||||||
int8_t ct = 0;
|
int ct = 0;
|
||||||
if (!Helpers::value2number(value, ct)) {
|
if (!Helpers::value2number(value, ct)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1192,7 +1192,7 @@ void Thermostat::set_settings_calinttemp(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// 0xA5 - Set the display settings
|
// 0xA5 - Set the display settings
|
||||||
void Thermostat::set_settings_display(const char * value, const int8_t id) {
|
void Thermostat::set_settings_display(const char * value, const int8_t id) {
|
||||||
uint8_t ds = 0;
|
int ds = 0;
|
||||||
if (!Helpers::value2number(value, ds)) {
|
if (!Helpers::value2number(value, ds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1243,7 +1243,7 @@ void Thermostat::set_settings_building(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// 0xA5 Set the language settings
|
// 0xA5 Set the language settings
|
||||||
void Thermostat::set_settings_language(const char * value, const int8_t id) {
|
void Thermostat::set_settings_language(const char * value, const int8_t id) {
|
||||||
uint8_t lg = 0;
|
int lg = 0;
|
||||||
if (!Helpers::value2number(value, lg)) {
|
if (!Helpers::value2number(value, lg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1255,7 +1255,7 @@ void Thermostat::set_settings_language(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// Set the control-mode for hc 0-off, 1-RC20, 2-RC3x
|
// Set the control-mode for hc 0-off, 1-RC20, 2-RC3x
|
||||||
void Thermostat::set_control(const char * value, const int8_t id) {
|
void Thermostat::set_control(const char * value, const int8_t id) {
|
||||||
uint8_t ctrl = 0;
|
int ctrl = 0;
|
||||||
if (!Helpers::value2number(value, ctrl)) {
|
if (!Helpers::value2number(value, ctrl)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1335,7 +1335,7 @@ void Thermostat::set_holiday(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set pause in hours
|
// set pause in hours
|
||||||
void Thermostat::set_pause(const char * value, const int8_t id) {
|
void Thermostat::set_pause(const char * value, const int8_t id) {
|
||||||
uint8_t hrs = 0;
|
int hrs = 0;
|
||||||
if (!Helpers::value2number(value, hrs)) {
|
if (!Helpers::value2number(value, hrs)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1356,7 +1356,7 @@ void Thermostat::set_pause(const char * value, const int8_t id) {
|
|||||||
|
|
||||||
// set partymode in hours
|
// set partymode in hours
|
||||||
void Thermostat::set_party(const char * value, const int8_t id) {
|
void Thermostat::set_party(const char * value, const int8_t id) {
|
||||||
uint8_t hrs = 0;
|
int hrs = 0;
|
||||||
if (!Helpers::value2number(value, hrs)) {
|
if (!Helpers::value2number(value, hrs)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ bool Helpers::hasValue(const uint32_t v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checks if we can convert a char string to an int value
|
// checks if we can convert a char string to an int value
|
||||||
bool Helpers::value2number(const char * v, int value) {
|
bool Helpers::value2number(const char * v, int & value) {
|
||||||
if ((v == nullptr) || (strlen(v) == 0)) {
|
if ((v == nullptr) || (strlen(v) == 0)) {
|
||||||
value = 0;
|
value = 0;
|
||||||
return false;
|
return false;
|
||||||
@@ -364,7 +364,7 @@ bool Helpers::value2number(const char * v, int value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// checks if we can convert a char string to a float value
|
// checks if we can convert a char string to a float value
|
||||||
bool Helpers::value2float(const char * v, float value) {
|
bool Helpers::value2float(const char * v, float & value) {
|
||||||
if ((v == nullptr) || (strlen(v) == 0)) {
|
if ((v == nullptr) || (strlen(v) == 0)) {
|
||||||
value = 0;
|
value = 0;
|
||||||
return false;
|
return false;
|
||||||
@@ -392,22 +392,24 @@ bool Helpers::value2string(const char * v, std::string & value) {
|
|||||||
|
|
||||||
// checks to see if a string (usually a command or payload cmd) looks like a boolean
|
// checks to see if a string (usually a command or payload cmd) looks like a boolean
|
||||||
// on, off, true, false, 1, 0
|
// on, off, true, false, 1, 0
|
||||||
bool Helpers::value2bool(const char * v, uint8_t value) {
|
bool Helpers::value2bool(const char * v, bool & value) {
|
||||||
if ((v == nullptr) || (strlen(v) == 0)) {
|
if ((v == nullptr) || (strlen(v) == 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strncmp(v, "on", 2) == 0) || (strncmp(v, "1", 1) == 0) || (strncmp(v, "true", 4) == 0)) {
|
std::string bool_str = toLower(v); // convert to lower case
|
||||||
|
|
||||||
|
if ((bool_str == "on") || (bool_str == "1") or (bool_str == "true")) {
|
||||||
value = true;
|
value = true;
|
||||||
return true;
|
return true; // is a bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strncmp(v, "off", 3) == 0) || (strncmp(v, "0", 1) == 0) || (strncmp(v, "false", 5) == 0)) {
|
if ((bool_str == "off") || (bool_str == "0") or (bool_str == "false")) {
|
||||||
value = false;
|
value = false;
|
||||||
return true;
|
return true; // is a bool
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false; // not a bool
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ class Helpers {
|
|||||||
|
|
||||||
static std::string toLower(std::string const & s);
|
static std::string toLower(std::string const & s);
|
||||||
|
|
||||||
static bool value2number(const char * v, int value);
|
static bool value2number(const char * v, int & value);
|
||||||
static bool value2float(const char * v, float value);
|
static bool value2float(const char * v, float & value);
|
||||||
static bool value2bool(const char * v, uint8_t value);
|
static bool value2bool(const char * v, bool & value);
|
||||||
static bool value2string(const char * v, std::string & value);
|
static bool value2string(const char * v, std::string & value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ MAKE_PSTR_WORD(heartbeat)
|
|||||||
MAKE_PSTR_WORD(users)
|
MAKE_PSTR_WORD(users)
|
||||||
MAKE_PSTR_WORD(master)
|
MAKE_PSTR_WORD(master)
|
||||||
MAKE_PSTR_WORD(test)
|
MAKE_PSTR_WORD(test)
|
||||||
|
MAKE_PSTR_WORD(gpio)
|
||||||
|
|
||||||
|
// for commands
|
||||||
MAKE_PSTR_WORD(call)
|
MAKE_PSTR_WORD(call)
|
||||||
|
|
||||||
// devices
|
// devices
|
||||||
@@ -81,7 +84,7 @@ MAKE_PSTR_WORD(sensors)
|
|||||||
MAKE_PSTR(kwh, "kWh")
|
MAKE_PSTR(kwh, "kWh")
|
||||||
MAKE_PSTR(wh, "Wh")
|
MAKE_PSTR(wh, "Wh")
|
||||||
MAKE_PSTR(hc_optional, "[heating circuit]")
|
MAKE_PSTR(hc_optional, "[heating circuit]")
|
||||||
MAKE_PSTR(master_thermostat_fmt, "Master Thermostat device ID = %s")
|
MAKE_PSTR(master_thermostat_fmt, "Master Thermostat Device ID = %s")
|
||||||
MAKE_PSTR(host_fmt, "Host = %s")
|
MAKE_PSTR(host_fmt, "Host = %s")
|
||||||
MAKE_PSTR(hostname_fmt, "WiFi Hostname = %s")
|
MAKE_PSTR(hostname_fmt, "WiFi Hostname = %s")
|
||||||
MAKE_PSTR(mark_interval_fmt, "Mark interval = %lus");
|
MAKE_PSTR(mark_interval_fmt, "Mark interval = %lus");
|
||||||
@@ -101,6 +104,7 @@ MAKE_PSTR(degrees, "°C")
|
|||||||
MAKE_PSTR(asterisks, "********")
|
MAKE_PSTR(asterisks, "********")
|
||||||
MAKE_PSTR(n_mandatory, "<n>")
|
MAKE_PSTR(n_mandatory, "<n>")
|
||||||
MAKE_PSTR(n_optional, "[n]")
|
MAKE_PSTR(n_optional, "[n]")
|
||||||
|
MAKE_PSTR(pin_mandatory, "<pin>")
|
||||||
MAKE_PSTR(data_optional, "[data]")
|
MAKE_PSTR(data_optional, "[data]")
|
||||||
MAKE_PSTR(typeid_mandatory, "<type ID>")
|
MAKE_PSTR(typeid_mandatory, "<type ID>")
|
||||||
MAKE_PSTR(deviceid_mandatory, "<device ID>")
|
MAKE_PSTR(deviceid_mandatory, "<device ID>")
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void System::mqtt_command_gpio(const char * value, const int8_t id) {
|
|||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
const uint8_t pins[] = {26, 22, 21, 17};
|
const uint8_t pins[] = {26, 22, 21, 17};
|
||||||
#else
|
#else
|
||||||
const uint8_t pins[] = {0, 1, 2, 3};
|
const uint8_t pins[] = {11, 12, 13, 14};
|
||||||
#endif
|
#endif
|
||||||
bool v = false;
|
bool v = false;
|
||||||
if (Helpers::value2bool(value, v)) {
|
if (Helpers::value2bool(value, v)) {
|
||||||
@@ -557,6 +557,20 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
flash_string_vector{F_(show), F_(users)},
|
flash_string_vector{F_(show), F_(users)},
|
||||||
[](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) { System::show_users(shell); });
|
[](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) { System::show_users(shell); });
|
||||||
|
|
||||||
|
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
||||||
|
CommandFlags::ADMIN,
|
||||||
|
flash_string_vector{F_(gpio)},
|
||||||
|
flash_string_vector{F_(pin_mandatory), F_(data_optional)},
|
||||||
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
|
if (arguments.size() == 1) {
|
||||||
|
shell.printfln(F("use on/off, 1/0 or true/false"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pin = 0;
|
||||||
|
if (Helpers::value2number(arguments[0].c_str(), pin)) {
|
||||||
|
System::mqtt_command_gpio(arguments[1].c_str(), pin);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// enter the context
|
// enter the context
|
||||||
Console::enter_custom_context(shell, context);
|
Console::enter_custom_context(shell, context);
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ class Telegram {
|
|||||||
|
|
||||||
value = 0;
|
value = 0;
|
||||||
for (uint8_t i = 0; i < size; i++) {
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
// shift
|
value = (value << 8) + message_data[abs_index + i]; // shift
|
||||||
value = (value << 8) + message_data[abs_index + i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace emsesp {
|
|||||||
// used with the 'test' command, under su/admin
|
// used with the 'test' command, under su/admin
|
||||||
void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
||||||
if (command == "default") {
|
if (command == "default") {
|
||||||
run_test(shell, "mqtt"); // add the default test case here
|
run_test(shell, "gpio"); // add the default test case here
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.empty()) {
|
if (command.empty()) {
|
||||||
@@ -480,6 +480,19 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
|||||||
EMSESP::txservice_.flush_tx_queue();
|
EMSESP::txservice_.flush_tx_queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command == "gpio") {
|
||||||
|
shell.printfln(F("Testing gpio..."));
|
||||||
|
|
||||||
|
EMSESP::add_context_menus(); // need to add this as it happens later in the code
|
||||||
|
shell.invoke_command("su");
|
||||||
|
shell.invoke_command("system");
|
||||||
|
shell.invoke_command("help");
|
||||||
|
shell.invoke_command("gpio");
|
||||||
|
shell.invoke_command("gpio 1 true");
|
||||||
|
|
||||||
|
shell.loop_all();
|
||||||
|
}
|
||||||
|
|
||||||
if (command == "mqtt") {
|
if (command == "mqtt") {
|
||||||
shell.printfln(F("Testing MQTT..."));
|
shell.printfln(F("Testing MQTT..."));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user