From b047f5a5052f9258aebafd8e5a2cf8a9d33737e0 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 28 Jul 2018 20:48:44 +0100 Subject: [PATCH] ESPilight support Support for ESPilight - only recieve at the moment --- OpenMQTTGateway.ino | 18 ++++++++- User_config.h | 1 + ZgatewayPilight.ino | 99 +++++++++++++++++++++++++++++++++++++++++++++ config_RF.h | 5 +++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 ZgatewayPilight.ino diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index a3f43d9..c2aa8bd 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -61,7 +61,7 @@ #include // Modules config inclusion -#if defined(ZgatewayRF) || defined(ZgatewayRF2) +#if defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZgatewayPilight) #include "config_RF.h" #endif #ifdef ZgatewayRF315 @@ -355,6 +355,9 @@ void setup() #ifdef ZgatewayRF2 setupRF2(); #endif + #ifdef ZgatewayPilight + setupPilight(); + #endif #ifdef ZgatewaySRFB setupSRFB(); #endif @@ -632,6 +635,13 @@ void loop() timer_led_receive = millis(); } #endif + #ifdef ZgatewayPilight + if(PilighttoMQTT()){ + trc(F("PilighttoMQTT OK")); + digitalWrite(led_receive, LOW); + timer_led_receive = millis(); + } + #endif #ifdef ZgatewaySRFB if(SRFBtoMQTT()) trc(F("SRFBtoMQTT OK")); @@ -718,6 +728,9 @@ void stateMeasures(){ #ifdef ZgatewayRF2 modules = modules + ZgatewayRF2; #endif + #ifdef ZgatewayPilight + modules = modules + ZgatewayPilight; + #endif #ifdef ZgatewaySRFB modules = modules + ZgatewaySRFB; #endif @@ -808,6 +821,9 @@ digitalWrite(led_send, LOW); #ifdef ZgatewayRF2 MQTTtoRF2(topicOri, datacallback); #endif +#ifdef ZgatewayPilight + MQTTtoPilight(topicOri, datacallback); +#endif #ifdef Zgateway2G MQTTto2G(topicOri, datacallback); #endif diff --git a/User_config.h b/User_config.h index 5fad76d..a50e53c 100644 --- a/User_config.h +++ b/User_config.h @@ -94,6 +94,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress #define ZgatewayIR "IR" //ESP8266, Arduino, Sonoff RF Bridge #define ZgatewayBT "BT" //ESP8266, Arduino, ESP32 //#define ZgatewayRF2 "RF2" //ESP8266, Arduino, ESP32 +//#define ZgatewayPilight "Pilight" //ESP8266 //#define ZgatewaySRFB "SRFB" // Sonoff RF Bridge //#define Zgateway2G "2G" //ESP8266, Arduino, ESP32 //#define ZactuatorONOFF "ONOFF" //ESP8266, Arduino, ESP32, Sonoff RF Bridge diff --git a/ZgatewayPilight.ino b/ZgatewayPilight.ino new file mode 100644 index 0000000..46a4c82 --- /dev/null +++ b/ZgatewayPilight.ino @@ -0,0 +1,99 @@ +/* + OpenMQTTGateway - ESP8266 or Arduino program for home automation + + Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker + Send and receiving command by MQTT + + This gateway enables to: + - publish MQTT data to a different topic related to received 433Mhz signal using ESPiLight + + Copyright: (c)Florian ROBERT + Copyright: (c)Randy Simons http://randysimons.nl/ + + This file is part of OpenMQTTGateway. + + OpenMQTTGateway is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenMQTTGateway is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef ZgatewayPilight + +#include + +ESPiLight rf(RF_EMITTER_PIN); // use -1 to disable transmitter + +struct Pilightrxd +{ + String protocol; + String deviceID; + String status; + String message; + bool hasNewData; +}; + +Pilightrxd pilightrd; + +void setupPilight(){ + #ifndef ZgatewayRF && ZgatewayRF2 //receiving with Pilight is not compatible with ZgatewayRF or RF2 as far as I can tell + rf.setCallback(pilightCallback); + rf.initReceiver(RF_RECEIVER_PIN); + trc(F("RF_EMITTER_PIN ")); + trc(String(RF_EMITTER_PIN)); + trc(F("RF_RECEIVER_PIN ")); + trc(String(RF_RECEIVER_PIN)); + trc(F("ZgatewayPilight setup done ")); + #endif +} + +boolean PilighttoMQTT(){ + rf.loop(); + + if(pilightrd.hasNewData){ + + pilightrd.hasNewData=false; + trc(F("Rcv. Pilight")); + String MQTTprotocol; + String MQTTdeviceID; + String MQTTstatus; + String MQTTmessage; + + MQTTprotocol = String(pilightrd.protocol); + MQTTdeviceID = String(pilightrd.deviceID); + MQTTstatus = String(pilightrd.status); + MQTTmessage = String(pilightrd.message); + String MQTTPilightstring; + MQTTPilightstring = subjectPilighttoMQTT+String("/")+MQTTprotocol+String("/")+MQTTdeviceID; + trc(F("Adv data PilighttoMQTT")); + client.publish((char *)MQTTPilightstring.c_str(),(char *)MQTTmessage.c_str()); + return true; + + } + return false; +} + +void pilightCallback(const String &protocol, const String &message, int status, + size_t repeats, const String &deviceID) { + + pilightrd.protocol=protocol; + pilightrd.deviceID=deviceID; + pilightrd.status=status; + pilightrd.message=message; + pilightrd.hasNewData=true; + +} + +void MQTTtoPilight(char * topicOri, char * datacallback) { + +} + +#endif diff --git a/config_RF.h b/config_RF.h index 17a2c39..41cd868 100644 --- a/config_RF.h +++ b/config_RF.h @@ -60,6 +60,11 @@ RF supported protocols #define RF2groupKey "GROUP_" // number of your group value will be defined if a subject contains RF2groupKey followed by a value of 1 digit #define RF2dimKey "DIM" // number of your dim value will be defined if a subject contains RF2dimKey and the payload contains the dim value as digits +/*-------------------ESPPiLight topics & parameters----------------------*/ +//433Mhz Pilight MQTT Subjects and keys +#define subjectMQTTtoPilight Base_Topic Gateway_Name "/commands/MQTTtoPilight" +#define subjectPilighttoMQTT Base_Topic Gateway_Name "/PilighttoMQTT" + /*-------------------PIN DEFINITIONS----------------------*/ #ifdef ESP8266 #define RF_RECEIVER_PIN 0 // D3 on nodemcu