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
+64
-34
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.
|
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...
|
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:
|
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
|
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
|
## FASTLED
|
||||||
|
|
||||||
|
|||||||
+33
-28
@@ -4,7 +4,7 @@
|
|||||||
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
|
Send and receiving command by MQTT
|
||||||
|
|
||||||
Output pin High or Low
|
Output pin defined to High or Low
|
||||||
|
|
||||||
Copyright: (c)Florian ROBERT
|
Copyright: (c)Florian ROBERT
|
||||||
|
|
||||||
@@ -30,44 +30,49 @@
|
|||||||
|
|
||||||
#ifdef ZactuatorONOFF
|
#ifdef ZactuatorONOFF
|
||||||
|
|
||||||
void setupONOFF(){
|
#ifdef jsonReceiving
|
||||||
trc(F("ACTUATOR_ONOFF_PIN"));
|
void MQTTtoONOFF(char * topicOri, JsonObject& ONOFFdata){
|
||||||
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){
|
|
||||||
|
|
||||||
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"));
|
|
||||||
trc(boolSWITCHTYPE);
|
|
||||||
digitalWrite(ACTUATOR_ONOFF_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){
|
if (strcmp(topicOri,subjectMQTTtoONOFF) == 0){
|
||||||
trc(F("MQTTtoONOFF json data analysis"));
|
trc(F("MQTTtoONOFF json data analysis"));
|
||||||
int boolSWITCHTYPE = ONOFFdata["switchType"] | 99;
|
int boolSWITCHTYPE = ONOFFdata["state"] | 99;
|
||||||
|
int pin = ONOFFdata["pin"] | ACTUATOR_ONOFF_PIN;
|
||||||
if (boolSWITCHTYPE != 99) {
|
if (boolSWITCHTYPE != 99) {
|
||||||
trc(F("MQTTtoONOFF boolSWITCHTYPE ok"));
|
trc(F("MQTTtoONOFF boolSWITCHTYPE ok"));
|
||||||
trc(boolSWITCHTYPE);
|
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
|
// we acknowledge the sending by publishing the value to an acknowledgement topic
|
||||||
pub(subjectGTWONOFFtoMQTT, ONOFFdata);
|
pub(subjectGTWONOFFtoMQTT, ONOFFdata);
|
||||||
}else{
|
}else{
|
||||||
trc(F("MQTTtoONOFF failed json read"));
|
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
|
#endif
|
||||||
@@ -34,7 +34,11 @@ extern void MQTTtoONOFF(char * topicOri, JsonObject& RFdata);
|
|||||||
#define subjectMQTTtoONOFF Base_Topic Gateway_Name "/commands/MQTTtoONOFF"
|
#define subjectMQTTtoONOFF Base_Topic Gateway_Name "/commands/MQTTtoONOFF"
|
||||||
#define subjectGTWONOFFtoMQTT Base_Topic Gateway_Name "/ONOFFtoMQTT"
|
#define subjectGTWONOFFtoMQTT Base_Topic Gateway_Name "/ONOFFtoMQTT"
|
||||||
|
|
||||||
|
#define ONKey "setON"
|
||||||
|
#define OFFKey "setOFF"
|
||||||
|
|
||||||
/*-------------------PIN DEFINITIONS----------------------*/
|
/*-------------------PIN DEFINITIONS----------------------*/
|
||||||
|
// default pin, if not set into the MQTT json
|
||||||
#ifndef ACTUATOR_ONOFF_PIN
|
#ifndef ACTUATOR_ONOFF_PIN
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define ACTUATOR_ONOFF_PIN 15 //12 for sonoff basic relay
|
#define ACTUATOR_ONOFF_PIN 15 //12 for sonoff basic relay
|
||||||
|
|||||||
@@ -579,9 +579,6 @@ void setup()
|
|||||||
#ifdef ZsensorTSL2561
|
#ifdef ZsensorTSL2561
|
||||||
setupZsensorTSL2561();
|
setupZsensorTSL2561();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZactuatorONOFF
|
|
||||||
setupONOFF();
|
|
||||||
#endif
|
|
||||||
#ifdef Zgateway2G
|
#ifdef Zgateway2G
|
||||||
setup2G();
|
setup2G();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
default_envs =
|
default_envs =
|
||||||
esp32dev-ble-1
|
esp32dev-ble-1
|
||||||
esp32dev-ble-2
|
esp32dev-ble-2
|
||||||
|
env:nodemcuv2-ONOFFPILIGHT
|
||||||
|
|
||||||
;esp32 1
|
;esp32 1
|
||||||
[env:esp32dev-ble-1]
|
[env:esp32dev-ble-1]
|
||||||
@@ -41,3 +42,18 @@ upload_flags =
|
|||||||
--auth=OTAPASSWORD
|
--auth=OTAPASSWORD
|
||||||
upload_speed = 512000
|
upload_speed = 512000
|
||||||
monitor_speed = 115200
|
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