add 315mhz RF gateway (#209)
based on RF gateway add the same implementation for 315mhz to facilitate the integration for whom who wants to use 433 and 315
This commit is contained in:
1 parent
11e5bd3f00
commit
b568e7137c
5 files changed
+242
-13
No files matched your search
+29
-13
@@ -64,6 +64,9 @@
|
|||||||
#if defined(ZgatewayRF) || defined(ZgatewayRF2)
|
#if defined(ZgatewayRF) || defined(ZgatewayRF2)
|
||||||
#include "config_RF.h"
|
#include "config_RF.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZgatewayRF315
|
||||||
|
#include "config_RF315.h"
|
||||||
|
#endif
|
||||||
#ifdef ZgatewaySRFB
|
#ifdef ZgatewaySRFB
|
||||||
#include "config_SRFB.h"
|
#include "config_SRFB.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -341,6 +344,9 @@ void setup()
|
|||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
setupRF();
|
setupRF();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZgatewayRF315
|
||||||
|
setupRF315();
|
||||||
|
#endif
|
||||||
#ifdef ZgatewayRF2
|
#ifdef ZgatewayRF2
|
||||||
setupRF2();
|
setupRF2();
|
||||||
#endif
|
#endif
|
||||||
@@ -597,7 +603,6 @@ void loop()
|
|||||||
#ifdef ZsensorADC
|
#ifdef ZsensorADC
|
||||||
MeasureADC(); //Addon to measure the analog value of analog pin
|
MeasureADC(); //Addon to measure the analog value of analog pin
|
||||||
#endif
|
#endif
|
||||||
// Receive loop, if data received by RF433 or IR send it by MQTT
|
|
||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
if(RFtoMQTT()){
|
if(RFtoMQTT()){
|
||||||
trc(F("RFtoMQTT OK"));
|
trc(F("RFtoMQTT OK"));
|
||||||
@@ -606,6 +611,14 @@ void loop()
|
|||||||
timer_led_receive = millis();
|
timer_led_receive = millis();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZgatewayRF315
|
||||||
|
if(RF315toMQTT()){
|
||||||
|
trc(F("RF315toMQTT OK"));
|
||||||
|
//GREEN ON
|
||||||
|
digitalWrite(led_receive, LOW);
|
||||||
|
timer_led_receive = millis();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef ZgatewayRF2
|
#ifdef ZgatewayRF2
|
||||||
if(RF2toMQTT()){
|
if(RF2toMQTT()){
|
||||||
trc(F("RF2toMQTT OK"));
|
trc(F("RF2toMQTT OK"));
|
||||||
@@ -675,41 +688,44 @@ void stateMeasures(){
|
|||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
modules = modules + ZgatewayRF;
|
modules = modules + ZgatewayRF;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ZgatewayRF315
|
||||||
|
modules = modules + ZgatewayRF315;
|
||||||
|
#endif
|
||||||
#ifdef ZsensorBME280
|
#ifdef ZsensorBME280
|
||||||
modules = modules + "," + ZsensorBME280;
|
modules = modules + ZsensorBME280;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZsensorBH1750
|
#ifdef ZsensorBH1750
|
||||||
modules = modules + "," + ZsensorBH1750;
|
modules = modules + ZsensorBH1750;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZsensorTSL2561
|
#ifdef ZsensorTSL2561
|
||||||
modules = modules + "," + ZsensorTSL2561;
|
modules = modules + ZsensorTSL2561;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZactuatorONOFF
|
#ifdef ZactuatorONOFF
|
||||||
modules = modules + "," + ZactuatorONOFF;
|
modules = modules + ZactuatorONOFF;
|
||||||
#endif
|
#endif
|
||||||
#ifdef Zgateway2G
|
#ifdef Zgateway2G
|
||||||
modules = modules + "," + Zgateway2G;
|
modules = modules + Zgateway2G;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayIR
|
#ifdef ZgatewayIR
|
||||||
modules = modules + "," + ZgatewayIR;
|
modules = modules + ZgatewayIR;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayRF2
|
#ifdef ZgatewayRF2
|
||||||
modules = modules + "," + ZgatewayRF2;
|
modules = modules + ZgatewayRF2;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewaySRFB
|
#ifdef ZgatewaySRFB
|
||||||
modules = modules + "," + ZgatewaySRFB;
|
modules = modules + ZgatewaySRFB;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayBT
|
#ifdef ZgatewayBT
|
||||||
modules = modules + "," + ZgatewayBT;
|
modules = modules + ZgatewayBT;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayRFM69
|
#ifdef ZgatewayRFM69
|
||||||
modules = modules + "," + ZgatewayRFM69;
|
modules = modules + ZgatewayRFM69;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZsensorINA226
|
#ifdef ZsensorINA226
|
||||||
modules = modules + "," + ZsensorINA226;
|
modules = modules + ZsensorINA226;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZsensorHCSR501
|
#ifdef ZsensorHCSR501
|
||||||
modules = modules + "," + ZsensorHCSR501;
|
modules = modules + ZsensorHCSR501;
|
||||||
#endif
|
#endif
|
||||||
SYSdata["modules"] = modules;
|
SYSdata["modules"] = modules;
|
||||||
trc(modules);
|
trc(modules);
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//Addons and module management, comment the Z line
|
//Addons and module management, comment the Z line
|
||||||
|
|
||||||
#define ZgatewayRF "RF" //ESP8266, Arduino, ESP32
|
#define ZgatewayRF "RF" //ESP8266, Arduino, ESP32
|
||||||
|
//#define ZgatewayRF315 "RF315" //ESP8266, Arduino, ESP32
|
||||||
#define ZgatewayIR "IR" //ESP8266, Arduino, Sonoff RF Bridge
|
#define ZgatewayIR "IR" //ESP8266, Arduino, Sonoff RF Bridge
|
||||||
#define ZgatewayBT "BT" //ESP8266, Arduino, ESP32
|
#define ZgatewayBT "BT" //ESP8266, Arduino, ESP32
|
||||||
//#define ZgatewayRF2 "RF2" //ESP8266, Arduino, ESP32
|
//#define ZgatewayRF2 "RF2" //ESP8266, Arduino, ESP32
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
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:
|
||||||
|
- receive MQTT data from a topic and send RF 315Mhz signal corresponding to the received MQTT data
|
||||||
|
- publish MQTT data to a different topic related to received 315Mhz signal
|
||||||
|
|
||||||
|
Copyright: (c)Florian ROBERT
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifdef ZgatewayRF315
|
||||||
|
|
||||||
|
#include <RCSwitch.h> // library for controling Radio frequency switch
|
||||||
|
|
||||||
|
RCSwitch mySwitch315 = RCSwitch();
|
||||||
|
|
||||||
|
void setupRF315(){
|
||||||
|
|
||||||
|
//RF init parameters
|
||||||
|
mySwitch315.enableTransmit(RF315_EMITTER_PIN);
|
||||||
|
trc(F("RF315_EMITTER_PIN "));
|
||||||
|
trc(RF315_EMITTER_PIN);
|
||||||
|
mySwitch315.setRepeatTransmit(RF315_EMITTER_REPEAT);
|
||||||
|
mySwitch315.enableReceive(RF315_RECEIVER_PIN);
|
||||||
|
trc(F("RF315_RECEIVER_PIN "));
|
||||||
|
trc(RF315_RECEIVER_PIN);
|
||||||
|
trc(F("ZgatewayRF315 setup done "));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean RF315toMQTT(){
|
||||||
|
|
||||||
|
if (mySwitch315.available()){
|
||||||
|
trc(F("Rcv. RF315"));
|
||||||
|
#ifdef ESP32
|
||||||
|
String taskMessage = "RF Task running on core ";
|
||||||
|
taskMessage = taskMessage + xPortGetCoreID();
|
||||||
|
trc(taskMessage);
|
||||||
|
#endif
|
||||||
|
unsigned long MQTTvalue = 0;
|
||||||
|
String MQTTprotocol;
|
||||||
|
String MQTTbits;
|
||||||
|
String MQTTlength;
|
||||||
|
MQTTvalue = mySwitch315.getReceivedValue();
|
||||||
|
MQTTprotocol = String(mySwitch315.getReceivedProtocol());
|
||||||
|
MQTTbits = String(mySwitch315.getReceivedBitlength());
|
||||||
|
MQTTlength = String(mySwitch315.getReceivedDelay());
|
||||||
|
mySwitch315.resetAvailable();
|
||||||
|
if (!isAduplicate(MQTTvalue) && MQTTvalue!=0) {// conditions to avoid duplications of RF -->MQTT
|
||||||
|
trc(F("Adv data RF315toMQTT"));
|
||||||
|
client.publish(subjectRF315toMQTTprotocol,(char *)MQTTprotocol.c_str());
|
||||||
|
client.publish(subjectRF315toMQTTbits,(char *)MQTTbits.c_str());
|
||||||
|
client.publish(subjectRF315toMQTTlength,(char *)MQTTlength.c_str());
|
||||||
|
trc(F("Sending RF315toMQTT"));
|
||||||
|
String value = String(MQTTvalue);
|
||||||
|
trc(value);
|
||||||
|
boolean result = client.publish(subjectRF315toMQTT,(char *)value.c_str());
|
||||||
|
if (repeatRF315wMQTT){
|
||||||
|
trc(F("Publish RF315 for repeat"));
|
||||||
|
client.publish(subjectMQTTtoRF315,(char *)value.c_str());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MQTTtoRF315(char * topicOri, char * datacallback) {
|
||||||
|
|
||||||
|
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
|
||||||
|
|
||||||
|
// RF315 DATA ANALYSIS
|
||||||
|
//We look into the subject to see if a special RF protocol is defined
|
||||||
|
String topic = topicOri;
|
||||||
|
int valuePRT = 0;
|
||||||
|
int valuePLSL = 0;
|
||||||
|
int valueBITS = 0;
|
||||||
|
int pos = topic.lastIndexOf(RF315protocolKey);
|
||||||
|
if (pos != -1){
|
||||||
|
pos = pos + +strlen(RF315protocolKey);
|
||||||
|
valuePRT = (topic.substring(pos,pos + 1)).toInt();
|
||||||
|
trc(F("RF315 Protocol:"));
|
||||||
|
trc(valuePRT);
|
||||||
|
}
|
||||||
|
//We look into the subject to see if a special RF pulselength is defined
|
||||||
|
int pos2 = topic.lastIndexOf(RF315pulselengthKey);
|
||||||
|
if (pos2 != -1) {
|
||||||
|
pos2 = pos2 + strlen(RF315pulselengthKey);
|
||||||
|
valuePLSL = (topic.substring(pos2,pos2 + 3)).toInt();
|
||||||
|
trc(F("RF315 Pulse Lgth:"));
|
||||||
|
trc(valuePLSL);
|
||||||
|
}
|
||||||
|
int pos3 = topic.lastIndexOf(RF315bitsKey);
|
||||||
|
if (pos3 != -1){
|
||||||
|
pos3 = pos3 + strlen(RF315bitsKey);
|
||||||
|
valueBITS = (topic.substring(pos3,pos3 + 2)).toInt();
|
||||||
|
trc(F("Bits nb:"));
|
||||||
|
trc(valueBITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((topic == subjectMQTTtoRF315) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)){
|
||||||
|
trc(F("MQTTtoRF315 dflt"));
|
||||||
|
mySwitch315.setProtocol(1,350);
|
||||||
|
mySwitch315.send(data, 24);
|
||||||
|
// Acknowledgement to the GTWRF topic
|
||||||
|
boolean result = client.publish(subjectGTWRF315toMQTT, datacallback);
|
||||||
|
if (result)trc(F("Ack pub."));
|
||||||
|
|
||||||
|
} else if ((valuePRT != 0) || (valuePLSL != 0)|| (valueBITS != 0)){
|
||||||
|
trc(F("MQTTtoRF315 usr par."));
|
||||||
|
if (valuePRT == 0) valuePRT = 1;
|
||||||
|
if (valuePLSL == 0) valuePLSL = 350;
|
||||||
|
if (valueBITS == 0) valueBITS = 24;
|
||||||
|
trc(valuePRT);
|
||||||
|
trc(valuePLSL);
|
||||||
|
trc(valueBITS);
|
||||||
|
mySwitch315.setProtocol(valuePRT,valuePLSL);
|
||||||
|
mySwitch315.send(data, valueBITS);
|
||||||
|
// Acknowledgement to the GTWRF topic
|
||||||
|
boolean result = client.publish(subjectGTWRF315toMQTT, datacallback);// we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
|
||||||
|
if (result){
|
||||||
|
trc(F("MQTTtoRF315 ack pub."));
|
||||||
|
trc(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
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 files enables to set your parameter for the radiofrequency gateways (ZgatewayRF315 ) with RCswitch library
|
||||||
|
|
||||||
|
Copyright: (c)Florian ROBERT
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-------------------RF topics & parameters----------------------*/
|
||||||
|
//433Mhz MQTT Subjects and keys
|
||||||
|
#define subjectMQTTtoRF315 Base_Topic Gateway_Name "/commands/MQTTto315"
|
||||||
|
#define subjectRF315toMQTT Base_Topic Gateway_Name "/315toMQTT"
|
||||||
|
#define subjectGTWRF315toMQTT Base_Topic Gateway_Name "/315toMQTT"
|
||||||
|
#define subjectRF315toMQTTprotocol Base_Topic Gateway_Name "/315toMQTT/protocol"
|
||||||
|
#define subjectRF315toMQTTbits Base_Topic Gateway_Name "/315toMQTT/bits"
|
||||||
|
#define subjectRF315toMQTTlength Base_Topic Gateway_Name "/315toMQTT/length"
|
||||||
|
#define RF315protocolKey "315_" // protocol will be defined if a subject contains RFprotocolKey followed by a value of 1 digit
|
||||||
|
#define RF315bitsKey "RFBITS_" // bits will be defined if a subject contains RFbitsKey followed by a value of 2 digits
|
||||||
|
#define repeatRF315wMQTT false // do we repeat a received signal by using mqtt
|
||||||
|
/*
|
||||||
|
RF supported protocols
|
||||||
|
315_1
|
||||||
|
315_2
|
||||||
|
315_3
|
||||||
|
315_4
|
||||||
|
315_5
|
||||||
|
315_6
|
||||||
|
*/
|
||||||
|
#define RF315pulselengthKey "PLSL_" // pulselength will be defined if a subject contains RFprotocolKey followed by a value of 3 digits
|
||||||
|
// subject monitored to listen traffic processed by other gateways to store data and avoid ntuple
|
||||||
|
#define subjectMultiGTWRF315 "+/315toMQTT"
|
||||||
|
//RF number of signal repetition
|
||||||
|
#define RF315_EMITTER_REPEAT 20
|
||||||
|
|
||||||
|
/*-------------------PIN DEFINITIONS----------------------*/
|
||||||
|
#ifdef ESP8266
|
||||||
|
#define RF315_RECEIVER_PIN 4 // D3 on nodemcu
|
||||||
|
#define RF315_EMITTER_PIN 5 // RX on nodemcu
|
||||||
|
#elif defined(ESP32)
|
||||||
|
#define RF315_RECEIVER_PIN 13 // D13 on DOIT ESP32
|
||||||
|
#define RF315_EMITTER_PIN 12 // D12 on DOIT ESP32
|
||||||
|
#else
|
||||||
|
//IMPORTANT NOTE: On arduino UNO connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library <library>IRremote/IRremoteInt.h so as to free pin D3 for RF RECEIVER PIN
|
||||||
|
//RF PIN definition
|
||||||
|
#define RF315_RECEIVER_PIN 1 //1 = D3 on arduino
|
||||||
|
#define RF315_EMITTER_PIN 4 //4 = D4 on arduino
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//Addons and module management, comment the Z line and the config file if you don't use
|
//Addons and module management, comment the Z line and the config file if you don't use
|
||||||
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
||||||
#define ZgatewayRF "RF"
|
#define ZgatewayRF "RF"
|
||||||
|
#define ZgatewayRF315 "RF315"
|
||||||
#define ZgatewaySRFB "SRFB"
|
#define ZgatewaySRFB "SRFB"
|
||||||
#define ZgatewayRF2 "RF2"
|
#define ZgatewayRF2 "RF2"
|
||||||
#define ZgatewayIR "IR"
|
#define ZgatewayIR "IR"
|
||||||
@@ -102,6 +103,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define ZgatewayRFM69 "RFM69"// If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
#define ZgatewayRFM69 "RFM69"// If you uncomment this you can't use RF and BT due to the fact that RF use also D8 and BT use also D6/D7
|
||||||
#elif ESP32
|
#elif ESP32
|
||||||
#define ZgatewayRF "RF"
|
#define ZgatewayRF "RF"
|
||||||
|
#define ZgatewayRF "RF315"
|
||||||
#define ZgatewayRF2 "RF2"
|
#define ZgatewayRF2 "RF2"
|
||||||
//#define Zgateway2G (not tested yet)
|
//#define Zgateway2G (not tested yet)
|
||||||
//#define ZgatewayIR
|
//#define ZgatewayIR
|
||||||
|
|||||||
Reference in new issue
Block a user