mirror of
https://github.com/anklimov/lighthub
synced 2025-12-09 05:09:49 +03:00
homie topic strucrure correction
This commit is contained in:
@@ -198,7 +198,7 @@ boolean Item::getEnableCMD(int delta) {
|
||||
#define MAXCTRLPAR 3
|
||||
|
||||
|
||||
int Item::Ctrl(char * payload, boolean send){
|
||||
int Item::Ctrl(char * payload, boolean send, char * subItem){
|
||||
if (!payload) return 0;
|
||||
// debugSerial<<F("'")<<payload<<F("'")<<endl;
|
||||
int cmd = txt2cmd(payload);
|
||||
@@ -210,7 +210,7 @@ int Item::Ctrl(char * payload, boolean send){
|
||||
while (payload && i < 3)
|
||||
Par[i++] = getInt((char **) &payload);
|
||||
|
||||
return Ctrl(0, i, Par, send);
|
||||
return Ctrl(0, i, Par, send, subItem);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -227,7 +227,7 @@ int Item::Ctrl(char * payload, boolean send){
|
||||
Par[0] = map(hsv.h, 0, 255, 0, 365);
|
||||
Par[1] = map(hsv.s, 0, 255, 0, 100);
|
||||
Par[2] = map(hsv.v, 0, 255, 0, 100);
|
||||
return Ctrl(0, 3, Par, send);
|
||||
return Ctrl(0, 3, Par, send, subItem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -236,26 +236,26 @@ int Item::Ctrl(char * payload, boolean send){
|
||||
|
||||
// if (item.getEnableCMD(500) || lanStatus == 4)
|
||||
return Ctrl(cmd, 0, NULL,
|
||||
send); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||
send, subItem); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||
// else debugSerial<<F("on Skipped"));
|
||||
|
||||
break;
|
||||
default: //some known command
|
||||
return Ctrl(cmd, 0, NULL, send);
|
||||
return Ctrl(cmd, 0, NULL, send, subItem);
|
||||
|
||||
} //ctrl
|
||||
}
|
||||
|
||||
|
||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) {
|
||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem) {
|
||||
|
||||
debugSerial<<F(" MEM=")<<freeRam()<<F(" Cmd=")<<cmd<<F(" Par: ");
|
||||
debugSerial<<F(" MEM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd=")<<cmd<<F(" Par= ");
|
||||
if (!itemArr) return -1;
|
||||
int Par[MAXCTRLPAR] = {0, 0, 0};
|
||||
if (Parameters)
|
||||
for (short i=0;i<n && i<MAXCTRLPAR;i++){
|
||||
Par[i] = Parameters[i];
|
||||
debugSerial<<Par[i]<<F(",");
|
||||
debugSerial<<F("<")<<Par[i]<<F("> ");
|
||||
}
|
||||
debugSerial<<endl;
|
||||
int iaddr = getArg();
|
||||
|
||||
@@ -105,8 +105,8 @@ class Item
|
||||
Item(char * name);
|
||||
Item(aJsonObject * obj);
|
||||
boolean isValid ();
|
||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true);
|
||||
virtual int Ctrl(char * payload, boolean send=true);
|
||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, char * subItem=NULL);
|
||||
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
|
||||
|
||||
int getArg(short n=0);
|
||||
boolean getEnableCMD(int delta);
|
||||
|
||||
@@ -176,19 +176,18 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||
debugSerial<<F("OOM!");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
debugSerial<<((char) payload[i]);
|
||||
debugSerial<<endl;
|
||||
|
||||
|
||||
|
||||
short intopic = 0;
|
||||
short pfxlen = 0;
|
||||
char * itemName;
|
||||
{
|
||||
char buf[MQTT_TOPIC_LENGTH + 1];
|
||||
// strncpy_P(buf, inprefix, sizeof(buf));
|
||||
char * itemName = NULL;
|
||||
char * subItem = NULL;
|
||||
|
||||
{
|
||||
char buf[MQTT_TOPIC_LENGTH + 1];
|
||||
|
||||
|
||||
if (lanStatus == RETAINING_COLLECTING)
|
||||
{
|
||||
@@ -210,11 +209,7 @@ else
|
||||
intopic = strncmp(topic, buf, pfxlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant.
|
||||
if (intopic) {
|
||||
debugSerial<<F("Skipping..");
|
||||
@@ -227,21 +222,22 @@ else
|
||||
cmd_parse((char *)payload);
|
||||
return;
|
||||
}
|
||||
//char subtopic[MQTT_SUBJECT_LENGTH] = "";
|
||||
char *t;
|
||||
if (t = strchr(itemName, '/'))
|
||||
|
||||
if (subItem = strchr(itemName, '/'))
|
||||
{
|
||||
*t = 0;
|
||||
t++;
|
||||
debugSerial<<F("Subtopic:")<<t<<endl;
|
||||
//strncpy(subtopic, t + 1, MQTT_SUBJECT_LENGTH - 1);
|
||||
*subItem = 0;
|
||||
subItem++;
|
||||
// debugSerial<<F("Subitem:")<<subItem<<endl;
|
||||
}
|
||||
debugSerial<<F("Item:")<<itemName<<endl;
|
||||
// debugSerial<<F("Item:")<<itemName<<endl;
|
||||
|
||||
if (itemName[0]=='$' || subItem[0]=='$') return; //Skipping homie stuff
|
||||
|
||||
Item item(itemName);
|
||||
if (item.isValid()) {
|
||||
if (item.itemType == CH_GROUP && (lanStatus == RETAINING_COLLECTING))
|
||||
return; //Do not restore group channels - they consist not relevant data
|
||||
item.Ctrl((char *)payload, !(lanStatus == RETAINING_COLLECTING));
|
||||
item.Ctrl((char *)payload, !(lanStatus == RETAINING_COLLECTING),subItem);
|
||||
} //valid item
|
||||
}
|
||||
|
||||
@@ -378,19 +374,19 @@ void onMQTTConnect(){
|
||||
|
||||
// High level homie topics publishing
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, state_P, sizeof(topic));
|
||||
strncpy_P(buf, ready_P, sizeof(buf));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, name_P, sizeof(topic));
|
||||
strncpy_P(buf, nameval_P, sizeof(buf));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, stats_P, sizeof(topic));
|
||||
strncpy_P(buf, statsval_P, sizeof(buf));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
@@ -398,7 +394,7 @@ void onMQTTConnect(){
|
||||
#ifndef NO_HOMIE
|
||||
|
||||
// strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, homie_P, sizeof(topic));
|
||||
strncpy_P(buf, homiever_P, sizeof(buf));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
@@ -440,7 +436,7 @@ void onMQTTConnect(){
|
||||
} //switch
|
||||
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
|
||||
strncat(topic,item->name,sizeof(topic));
|
||||
strncat(topic,"/",sizeof(topic));
|
||||
@@ -450,7 +446,7 @@ void onMQTTConnect(){
|
||||
if (format[0])
|
||||
{
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
|
||||
strncat(topic,item->name,sizeof(topic));
|
||||
strncat(topic,"/",sizeof(topic));
|
||||
@@ -460,7 +456,7 @@ void onMQTTConnect(){
|
||||
item = item->next;
|
||||
} //if
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_OUT);
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, nodes_P, sizeof(topic));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
}
|
||||
@@ -519,7 +515,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
strncpy_P(willMessage,disconnected_P,sizeof(willMessage));
|
||||
|
||||
// strncpy_P(willTopic, outprefix, sizeof(willTopic));
|
||||
setTopic(willTopic,sizeof(willTopic),T_OUT);
|
||||
setTopic(willTopic,sizeof(willTopic),T_DEV);
|
||||
|
||||
strncat_P(willTopic, state_P, sizeof(willTopic));
|
||||
|
||||
|
||||
@@ -82,14 +82,17 @@
|
||||
#endif
|
||||
*/
|
||||
|
||||
//Default output topic
|
||||
#ifndef OUTTOPIC
|
||||
#define OUTTOPIC "s_out"
|
||||
#endif
|
||||
|
||||
//Topic to receive CLI commands
|
||||
#ifndef CMDTOPIC
|
||||
#define CMDTOPIC "command"
|
||||
#define CMDTOPIC "$command"
|
||||
#endif
|
||||
|
||||
//Default broadcast topic
|
||||
#ifndef INTOPIC
|
||||
#define INTOPIC "in"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user