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:
Florian authored and GitHub committed 2019-11-04 20:51:29 +01:00
1 parent 81201cf7de
commit 12bd11bbe1
5 files changed
+73 -43

No files matched your search

+42 -37
View File
@@ -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
+4
View File
@@ -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
-3
View File
@@ -579,9 +579,6 @@ void setup()
#ifdef ZsensorTSL2561
setupZsensorTSL2561();
#endif
#ifdef ZactuatorONOFF
setupONOFF();
#endif
#ifdef Zgateway2G
setup2G();
#endif