From 4b872bebbe8ca0b8a1a9bab7a17ffa524cf6be12 Mon Sep 17 00:00:00 2001 From: Joseph Perry Date: Wed, 20 Apr 2022 03:55:14 -0400 Subject: [PATCH] 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 --- docs/use/actuators.md | 8 ++++++++ main/ZactuatorONOFF.ino | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/use/actuators.md b/docs/use/actuators.md index 8ec91c5..d9cd24b 100644 --- a/docs/use/actuators.md +++ b/docs/use/actuators.md @@ -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 diff --git a/main/ZactuatorONOFF.ino b/main/ZactuatorONOFF.ino index 4f87efe..f15cd9e 100644 --- a/main/ZactuatorONOFF.ino +++ b/main/ZactuatorONOFF.ino @@ -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));