Add ability to specify pulse length in ZactuatorONOFF (#1200)
* Add ability to specify pulse length in ZactuatorONOFF
Add an additional parameter to the MQTT message to control the actuatorONOFF pulse length e.g. `mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"gpio":15,"cmd":"high_pulse","pulse_length":25}'`
* Simplify initialization of pulselength
This commit is contained in:
1 parent
8d902962e5
commit
4b872bebbe
2 files changed
+14
-2
No files matched your search
@@ -31,6 +31,14 @@ Goes ON for half a second, then back to OFF:
|
||||
Goes OFF for half a second, then back to ON:
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"gpio":15,"cmd":"low_pulse}"'`
|
||||
|
||||
To specify activations other than half a second, include pulse_length and the time in ms.
|
||||
|
||||
Goes ON for 25 ms, then back to OFF:
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"gpio":15,"cmd":"high_pulse","pulse_length":25}'`
|
||||
|
||||
Goes OFF for 25 ms, then back to ON:
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"gpio":15,"cmd":"low_pulse","pulse_length":25}'`
|
||||
|
||||
Be aware that outputs are OFF by default when the board first start.
|
||||
|
||||
## FASTLED
|
||||
|
||||
@@ -47,16 +47,20 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
|
||||
if (ONOFFdata["cmd"] == "high_pulse") {
|
||||
Log.notice(F("MQTTtoONOFF high_pulse ok" CR));
|
||||
Log.notice(F("GPIO number: %d" CR), gpio);
|
||||
int pulselength = ONOFFdata["pulse_length"] | 500;
|
||||
Log.notice(F("Pulse length: %d ms" CR), pulselength);
|
||||
pinMode(gpio, OUTPUT);
|
||||
digitalWrite(gpio, HIGH);
|
||||
delay(500);
|
||||
delay(pulselength);
|
||||
digitalWrite(gpio, LOW);
|
||||
} else if (ONOFFdata["cmd"] == "low_pulse") {
|
||||
Log.notice(F("MQTTtoONOFF low_pulse ok" CR));
|
||||
Log.notice(F("GPIO number: %d" CR), gpio);
|
||||
int pulselength = ONOFFdata["pulse_length"] | 500;
|
||||
Log.notice(F("Pulse length: %d ms" CR), pulselength);
|
||||
pinMode(gpio, OUTPUT);
|
||||
digitalWrite(gpio, LOW);
|
||||
delay(500);
|
||||
delay(pulselength);
|
||||
digitalWrite(gpio, HIGH);
|
||||
} else {
|
||||
Log.error(F("MQTTtoONOFF failed json read" CR));
|
||||
|
||||
Reference in new issue
Block a user