Adjustments for sending Pilight messages including RAW messages

https://manual.pilight.org/programs/debug.html
https://manual.pilight.org/programs/raw.html

Considering a RAW receive handler
This commit is contained in:
Paul committed 2018-07-29 16:18:42 +01:00
1 parent b047f5a505
commit 50ddbd7352
2 files changed
+92 -7

No files matched your search

+91 -7
View File
@@ -64,12 +64,10 @@ boolean PilighttoMQTT(){
trc(F("Rcv. Pilight"));
String MQTTprotocol;
String MQTTdeviceID;
String MQTTstatus;
String MQTTmessage;
MQTTprotocol = String(pilightrd.protocol);
MQTTdeviceID = String(pilightrd.deviceID);
MQTTstatus = String(pilightrd.status);
MQTTmessage = String(pilightrd.message);
String MQTTPilightstring;
MQTTPilightstring = subjectPilighttoMQTT+String("/")+MQTTprotocol+String("/")+MQTTdeviceID;
@@ -84,16 +82,102 @@ boolean PilighttoMQTT(){
void pilightCallback(const String &protocol, const String &message, int status,
size_t repeats, const String &deviceID) {
pilightrd.protocol=protocol;
pilightrd.deviceID=deviceID;
pilightrd.status=status;
pilightrd.message=message;
pilightrd.hasNewData=true;
if (status == VALID) {
pilightrd.protocol=protocol;
pilightrd.deviceID=deviceID;
pilightrd.status=status;
pilightrd.message=message;
pilightrd.hasNewData=true;
}
}
void MQTTtoPilight(char * topicOri, char * datacallback) {
String topic = topicOri;
int pos = topic.lastIndexOf(subjectMQTTtoPilight);
if (pos == -1){
return;
}
trc(F("Adv data PilighttoMQTT"));
char *last = strrchr(topicOri, '/');
String protocol = "";
if (last+1 != NULL) {
protocol = last+1;
}
int result = 0;
if (protocol == PilightRAW){
trc(F("RAW:"));
trc(String(datacallback));
uint16_t rawpulses[MAXPULSESTREAMLENGTH];
int rawlen =
rf.stringToPulseTrain(datacallback, rawpulses, MAXPULSESTREAMLENGTH);
if (rawlen > 0) {
rf.sendPulseTrain(rawpulses, rawlen);
result = rawlen;
} else {
result = -9999;
}
} else {
trc(F("PROTO:"));
trc(protocol);
result = rf.send(protocol, datacallback);
}
String MQTTmessage;
String MQTTprotocol = String(protocol);
String MQTTPilightstring = subjectPilighttoMQTT+String("/")+MQTTprotocol+String("/");
if (result > 0) {
trc(F("Adv data MQTTtoPilight push state via PilighttoMQTT"));
MQTTmessage = String(datacallback);
char *deviceID = "0";
DynamicJsonBuffer jb;
JsonObject& rjson = jb.parseObject(MQTTmessage);
if (rjson.success()) {
strcpy(deviceID, rjson["id"]);
}
MQTTmessage = String(datacallback);
MQTTPilightstring += String(deviceID);
} else {
switch (result) {
case ESPiLight::ERROR_UNAVAILABLE_PROTOCOL:
MQTTmessage = "protocol is not avaiable";
break;
case ESPiLight::ERROR_INVALID_PILIGHT_MSG:
MQTTmessage = "message is invalid";
break;
case ESPiLight::ERROR_INVALID_JSON:
MQTTmessage = "message is not a proper json object";
break;
case ESPiLight::ERROR_NO_OUTPUT_PIN:
MQTTmessage = "no transmitter pin";
break;
case -9999:
MQTTmessage = "invalid pulse train message";
break;
}
trc(F("ESPiLight Error: "));
trc(String(MQTTmessage));
MQTTPilightstring += String("error");
}
client.publish((char *)MQTTPilightstring.c_str(),(char *)MQTTmessage.c_str());
}
#endif
+1
View File
@@ -64,6 +64,7 @@ RF supported protocols
//433Mhz Pilight MQTT Subjects and keys
#define subjectMQTTtoPilight Base_Topic Gateway_Name "/commands/MQTTtoPilight"
#define subjectPilighttoMQTT Base_Topic Gateway_Name "/PilighttoMQTT"
#define PilightRAW "RAW"
/*-------------------PIN DEFINITIONS----------------------*/
#ifdef ESP8266