Makes RF2 sending and receiving work for ESP8266 with added support for group bit and dimming (#113)
* Made rf2 sending and receiving work With code from https://github.com/1technophile/OpenMQTTGateway/pull/109 plus some other fixes. * Added support for group bit Added support for sending and receiving group bit * Group bit and MQTT retransmitting Added support for sending and receiving group bit. Made the gateway transmit the new state of a RF2 switch to the MQTT state topic when it receives a MQTT command to control that switch. * Removed hard coded RF2 code length * Added support for dimming to RF2 Verified to work with Nexa WMR-250 dimmer. * Minor cleanup
This commit is contained in:
1 parent
0b9bbc3dd6
commit
0d1e7bbe75
4 files changed
+74
-10
No files matched your search
@@ -173,6 +173,9 @@ void setup()
|
||||
#ifdef ZgatewayRF
|
||||
setupRF();
|
||||
#endif
|
||||
#ifdef ZgatewayRF2
|
||||
setupRF2();
|
||||
#endif
|
||||
#ifdef ZgatewayBT
|
||||
setupBT();
|
||||
#endif
|
||||
@@ -249,6 +252,11 @@ void loop()
|
||||
if(resultRF)
|
||||
trc(F("RFtoMQTT OK"));
|
||||
#endif
|
||||
#ifdef ZgatewayRF2
|
||||
boolean resultRF2 = RF2toMQTT();
|
||||
if(resultRF2)
|
||||
trc(F("RF2toMQTT OK"));
|
||||
#endif
|
||||
#ifdef ZgatewayIR
|
||||
boolean resultIR = IRtoMQTT();
|
||||
if(resultIR)
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
||||
#else // for arduino + W5100
|
||||
#define ZgatewayRF
|
||||
#include "config_RF.h"
|
||||
#define ZgatewayRF2
|
||||
//#define ZgatewayRF2 // too big for UNO
|
||||
#ifdef RFM69_Wiring
|
||||
//#define ZgatewayRFM69 not tested
|
||||
//#include "config_RFM69.h"
|
||||
|
||||
+62
-8
@@ -59,7 +59,10 @@ void setupRF2(){
|
||||
#else
|
||||
NewRemoteReceiver::init(0, 2, rf2Callback);
|
||||
#endif
|
||||
Serial.println("Receiver RF2 initialized");
|
||||
trc(F("Receiver RF2 initialized"));
|
||||
pinMode(RF_EMITTER_PIN, OUTPUT);
|
||||
digitalWrite(RF_EMITTER_PIN, LOW);
|
||||
trc(F("Transmitter RF2 initialized"));
|
||||
}
|
||||
|
||||
boolean RF2toMQTT(){
|
||||
@@ -80,10 +83,10 @@ boolean RF2toMQTT(){
|
||||
MQTTgroupBit = String(rf2rd.groupBit);
|
||||
MQTTswitchType = String(rf2rd.switchType);
|
||||
String MQTTRF2string;
|
||||
MQTTRF2string = subjectRF2toMQTT+String("/")+RF2codeKey+MQTTAddress+String("/")+RF2unitKey+MQTTunit+String("/")+RF2periodKey+MQTTperiod;
|
||||
trc(F("Adv data RF2toMQTT"));
|
||||
client.publish((char *)MQTTRF2string.c_str(),(char *)MQTTswitchType.c_str());
|
||||
return true;
|
||||
MQTTRF2string = subjectRF2toMQTT+String("/")+RF2codeKey+MQTTAddress+String("/")+RF2unitKey+MQTTunit+String("/")+RF2groupKey+MQTTgroupBit+String("/")+RF2periodKey+MQTTperiod;
|
||||
trc(F("Adv data RF2toMQTT"));
|
||||
client.publish((char *)MQTTRF2string.c_str(),(char *)MQTTswitchType.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -110,7 +113,8 @@ void MQTTtoRF2(char * topicOri, char * datacallback) {
|
||||
long valueCODE = 0;
|
||||
int valueUNIT = -1;
|
||||
int valuePERIOD = 0;
|
||||
int valueBIT = 0;
|
||||
int valueGROUP = 0;
|
||||
int valueDIM = -1;
|
||||
|
||||
int pos = topic.lastIndexOf(RF2codeKey);
|
||||
if (pos != -1){
|
||||
@@ -129,10 +133,24 @@ void MQTTtoRF2(char * topicOri, char * datacallback) {
|
||||
int pos3 = topic.lastIndexOf(RF2unitKey);
|
||||
if (pos3 != -1){
|
||||
pos3 = pos3 + strlen(RF2unitKey);
|
||||
valueUNIT = (topic.substring(pos3,pos3 + 1)).toInt();
|
||||
valueUNIT = (topic.substring(pos3, topic.indexOf("/", pos3))).toInt();
|
||||
trc(F("Unit:"));
|
||||
trc(String(valueUNIT));
|
||||
}
|
||||
int pos4 = topic.lastIndexOf(RF2groupKey);
|
||||
if (pos4 != -1) {
|
||||
pos4 = pos4 + strlen(RF2groupKey);
|
||||
valueGROUP = (topic.substring(pos4,pos4 + 1)).toInt();
|
||||
trc(F("RF2 Group:"));
|
||||
trc(String(valueGROUP));
|
||||
}
|
||||
int pos5 = topic.lastIndexOf(RF2dimKey);
|
||||
if (pos5 != -1) {
|
||||
pos5 = pos5 + strlen(RF2dimKey);
|
||||
valueDIM = (topic.substring(pos5, topic.indexOf("/", pos5))).toInt();
|
||||
trc(F("RF2 Dim:"));
|
||||
trc(String(valueDIM));
|
||||
}
|
||||
|
||||
if ((topic == subjectMQTTtoRF2) || (valueCODE != 0) || (valueUNIT != -1)|| (valuePERIOD != 0)){
|
||||
trc(F("MQTTtoRF2"));
|
||||
@@ -142,12 +160,48 @@ void MQTTtoRF2(char * topicOri, char * datacallback) {
|
||||
trc(String(valueCODE));
|
||||
trc(String(valueUNIT));
|
||||
trc(String(valuePERIOD));
|
||||
trc(String(valueGROUP));
|
||||
trc(String(boolSWITCHTYPE));
|
||||
trc(String(valueDIM));
|
||||
NewRemoteReceiver::disable();
|
||||
trc(F("Creating transmitter"));
|
||||
NewRemoteTransmitter transmitter(valueCODE, RF_EMITTER_PIN, valuePERIOD);
|
||||
trc(F("Sending data"));
|
||||
transmitter.sendUnit(valueUNIT, boolSWITCHTYPE);
|
||||
if (valueGROUP) {
|
||||
if (valueDIM >= 0) {
|
||||
transmitter.sendGroupDim(valueDIM);
|
||||
}
|
||||
else {
|
||||
transmitter.sendGroup(boolSWITCHTYPE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (valueDIM >= 0) {
|
||||
transmitter.sendDim(valueUNIT, valueDIM);
|
||||
}
|
||||
else {
|
||||
transmitter.sendUnit(valueUNIT, boolSWITCHTYPE);
|
||||
}
|
||||
}
|
||||
trc(F("Data sent"));
|
||||
NewRemoteReceiver::enable();
|
||||
|
||||
// Publish state change back to MQTT
|
||||
String MQTTAddress;
|
||||
String MQTTperiod;
|
||||
String MQTTunit;
|
||||
String MQTTgroupBit;
|
||||
String MQTTswitchType;
|
||||
|
||||
MQTTAddress = String(valueCODE);
|
||||
MQTTperiod = String(valuePERIOD);
|
||||
MQTTunit = String(valueUNIT);
|
||||
MQTTgroupBit = String(rf2rd.groupBit);
|
||||
MQTTswitchType = String(boolSWITCHTYPE);
|
||||
String MQTTRF2string;
|
||||
MQTTRF2string = subjectRF2toMQTT+String("/")+RF2codeKey+MQTTAddress+String("/")+RF2unitKey+MQTTunit+String("/")+RF2groupKey+MQTTgroupBit+String("/")+RF2periodKey+MQTTperiod;
|
||||
trc(F("Adv data MQTTtoRF2 push state via RF2toMQTT"));
|
||||
client.publish((char *)MQTTRF2string.c_str(),(char *)MQTTswitchType.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -59,7 +59,9 @@ RF supported protocols
|
||||
#define subjectRF2toMQTT "home/RF2toMQTT"
|
||||
#define RF2codeKey "CODE_" // code will be defined if a subject contains RF2codeKey followed by a value of 7 digits
|
||||
#define RF2periodKey "PERIOD_" // period will be defined if a subject contains RF2periodKey followed by a value of 3 digits
|
||||
#define RF2unitKey "UNIT_" // number of your unit value will be defined if a subject contains RF2unitKey followed by a value of 1 digit
|
||||
#define RF2unitKey "UNIT_" // number of your unit value will be defined if a subject contains RF2unitKey followed by a value of 1-2 digits
|
||||
#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 followed by a value of 1-3 digits
|
||||
|
||||
/*-------------------PIN DEFINITIONS----------------------*/
|
||||
#ifdef I2C_Wiring // With Support for I2C Modules
|
||||
|
||||
Reference in new issue
Block a user