mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 05:06:32 +00:00
fix multiple subscribes (#17567)
This commit is contained in:
parent
a334826906
commit
ca82877362
@ -1159,11 +1159,14 @@ bool RulesMqttData(void)
|
|||||||
}
|
}
|
||||||
bool serviced = false;
|
bool serviced = false;
|
||||||
String sTopic = XdrvMailbox.topic;
|
String sTopic = XdrvMailbox.topic;
|
||||||
String sData = XdrvMailbox.data;
|
String buData = XdrvMailbox.data;
|
||||||
//AddLog(LOG_LEVEL_DEBUG, PSTR("RUL: MQTT Topic %s, Event %s"), XdrvMailbox.topic, XdrvMailbox.data);
|
//AddLog(LOG_LEVEL_DEBUG, PSTR("RUL: MQTT Topic %s, Event %s"), XdrvMailbox.topic, XdrvMailbox.data);
|
||||||
MQTT_Subscription event_item;
|
MQTT_Subscription event_item;
|
||||||
//Looking for matched topic
|
//Looking for matched topic
|
||||||
for (uint32_t index = 0; index < subscriptions.size(); index++) {
|
for (uint32_t index = 0; index < subscriptions.size(); index++) {
|
||||||
|
|
||||||
|
String sData = buData;
|
||||||
|
|
||||||
event_item = subscriptions.get(index);
|
event_item = subscriptions.get(index);
|
||||||
|
|
||||||
//AddLog(LOG_LEVEL_DEBUG, PSTR("RUL: Match MQTT message Topic %s with subscription topic %s"), sTopic.c_str(), event_item.Topic.c_str());
|
//AddLog(LOG_LEVEL_DEBUG, PSTR("RUL: Match MQTT message Topic %s with subscription topic %s"), sTopic.c_str(), event_item.Topic.c_str());
|
||||||
|
@ -8260,7 +8260,7 @@ bool ScriptCommand(void) {
|
|||||||
Response_P(S_JSON_COMMAND_SVALUE, command, result.c_str());
|
Response_P(S_JSON_COMMAND_SVALUE, command, result.c_str());
|
||||||
#ifdef DEBUG_MQTT_EVENT
|
#ifdef DEBUG_MQTT_EVENT
|
||||||
} else if (CMND_SUBTEST == command_code) {
|
} else if (CMND_SUBTEST == command_code) {
|
||||||
XdrvMailbox.topic = (char*)"tele";
|
XdrvMailbox.topic = (char*)"stat/tasmota/SENSOR";
|
||||||
ScriptMqttData();
|
ScriptMqttData();
|
||||||
serviced = true;
|
serviced = true;
|
||||||
#endif
|
#endif
|
||||||
@ -8291,92 +8291,12 @@ void dateTime(uint16_t* date, uint16_t* time) {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef SUPPORT_MQTT_EVENT
|
#ifdef SUPPORT_MQTT_EVENT
|
||||||
/*
|
|
||||||
//#define DEBUG_MQTT_EVENT
|
|
||||||
// parser object, source keys, delimiter, float result or NULL, string result or NULL, string size
|
|
||||||
uint32_t JsonParsePath(JsonParserObject *jobj, const char *spath, char delim, float *nres, char *sres, uint32_t slen) {
|
|
||||||
uint32_t res = 0;
|
|
||||||
const char *cp = spath;
|
|
||||||
#ifdef DEBUG_JSON_PARSE_PATH
|
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("JSON: parsing json key: %s from json: %s"), cp, jpath);
|
|
||||||
#endif
|
|
||||||
JsonParserObject obj = *jobj;
|
|
||||||
JsonParserObject lastobj = obj;
|
|
||||||
char selem[32];
|
|
||||||
uint8_t aindex = 0;
|
|
||||||
String value = "";
|
|
||||||
while (1) {
|
|
||||||
// read next element
|
|
||||||
for (uint32_t sp=0; sp<sizeof(selem)-1; sp++) {
|
|
||||||
if (!*cp || *cp==delim) {
|
|
||||||
selem[sp] = 0;
|
|
||||||
cp++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
selem[sp] = *cp++;
|
|
||||||
}
|
|
||||||
#ifdef DEBUG_JSON_PARSE_PATH
|
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("JSON: cmp current key: %s"), selem);
|
|
||||||
#endif
|
|
||||||
// check for array
|
|
||||||
char *sp = strchr(selem,'[');
|
|
||||||
if (sp) {
|
|
||||||
*sp = 0;
|
|
||||||
aindex = atoi(sp+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now check element
|
|
||||||
obj = obj[selem];
|
|
||||||
if (!obj.isValid()) {
|
|
||||||
#ifdef DEBUG_JSON_PARSE_PATH
|
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("JSON: obj invalid: %s"), selem);
|
|
||||||
#endif
|
|
||||||
JsonParserToken tok = lastobj[selem];
|
|
||||||
if (tok.isValid()) {
|
|
||||||
if (tok.isArray()) {
|
|
||||||
JsonParserArray array = JsonParserArray(tok);
|
|
||||||
value = array[aindex].getStr();
|
|
||||||
if (array.isNum()) {
|
|
||||||
if (nres) *nres=tok.getFloat();
|
|
||||||
res = 1;
|
|
||||||
} else {
|
|
||||||
res = 2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
value = tok.getStr();
|
|
||||||
if (tok.isNum()) {
|
|
||||||
if (nres) *nres=tok.getFloat();
|
|
||||||
res = 1;
|
|
||||||
} else {
|
|
||||||
res = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#ifdef DEBUG_JSON_PARSE_PATH
|
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("JSON: token invalid: %s"), selem);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (obj.isObject()) {
|
|
||||||
lastobj = obj;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!*cp) break;
|
|
||||||
}
|
|
||||||
if (sres) {
|
|
||||||
strlcpy(sres,value.c_str(), slen);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#ifndef MQTT_EVENT_MSIZE
|
#ifndef MQTT_EVENT_MSIZE
|
||||||
#define MQTT_EVENT_MSIZE 256
|
#define MQTT_EVENT_MSIZE 256
|
||||||
#endif // MQTT_EVENT_MSIZE
|
#endif // MQTT_EVENT_MSIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Script: Process received MQTT message.
|
* Script: Process received MQTT message.
|
||||||
@ -8387,8 +8307,7 @@ uint32_t JsonParsePath(JsonParserObject *jobj, const char *spath, char delim, fl
|
|||||||
* true - The message is consumed.
|
* true - The message is consumed.
|
||||||
* false - The message is not in our list.
|
* false - The message is not in our list.
|
||||||
*/
|
*/
|
||||||
bool ScriptMqttData(void)
|
bool ScriptMqttData(void) {
|
||||||
{
|
|
||||||
bool serviced = false;
|
bool serviced = false;
|
||||||
//toLog(">>> 1");
|
//toLog(">>> 1");
|
||||||
//toLog(XdrvMailbox.data);
|
//toLog(XdrvMailbox.data);
|
||||||
@ -8396,7 +8315,7 @@ bool ScriptMqttData(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String sTopic = XdrvMailbox.topic;
|
String sTopic = XdrvMailbox.topic;
|
||||||
String sData = XdrvMailbox.data;
|
String buData = XdrvMailbox.data;
|
||||||
|
|
||||||
#ifdef DEBUG_MQTT_EVENT
|
#ifdef DEBUG_MQTT_EVENT
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("Script: MQTT Topic %s, Event %s"), XdrvMailbox.topic, XdrvMailbox.data);
|
AddLog(LOG_LEVEL_INFO, PSTR("Script: MQTT Topic %s, Event %s"), XdrvMailbox.topic, XdrvMailbox.data);
|
||||||
@ -8408,6 +8327,8 @@ bool ScriptMqttData(void)
|
|||||||
event_item = subscriptions.get(index);
|
event_item = subscriptions.get(index);
|
||||||
uint8_t json_valid = 0;
|
uint8_t json_valid = 0;
|
||||||
|
|
||||||
|
String sData = buData;
|
||||||
|
|
||||||
#ifdef DEBUG_MQTT_EVENT
|
#ifdef DEBUG_MQTT_EVENT
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("Script: Match MQTT message Topic %s with subscription topic %s and key %s"), sTopic.c_str(), event_item.Topic.c_str(),event_item.Key.c_str());
|
AddLog(LOG_LEVEL_INFO, PSTR("Script: Match MQTT message Topic %s with subscription topic %s and key %s"), sTopic.c_str(), event_item.Topic.c_str(),event_item.Key.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user