Added JSON info to doc and multiple relay control.
This commit is contained in:
parent
97c1a2245b
commit
7acc537c7a
@ -16,6 +16,12 @@ Examples
|
|||||||
1. 4 relays at all, relay 2 will be toggled: `http://[device-ip]/relays?toggle=0,1,0,0`
|
1. 4 relays at all, relay 2 will be toggled: `http://[device-ip]/relays?toggle=0,1,0,0`
|
||||||
2. 3 relays at all, relay 1&3 will be switched on: `http://[device-ip]/relays?switch=1,0,1`
|
2. 3 relays at all, relay 1&3 will be switched on: `http://[device-ip]/relays?switch=1,0,1`
|
||||||
|
|
||||||
|
## JSON API
|
||||||
|
You can switch relay state using the following JSON object transmitted to: `http://[device-ip]/json`
|
||||||
|
|
||||||
|
Switch relay 0 on: `{MultiRelay:{relay:0,on:true}}`
|
||||||
|
Switch relay4 3 & 4 off: `{"MultiRelay":[{"relay":2,"on":false},{"relay":3,"on":false}]}`
|
||||||
|
|
||||||
## MQTT API
|
## MQTT API
|
||||||
|
|
||||||
wled/deviceMAC/relay/0/command on|off|toggle
|
wled/deviceMAC/relay/0/command on|off|toggle
|
||||||
|
@ -443,6 +443,13 @@ class MultiRelay : public Usermod {
|
|||||||
if (usermod["on"].is<bool>() && usermod[FPSTR(_relay_str)].is<int>() && usermod[FPSTR(_relay_str)].as<int>()>=0) {
|
if (usermod["on"].is<bool>() && usermod[FPSTR(_relay_str)].is<int>() && usermod[FPSTR(_relay_str)].as<int>()>=0) {
|
||||||
switchRelay(usermod[FPSTR(_relay_str)].as<int>(), usermod["on"].as<bool>());
|
switchRelay(usermod[FPSTR(_relay_str)].as<int>(), usermod["on"].as<bool>());
|
||||||
}
|
}
|
||||||
|
} else if (root[FPSTR(_name)].is<JsonArray>()) {
|
||||||
|
JsonArray relays = root[FPSTR(_name)].as<JsonArray>();
|
||||||
|
for (JsonVariant r : relays) {
|
||||||
|
if (r["on"].is<bool>() && r[FPSTR(_relay_str)].is<int>() && r[FPSTR(_relay_str)].as<int>()>=0) {
|
||||||
|
switchRelay(r[FPSTR(_relay_str)].as<int>(), r["on"].as<bool>());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user