make ON OFF actuator more flexible (#481)
* make ON OFF actuator more flexible enable to choose the pin when sending the MQTT command * add on off environment example
This commit is contained in:
1 parent
81201cf7de
commit
12bd11bbe1
5 files changed
+73
-43
No files matched your search
+11
-3
@@ -3,13 +3,21 @@
|
||||
This module enables to actuate things by giving to a PIN a HIGH or LOW value corresponding to an MQTT topic.
|
||||
Example usage: Connect a transistor to power a relay, connect a led...
|
||||
|
||||
So as to pilot the pin use the following commands:
|
||||
So as to pilot the pin use the following commands with [simple receiving](../upload/pio.md#api):
|
||||
|
||||
OFF command:
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m OFF`
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF/setOFF -m 15`
|
||||
|
||||
ON command
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m ON`
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF/setON -m 15`
|
||||
|
||||
or with [json receiving](../upload/pio.md#api)
|
||||
|
||||
OFF command:
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"pin":15,"state":0}'`
|
||||
|
||||
ON command
|
||||
`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"pin":15,"state":1}'`
|
||||
|
||||
## FASTLED
|
||||
|
||||
|
||||
+42
-37
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
|
||||
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
Output pin High or Low
|
||||
Output pin defined to High or Low
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
@@ -30,44 +30,49 @@
|
||||
|
||||
#ifdef ZactuatorONOFF
|
||||
|
||||
void setupONOFF(){
|
||||
trc(F("ACTUATOR_ONOFF_PIN"));
|
||||
trc(ACTUATOR_ONOFF_PIN);
|
||||
//init
|
||||
pinMode(ACTUATOR_ONOFF_PIN, OUTPUT);
|
||||
trc(F("Set to OFF"));
|
||||
digitalWrite(ACTUATOR_ONOFF_PIN, LOW);
|
||||
trc(F("ZactuatorONOFF setup done "));
|
||||
}
|
||||
|
||||
void MQTTtoONOFF(char * topicOri, char * datacallback){
|
||||
#ifdef jsonReceiving
|
||||
void MQTTtoONOFF(char * topicOri, JsonObject& ONOFFdata){
|
||||
|
||||
int boolSWITCHTYPE;
|
||||
if (strcmp(datacallback, "ON") == 0) boolSWITCHTYPE = 1;
|
||||
if (strcmp(datacallback, "OFF") == 0) boolSWITCHTYPE = 0;
|
||||
|
||||
if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){
|
||||
trc(F("MQTTtoONOFF data analysis"));
|
||||
if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){
|
||||
trc(F("MQTTtoONOFF json data analysis"));
|
||||
int boolSWITCHTYPE = ONOFFdata["state"] | 99;
|
||||
int pin = ONOFFdata["pin"] | ACTUATOR_ONOFF_PIN;
|
||||
if (boolSWITCHTYPE != 99) {
|
||||
trc(F("MQTTtoONOFF boolSWITCHTYPE ok"));
|
||||
trc(boolSWITCHTYPE);
|
||||
digitalWrite(ACTUATOR_ONOFF_PIN, boolSWITCHTYPE);
|
||||
trc(F("pin number"));
|
||||
trc(pin);
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, boolSWITCHTYPE);
|
||||
// we acknowledge the sending by publishing the value to an acknowledgement topic
|
||||
pub(subjectGTWONOFFtoMQTT, datacallback);
|
||||
}
|
||||
}
|
||||
void MQTTtoONOFF(char * topicOri, JsonObject& ONOFFdata){
|
||||
|
||||
if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){
|
||||
trc(F("MQTTtoONOFF json data analysis"));
|
||||
int boolSWITCHTYPE = ONOFFdata["switchType"] | 99;
|
||||
if (boolSWITCHTYPE != 99) {
|
||||
trc(F("MQTTtoONOFF boolSWITCHTYPE ok"));
|
||||
trc(boolSWITCHTYPE);
|
||||
digitalWrite(ACTUATOR_ONOFF_PIN, boolSWITCHTYPE);
|
||||
// we acknowledge the sending by publishing the value to an acknowledgement topic
|
||||
pub(subjectGTWONOFFtoMQTT, ONOFFdata);
|
||||
}else{
|
||||
trc(F("MQTTtoONOFF failed json read"));
|
||||
}
|
||||
pub(subjectGTWONOFFtoMQTT, ONOFFdata);
|
||||
}else{
|
||||
trc(F("MQTTtoONOFF failed json read"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef simpleReceiving
|
||||
void MQTTtoONOFF(char * topicOri, char * datacallback) {
|
||||
if ((strstr(topicOri,subjectMQTTtoONOFF) != NULL) ){
|
||||
|
||||
trc(F("MQTTtoONOFF"));
|
||||
int pin = strtol(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
|
||||
trc(F("pin number"));
|
||||
trc(pin);
|
||||
pinMode(pin, OUTPUT);
|
||||
|
||||
bool ON = false;
|
||||
if (strstr(topicOri,ONKey) != NULL) ON = true;
|
||||
if (strstr(topicOri,OFFKey) != NULL) ON = false;
|
||||
|
||||
digitalWrite(pin, ON);
|
||||
// we acknowledge the sending by publishing the value to an acknowledgement topic
|
||||
pub(subjectGTWONOFFtoMQTT, ON);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -34,7 +34,11 @@ extern void MQTTtoONOFF(char * topicOri, JsonObject& RFdata);
|
||||
#define subjectMQTTtoONOFF Base_Topic Gateway_Name "/commands/MQTTtoONOFF"
|
||||
#define subjectGTWONOFFtoMQTT Base_Topic Gateway_Name "/ONOFFtoMQTT"
|
||||
|
||||
#define ONKey "setON"
|
||||
#define OFFKey "setOFF"
|
||||
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
// default pin, if not set into the MQTT json
|
||||
#ifndef ACTUATOR_ONOFF_PIN
|
||||
#ifdef ESP8266
|
||||
#define ACTUATOR_ONOFF_PIN 15 //12 for sonoff basic relay
|
||||
|
||||
@@ -579,9 +579,6 @@ void setup()
|
||||
#ifdef ZsensorTSL2561
|
||||
setupZsensorTSL2561();
|
||||
#endif
|
||||
#ifdef ZactuatorONOFF
|
||||
setupONOFF();
|
||||
#endif
|
||||
#ifdef Zgateway2G
|
||||
setup2G();
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
default_envs =
|
||||
esp32dev-ble-1
|
||||
esp32dev-ble-2
|
||||
env:nodemcuv2-ONOFFPILIGHT
|
||||
|
||||
;esp32 1
|
||||
[env:esp32dev-ble-1]
|
||||
@@ -41,3 +42,18 @@ upload_flags =
|
||||
--auth=OTAPASSWORD
|
||||
upload_speed = 512000
|
||||
monitor_speed = 115200
|
||||
|
||||
[env:nodemcuv2-ONOFFPILIGHT]
|
||||
platform = ${com.esp8266_platform}
|
||||
board = nodemcuv2
|
||||
lib_deps =
|
||||
${com-esp.lib_deps}
|
||||
${libraries.esppilight}
|
||||
${libraries.esp8266_mdns}
|
||||
${libraries.wire}
|
||||
build_flags =
|
||||
${com-esp.build_flags}
|
||||
'-DZgatewayPilight="Pilight"'
|
||||
'-DZactuatorONOFF="ONOFF"'
|
||||
'-DGateway_Name="OpenMQTTGateway_ESP8266_ONOFFRF"'
|
||||
board_build.flash_mode = dout
|
||||
Reference in new issue
Block a user