1 parent
ad6929c77c
commit
0b9bbc3dd6
2 files changed
+62
-1
No files matched your search
+61
-1
@@ -39,6 +39,65 @@ sudo mosquitto_pub -t home/commands/MQTTtoRF2/CODE_8233372/UNIT_0/PERIOD_272 -m
|
|||||||
#ifdef ZgatewayRF2
|
#ifdef ZgatewayRF2
|
||||||
|
|
||||||
#include <NewRemoteTransmitter.h>
|
#include <NewRemoteTransmitter.h>
|
||||||
|
#include <NewRemoteReceiver.h>
|
||||||
|
|
||||||
|
struct RF2rxd
|
||||||
|
{
|
||||||
|
unsigned int period;
|
||||||
|
unsigned long address;
|
||||||
|
unsigned long groupBit;
|
||||||
|
unsigned long unit;
|
||||||
|
unsigned long switchType;
|
||||||
|
bool hasNewData;
|
||||||
|
};
|
||||||
|
|
||||||
|
RF2rxd rf2rd;
|
||||||
|
|
||||||
|
void setupRF2(){
|
||||||
|
#ifdef ESP8266
|
||||||
|
NewRemoteReceiver::init(5, 2, rf2Callback);
|
||||||
|
#else
|
||||||
|
NewRemoteReceiver::init(0, 2, rf2Callback);
|
||||||
|
#endif
|
||||||
|
Serial.println("Receiver RF2 initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean RF2toMQTT(){
|
||||||
|
//Serial.println("entra rf2tomqtt");
|
||||||
|
if(rf2rd.hasNewData){
|
||||||
|
rf2rd.hasNewData=false;
|
||||||
|
|
||||||
|
trc(F("Rcv. RF2"));
|
||||||
|
String MQTTAddress;
|
||||||
|
String MQTTperiod;
|
||||||
|
String MQTTunit;
|
||||||
|
String MQTTgroupBit;
|
||||||
|
String MQTTswitchType;
|
||||||
|
|
||||||
|
MQTTAddress = String(rf2rd.address);
|
||||||
|
MQTTperiod = String(rf2rd.period);
|
||||||
|
MQTTunit = String(rf2rd.unit);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rf2Callback(unsigned int period, unsigned long address, unsigned long groupBit, unsigned long unit, unsigned long switchType) {
|
||||||
|
|
||||||
|
rf2rd.period=period;
|
||||||
|
rf2rd.address=address;
|
||||||
|
rf2rd.groupBit=groupBit;
|
||||||
|
rf2rd.unit=unit;
|
||||||
|
rf2rd.switchType=switchType;
|
||||||
|
rf2rd.hasNewData=true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MQTTtoRF2(char * topicOri, char * datacallback) {
|
void MQTTtoRF2(char * topicOri, char * datacallback) {
|
||||||
|
|
||||||
@@ -51,11 +110,12 @@ void MQTTtoRF2(char * topicOri, char * datacallback) {
|
|||||||
long valueCODE = 0;
|
long valueCODE = 0;
|
||||||
int valueUNIT = -1;
|
int valueUNIT = -1;
|
||||||
int valuePERIOD = 0;
|
int valuePERIOD = 0;
|
||||||
|
int valueBIT = 0;
|
||||||
|
|
||||||
int pos = topic.lastIndexOf(RF2codeKey);
|
int pos = topic.lastIndexOf(RF2codeKey);
|
||||||
if (pos != -1){
|
if (pos != -1){
|
||||||
pos = pos + +strlen(RF2codeKey);
|
pos = pos + +strlen(RF2codeKey);
|
||||||
valueCODE = (topic.substring(pos,pos + 7)).toInt();
|
valueCODE = (topic.substring(pos,pos + 8)).toInt();
|
||||||
trc(F("RF2 code:"));
|
trc(F("RF2 code:"));
|
||||||
trc(String(valueCODE));
|
trc(String(valueCODE));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ RF supported protocols
|
|||||||
/*-------------------RF2 topics & parameters----------------------*/
|
/*-------------------RF2 topics & parameters----------------------*/
|
||||||
//433Mhz newremoteswitch MQTT Subjects and keys
|
//433Mhz newremoteswitch MQTT Subjects and keys
|
||||||
#define subjectMQTTtoRF2 "home/commands/MQTTtoRF2"
|
#define subjectMQTTtoRF2 "home/commands/MQTTtoRF2"
|
||||||
|
#define subjectRF2toMQTT "home/RF2toMQTT"
|
||||||
#define RF2codeKey "CODE_" // code will be defined if a subject contains RF2codeKey followed by a value of 7 digits
|
#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 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 digit
|
||||||
|
|||||||
Reference in new issue
Block a user