Skip to content

Commit

Permalink
traces improvements, and code refactoring (RF315)
Browse files Browse the repository at this point in the history
  • Loading branch information
1technophile committed Jan 31, 2019
1 parent a587d9d commit 238bb47
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
3 changes: 2 additions & 1 deletion ZgatewayIR.ino
Expand Up @@ -483,7 +483,7 @@ void IRtoMQTT(){
void MQTTtoIR(char * topicOri, JsonObject& IRdata) {

if (strcmp(topicOri,subjectMQTTtoIR) == 0){
trc(F("MQTTtoIR json data analysis"));
trc(F("MQTTtoIR json"));
unsigned long data = IRdata["value"];
const char * raw = IRdata["raw"];
if (data != 0||raw) {
Expand Down Expand Up @@ -781,6 +781,7 @@ void IRtoMQTT(){
signalSent = true;
}
if (signalSent){ // 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
trc(F("MQTTtoIR OK"));
pub(subjectGTWIRtoMQTT, IRdata);
}
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
Expand Down
7 changes: 4 additions & 3 deletions ZgatewayRF.ino
Expand Up @@ -159,17 +159,18 @@ void MQTTtoRF(char * topicOri, char * datacallback) {
void MQTTtoRF(char * topicOri, JsonObject& RFdata) { // json object decoding

if (strcmp(topicOri,subjectMQTTtoRF) == 0){
trc(F("MQTTtoRF json analysis"));
trc(F("MQTTtoRF json"));
unsigned long data = RFdata["value"];
if (data != 0) {
int valuePRT = RFdata["protocol"]|1;
int valuePLSL = RFdata["delay"]|350;
int valueBITS = RFdata["length"]|24;
mySwitch.setProtocol(valuePRT,valuePLSL);
mySwitch.send(data, valueBITS);
mySwitch.send(data, valueBITS);
trc(F("MQTTtoRF OK"));
pub(subjectGTWRFtoMQTT, RFdata);// 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
}else{
trc(F("MQTTtoRF Fail read json"));
trc(F("MQTTtoRF Fail json"));
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions ZgatewayRF2.ino
Expand Up @@ -218,7 +218,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
void MQTTtoRF2(char * topicOri, JsonObject& RF2data) { // json object decoding

if (strcmp(topicOri,subjectMQTTtoRF2) == 0){
trc(F("MQTTtoRF2 json data analysis"));
trc(F("MQTTtoRF2 json"));
int boolSWITCHTYPE = RF2data["switchType"] | 99;
if (boolSWITCHTYPE != 99) {
trc(F("MQTTtoRF2 switch type ok"));
Expand All @@ -240,9 +240,8 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
trc(boolSWITCHTYPE);
trc(valueDIM);
NewRemoteReceiver::disable();
trc(F("Creating transmitter"));
NewRemoteTransmitter transmitter(valueCODE, RF_EMITTER_PIN, valuePERIOD);
trc(F("Sending data"));
trc(F("Sending"));
if (valueGROUP) {
if (isDimCommand) {
transmitter.sendGroupDim(valueDIM);
Expand All @@ -259,7 +258,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
transmitter.sendUnit(valueUNIT, boolSWITCHTYPE);
}
}
trc(F("Data sent"));
trc(F("MQTTtoRF2 OK"));
NewRemoteReceiver::enable();

// Publish state change back to MQTT
Expand Down
34 changes: 10 additions & 24 deletions ZgatewayRF315.ino
Expand Up @@ -139,32 +139,18 @@ boolean RF315toMQTT(){
void MQTTtoRF315(char * topicOri, JsonObject& RF315data) { // json object decoding

if (strcmp(topicOri,subjectMQTTtoRF315) == 0){
trc(F("MQTTtoRF315 json data analysis"));
trc(F("MQTTtoRF315 json"));
unsigned long data = RF315data["value"];
if (data != 0) {
trc(F("MQTTtoRF315 data ok"));
int valuePRT = RF315data["protocol"];
int valuePLSL = RF315data["delay"];
int valueBITS = RF315data["length"];
if ((valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)){
trc(F("MQTTtoRF315 dflt"));
mySwitch315.setProtocol(1,350);
mySwitch315.send(data, 24);
// Acknowledgement to the GTWRF topic
pub(subjectGTWRF315toMQTT, RF315data);
} 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
pub(subjectGTWRF315toMQTT, RF315data);// 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
}
int valuePRT = RF315data["protocol"]|1;
int valuePLSL = RF315data["delay"]|350;
int valueBITS = RF315data["length"]|24;
mySwitch315.setProtocol(valuePRT,valuePLSL);
mySwitch315.send(data, valueBITS);
trc(F("MQTTtoRF315 OK"));
pub(subjectGTWRF315toMQTT, RFdata);// 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
}else{
trc(F("MQTTtoRF315 Fail json"));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ZgatewaySRFB.ino
Expand Up @@ -277,7 +277,7 @@ bool _rfbToChar(byte * in, char * out) {
const char * raw = SRFBdata["raw"];
int valueRPT = SRFBdata["repeat"]|1;
if (strcmp(topicOri,subjectMQTTtoSRFB) == 0){
trc(F("MQTTtoSRFB json data analysis"));
trc(F("MQTTtoSRFB json"));
if (raw){ // send raw in priority when defined in the json
trc(F("MQTTtoSRFB raw ok"));
byte message_b[RF_MESSAGE_SIZE];
Expand Down Expand Up @@ -320,7 +320,7 @@ bool _rfbToChar(byte * in, char * out) {
memcpy(message_b + 4, hex_valueMaxiPLSL, 2);
memcpy(message_b + 6, hex_data, 3);

trc(F("MQTTtoSRFB send"));
trc(F("MQTTtoSRFB OK"));
_rfbSend(message_b, valueRPT);
// Acknowledgement to the GTWRF topic
pub(subjectGTWSRFBtoMQTT, SRFBdata);// 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
Expand Down

0 comments on commit 238bb47

Please sign in to comment.