Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
rename gpio to pin command - #445
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Aug 4, 2020
1 parent e8c3b07 commit b2b51b7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ system
set wifi password
set wifi ssid <name>
wifi reconnect
gpio <pin> [data]
pin <gpio> [data]
boiler
read <type ID>
Expand Down Expand Up @@ -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>
```

Expand Down
4 changes: 2 additions & 2 deletions src/locale_EN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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>")
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 7 additions & 15 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -559,16 +551,16 @@ 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"));
return;
}
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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b2b51b7

Please sign in to comment.