Fix ESPiLight transmission error reporting (#762)

This commit is contained in:
melyux authored and GitHub committed 2020-09-09 06:07:58 -05:00
1 parent ae3253315f
commit eef8c5048d
1 file changed
+11 -17
+11 -17
View File
@@ -101,26 +101,21 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
rf.disableReceiver(); rf.disableReceiver();
# endif # endif
int result = 0;
if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) { if (cmpToMainTopic(topicOri, subjectMQTTtoPilight)) {
Log.trace(F("MQTTtoPilight json data analysis" CR)); Log.trace(F("MQTTtoPilight json data analysis" CR));
const char* message = Pilightdata["message"]; const char* message = Pilightdata["message"];
const char* protocol = Pilightdata["protocol"]; const char* protocol = Pilightdata["protocol"];
const char* raw = Pilightdata["raw"]; const char* raw = Pilightdata["raw"];
if (raw) { if (raw) {
int msgLength = 0;
uint16_t codes[MAXPULSESTREAMLENGTH]; uint16_t codes[MAXPULSESTREAMLENGTH];
msgLength = rf.stringToPulseTrain( int msgLength = rf.stringToPulseTrain(
raw, raw, codes, MAXPULSESTREAMLENGTH);
codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) { if (msgLength > 0) {
rf.sendPulseTrain(codes, msgLength); rf.sendPulseTrain(codes, msgLength);
Log.notice(F("MQTTtoPilight raw ok" CR)); Log.notice(F("MQTTtoPilight raw ok" CR));
result = msgLength;
} else { } else {
Log.trace(F("MQTTtoPilight raw KO" CR)); Log.trace(F("MQTTtoPilight raw KO" CR));
switch (result) { switch (msgLength) {
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_C: case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_C:
Log.trace(F("'c' not found in string, or has no data" CR)); Log.trace(F("'c' not found in string, or has no data" CR));
break; break;
@@ -134,19 +129,16 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
Log.trace(F("pulse type not defined" CR)); Log.trace(F("pulse type not defined" CR));
break; break;
} }
Log.error(F("Invalid JSON: raw data malformed" CR));
} }
} else if (message && protocol) { } else if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR)); Log.trace(F("MQTTtoPilight msg & protocol ok" CR));
result = rf.send(protocol, message); int msgLength = rf.send(protocol, message);
} else { if (msgLength > 0) {
Log.error(F("MQTTtoPilight failed json read" CR));
}
if (result > 0) {
Log.trace(F("Adv data MQTTtoPilight push state via PilighttoMQTT" CR)); Log.trace(F("Adv data MQTTtoPilight push state via PilighttoMQTT" CR));
pub(subjectGTWPilighttoMQTT, Pilightdata); pub(subjectGTWPilighttoMQTT, Pilightdata);
} else { } else {
switch (result) { switch (msgLength) {
case ESPiLight::ERROR_UNAVAILABLE_PROTOCOL: case ESPiLight::ERROR_UNAVAILABLE_PROTOCOL:
Log.error(F("protocol is not available" CR)); Log.error(F("protocol is not available" CR));
break; break;
@@ -160,10 +152,12 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
Log.error(F("no transmitter pin" CR)); Log.error(F("no transmitter pin" CR));
break; break;
default: default:
Log.error(F("invalid json data, can't read raw or message/protocol" CR)); Log.error(F("Invalid JSON: can't read message/protocol" CR));
break;
} }
} }
} else {
Log.error(F("MQTTtoPilight failed json read" CR));
}
} }
# ifdef ZradioCC1101 # ifdef ZradioCC1101
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on