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:
1 parent
b047f5a505
commit
50ddbd7352
2 files changed
+87
-2
No files matched your search
+86
-2
@@ -64,12 +64,10 @@ boolean PilighttoMQTT(){
|
|||||||
trc(F("Rcv. Pilight"));
|
trc(F("Rcv. Pilight"));
|
||||||
String MQTTprotocol;
|
String MQTTprotocol;
|
||||||
String MQTTdeviceID;
|
String MQTTdeviceID;
|
||||||
String MQTTstatus;
|
|
||||||
String MQTTmessage;
|
String MQTTmessage;
|
||||||
|
|
||||||
MQTTprotocol = String(pilightrd.protocol);
|
MQTTprotocol = String(pilightrd.protocol);
|
||||||
MQTTdeviceID = String(pilightrd.deviceID);
|
MQTTdeviceID = String(pilightrd.deviceID);
|
||||||
MQTTstatus = String(pilightrd.status);
|
|
||||||
MQTTmessage = String(pilightrd.message);
|
MQTTmessage = String(pilightrd.message);
|
||||||
String MQTTPilightstring;
|
String MQTTPilightstring;
|
||||||
MQTTPilightstring = subjectPilighttoMQTT+String("/")+MQTTprotocol+String("/")+MQTTdeviceID;
|
MQTTPilightstring = subjectPilighttoMQTT+String("/")+MQTTprotocol+String("/")+MQTTdeviceID;
|
||||||
@@ -84,16 +82,102 @@ boolean PilighttoMQTT(){
|
|||||||
void pilightCallback(const String &protocol, const String &message, int status,
|
void pilightCallback(const String &protocol, const String &message, int status,
|
||||||
size_t repeats, const String &deviceID) {
|
size_t repeats, const String &deviceID) {
|
||||||
|
|
||||||
|
if (status == VALID) {
|
||||||
pilightrd.protocol=protocol;
|
pilightrd.protocol=protocol;
|
||||||
pilightrd.deviceID=deviceID;
|
pilightrd.deviceID=deviceID;
|
||||||
pilightrd.status=status;
|
pilightrd.status=status;
|
||||||
pilightrd.message=message;
|
pilightrd.message=message;
|
||||||
pilightrd.hasNewData=true;
|
pilightrd.hasNewData=true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQTTtoPilight(char * topicOri, char * datacallback) {
|
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
|
#endif
|
||||||
|
|
||||||
@@ -64,6 +64,7 @@ RF supported protocols
|
|||||||
//433Mhz Pilight MQTT Subjects and keys
|
//433Mhz Pilight MQTT Subjects and keys
|
||||||
#define subjectMQTTtoPilight Base_Topic Gateway_Name "/commands/MQTTtoPilight"
|
#define subjectMQTTtoPilight Base_Topic Gateway_Name "/commands/MQTTtoPilight"
|
||||||
#define subjectPilighttoMQTT Base_Topic Gateway_Name "/PilighttoMQTT"
|
#define subjectPilighttoMQTT Base_Topic Gateway_Name "/PilighttoMQTT"
|
||||||
|
#define PilightRAW "RAW"
|
||||||
|
|
||||||
/*-------------------PIN DEFINITIONS----------------------*/
|
/*-------------------PIN DEFINITIONS----------------------*/
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
|
|||||||
Reference in new issue
Block a user