mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
rename gpio to pin command - #445
This commit is contained in:
@@ -91,7 +91,7 @@ system
|
||||
set wifi password
|
||||
set wifi ssid <name>
|
||||
wifi reconnect
|
||||
gpio <pin> [data]
|
||||
pin <gpio> [data]
|
||||
|
||||
boiler
|
||||
read <type ID>
|
||||
@@ -150,9 +150,9 @@ commands must be written as `{"cmd":<cmd> ,"data":<data>, "id":<n> }`. The `id`
|
||||
holiday <dd.mm.yyyy-dd.mm.yyyy>
|
||||
date <NTP | hh:mm:ss-dd.mm.yyyy-dw-dst>
|
||||
|
||||
*cmd*
|
||||
*system_cmd*
|
||||
send <"0B XX XX ..">
|
||||
gpio <0 | 1> <0-3> (for D0-D3)
|
||||
pin <gpio> <on|off|1|0|true|false>
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ MAKE_PSTR_WORD(heartbeat)
|
||||
MAKE_PSTR_WORD(users)
|
||||
MAKE_PSTR_WORD(master)
|
||||
MAKE_PSTR_WORD(test)
|
||||
MAKE_PSTR_WORD(gpio)
|
||||
MAKE_PSTR_WORD(pin)
|
||||
|
||||
// for commands
|
||||
MAKE_PSTR_WORD(call)
|
||||
@@ -104,7 +104,7 @@ MAKE_PSTR(degrees, "°C")
|
||||
MAKE_PSTR(asterisks, "********")
|
||||
MAKE_PSTR(n_mandatory, "<n>")
|
||||
MAKE_PSTR(n_optional, "[n]")
|
||||
MAKE_PSTR(pin_mandatory, "<pin>")
|
||||
MAKE_PSTR(gpio_mandatory, "<gpio>")
|
||||
MAKE_PSTR(data_optional, "[data]")
|
||||
MAKE_PSTR(typeid_mandatory, "<type ID>")
|
||||
MAKE_PSTR(deviceid_mandatory, "<device ID>")
|
||||
|
||||
@@ -432,7 +432,7 @@ void Mqtt::on_connect() {
|
||||
// add the system MQTT subscriptions, only if its a fresh start with no previous subscriptions
|
||||
// these commands respond to the topic "system_cmd" and take a payload like {cmd:"", data:"", id:""}
|
||||
if (mqtt_subfunctions_.empty()) {
|
||||
add_command(EMSdevice::DeviceType::SERVICEKEY, F("gpio"), System::mqtt_command_gpio);
|
||||
add_command(EMSdevice::DeviceType::SERVICEKEY, F("pin"), System::mqtt_command_pin);
|
||||
add_command(EMSdevice::DeviceType::SERVICEKEY, F("send"), System::mqtt_command_send);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,20 +36,12 @@ bool System::upload_status_ = false;
|
||||
|
||||
// send on/off to a gpio pin
|
||||
// value: true = HIGH, false = LOW
|
||||
void System::mqtt_command_gpio(const char * value, const int8_t id) {
|
||||
#if defined(ESP8266)
|
||||
const uint8_t pins[] = {16, 5, 4, 0};
|
||||
#elif defined(ESP32)
|
||||
const uint8_t pins[] = {26, 22, 21, 17};
|
||||
#else
|
||||
const uint8_t pins[] = {11, 12, 13, 14};
|
||||
#endif
|
||||
void System::mqtt_command_pin(const char * value, const int8_t id) {
|
||||
bool v = false;
|
||||
if (Helpers::value2bool(value, v)) {
|
||||
uint8_t gpio = pins[id]; // D0 - D3
|
||||
pinMode(gpio, OUTPUT);
|
||||
digitalWrite(gpio, v);
|
||||
LOG_INFO(F("Port D%d set to %s"), id, v ? "HIGH" : "LOW");
|
||||
pinMode(id, OUTPUT);
|
||||
digitalWrite(id, v);
|
||||
LOG_INFO(F("GPIO %d set to %s"), id, v ? "HIGH" : "LOW");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,8 +551,8 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
||||
|
||||
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
||||
CommandFlags::ADMIN,
|
||||
flash_string_vector{F_(gpio)},
|
||||
flash_string_vector{F_(pin_mandatory), F_(data_optional)},
|
||||
flash_string_vector{F_(pin)},
|
||||
flash_string_vector{F_(gpio_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"));
|
||||
@@ -568,7 +560,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
||||
}
|
||||
int pin = 0;
|
||||
if (Helpers::value2number(arguments[0].c_str(), pin)) {
|
||||
System::mqtt_command_gpio(arguments[1].c_str(), pin);
|
||||
System::mqtt_command_pin(arguments[1].c_str(), pin);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class System {
|
||||
|
||||
static void console_commands(Shell & shell, unsigned int context);
|
||||
|
||||
static void mqtt_command_gpio(const char * value, const int8_t id);
|
||||
static void mqtt_command_pin(const char * value, const int8_t id);
|
||||
static void mqtt_command_send(const char * value, const int8_t id);
|
||||
|
||||
static uint8_t free_mem();
|
||||
|
||||
@@ -480,15 +480,15 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
||||
EMSESP::txservice_.flush_tx_queue();
|
||||
}
|
||||
|
||||
if (command == "gpio") {
|
||||
shell.printfln(F("Testing gpio..."));
|
||||
if (command == "pin") {
|
||||
shell.printfln(F("Testing pin..."));
|
||||
|
||||
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.invoke_command("pin");
|
||||
shell.invoke_command("pin 1 true");
|
||||
|
||||
shell.loop_all();
|
||||
}
|
||||
@@ -550,12 +550,12 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
||||
strcpy(payload, "{\"cmd\":\"flowtemp\",\"data\":55}");
|
||||
EMSESP::mqtt_.incoming(topic, payload);
|
||||
|
||||
strcpy(topic, "ems-esp/system");
|
||||
strcpy(topic, "ems-esp/system_cmd");
|
||||
strcpy(payload, "{\"cmd\":\"send\",\"data\":\"01 02 03 04 05\"}");
|
||||
EMSESP::mqtt_.incoming(topic, payload);
|
||||
|
||||
strcpy(topic, "ems-esp/system");
|
||||
strcpy(payload, "{\"cmd\":\"gpio\",\"id\":1,\"data\":\"1\"}");
|
||||
strcpy(topic, "ems-esp/system_cmd");
|
||||
strcpy(payload, "{\"cmd\":\"pin\",\"id\":12,\"data\":\"1\"}");
|
||||
EMSESP::mqtt_.incoming(topic, payload);
|
||||
|
||||
strcpy(topic, "ems-esp/thermostat_cmd");
|
||||
|
||||
Reference in New Issue
Block a user