From db8df1ddf650d4e6550d739e04a5e2e57c8132f2 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Fri, 20 Dec 2019 23:01:56 +0100 Subject: [PATCH] Hass discovery improvments (#512) Rename set commands to config correct json buffer size and gateway name replace state to cmd replace set by config add restart and erase command add unicity to gateway command switches BLE devices shouldn't be child of the gateway make the BTtoMQTT topic consistent with other definitions --- docs/use/actuators.md | 4 +-- docs/use/ble.md | 12 ++++----- docs/use/gateway.md | 4 +-- main/User_config.h | 2 +- main/ZactuatorONOFF.ino | 2 +- main/ZgatewayBT.ino | 54 ++++++++++++++++++++--------------------- main/ZmqttDiscovery.ino | 33 +++++++++++++++++-------- main/config_BT.h | 4 +-- main/main.ino | 16 ++++++------ test/Test_config.h | 2 +- 10 files changed, 74 insertions(+), 59 deletions(-) diff --git a/docs/use/actuators.md b/docs/use/actuators.md index c8c35b3..221e5df 100644 --- a/docs/use/actuators.md +++ b/docs/use/actuators.md @@ -14,10 +14,10 @@ ON command or with [json receiving](../upload/pio.md#api) OFF command: -`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"pin":15,"state":0}'` +`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"pin":15,"cmd":0}'` ON command -`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"pin":15,"state":1}'` +`mosquitto_pub -t home/OpenMQTTGateway_MEGA/commands/MQTTtoONOFF -m '{"pin":15,"cmd":1}'` ## FASTLED ### The FASTLED module support 2 different operation modes diff --git a/docs/use/ble.md b/docs/use/ble.md index cb93741..251ae6d 100644 --- a/docs/use/ble.md +++ b/docs/use/ble.md @@ -52,11 +52,11 @@ More info are available on [my blog](https://1technophile.blogspot.fr/2017/11/mi ## Setting a white or black list A black list is a list of mac adresses that will never be published by OMG to set black list -`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"black-list":["012314551615","4C6577889C79","4C65A6663C79"]}'` +`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"black-list":["012314551615","4C6577889C79","4C65A6663C79"]}'` A white list is a list of mac adresses permitted to be published by OMG to set white list -`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"white-list":["012314551615","4C65A5553C79","4C65A6663C79"]}'` +`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"white-list":["012314551615","4C65A5553C79","4C65A6663C79"]}'` Note: if you want to filter (white or black list) on BLE sensors that are auto discovered, you need to wait for the discovery before applying the white or black list @@ -64,11 +64,11 @@ Note: if you want to filter (white or black list) on BLE sensors that are auto d If you want to change the time between readings you can change the interval by MQTT, if you want the BLE scan every 66seconds: -`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"interval":66000}'` +`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"interval":66000}'` you can also force a scan to be done by the following command: -`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"interval":0}'` +`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"interval":0}'` Once done the previous value of interval will be recovered. @@ -78,11 +78,11 @@ The default value is set into config_BT.h If you want to change the minimum RSSI value accepted for a device to be published, you can change it by MQTT. For example if you want to set -80 -`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"minrssi":-80}'` +`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"minrssi":-80}'` you can also accept all the devices by the following command: -`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"minrssi":0}'` +`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"minrssi":0}'` The default value is set into config_BT.h diff --git a/docs/use/gateway.md b/docs/use/gateway.md index de946be..99e9660 100644 --- a/docs/use/gateway.md +++ b/docs/use/gateway.md @@ -2,8 +2,8 @@ ## Restart the ESP -`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/set" -m '{"cmd":"restart"}'` +`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"cmd":"restart"}'` ## Erase the ESP settings -`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/set" -m '{"cmd":"erase"}'` +`mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoSYS/config" -m '{"cmd":"erase"}'` diff --git a/main/User_config.h b/main/User_config.h index 7f30d84..9ad957f 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -229,7 +229,7 @@ char gateway_name[parameters_size * 2] = Gateway_Name; #define TimeBetweenReadingSYS 120000 // time between system readings (like memory) #define subjectSYStoMQTT "/SYStoMQTT" -#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/set" +#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/config" //#define subjectTRACEtoMQTT "OpenMQTTGateway/log" //uncomment if you want to see traces on OpenMQTTGateway/log topic diff --git a/main/ZactuatorONOFF.ino b/main/ZactuatorONOFF.ino index 9fca327..8a0dbc0 100644 --- a/main/ZactuatorONOFF.ino +++ b/main/ZactuatorONOFF.ino @@ -36,7 +36,7 @@ void MQTTtoONOFF(char *topicOri, JsonObject &ONOFFdata) if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) { trc(F("MQTTtoONOFF json data analysis")); - int boolSWITCHTYPE = ONOFFdata["state"] | 99; + int boolSWITCHTYPE = ONOFFdata["cmd"] | 99; int pin = ONOFFdata["pin"] | ACTUATOR_ONOFF_PIN; if (boolSWITCHTYPE != 99) { diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 46e38b6..5b24d17 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -139,13 +139,13 @@ void MiFloraDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(MiFlorasensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + MiFlorasensor[i][1]; createDiscovery(MiFlorasensor[i][0], (char *)discovery_topic.c_str(), MiFlorasensor[i][1], (char *)unique_id.c_str(), will_Topic, MiFlorasensor[i][3], MiFlorasensor[i][4], MiFlorasensor[i][5], MiFlorasensor[i][6], MiFlorasensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -171,13 +171,13 @@ void VegTrugDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(VegTrugsensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + VegTrugsensor[i][1]; createDiscovery(VegTrugsensor[i][0], (char *)discovery_topic.c_str(), VegTrugsensor[i][1], (char *)unique_id.c_str(), will_Topic, VegTrugsensor[i][3], VegTrugsensor[i][4], VegTrugsensor[i][5], VegTrugsensor[i][6], VegTrugsensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -202,13 +202,13 @@ void MiJiaDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(MiJiasensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + MiJiasensor[i][1]; createDiscovery(MiJiasensor[i][0], (char *)discovery_topic.c_str(), MiJiasensor[i][1], (char *)unique_id.c_str(), will_Topic, MiJiasensor[i][3], MiJiasensor[i][4], MiJiasensor[i][5], MiJiasensor[i][6], MiJiasensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -233,13 +233,13 @@ void LYWSD02Discovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(LYWSD02sensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + LYWSD02sensor[i][1]; createDiscovery(LYWSD02sensor[i][0], (char *)discovery_topic.c_str(), LYWSD02sensor[i][1], (char *)unique_id.c_str(), will_Topic, LYWSD02sensor[i][3], LYWSD02sensor[i][4], LYWSD02sensor[i][5], LYWSD02sensor[i][6], LYWSD02sensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -264,13 +264,13 @@ void CLEARGRASSTRHDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(CLEARGRASSTRHsensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + CLEARGRASSTRHsensor[i][1]; createDiscovery(CLEARGRASSTRHsensor[i][0], (char *)discovery_topic.c_str(), CLEARGRASSTRHsensor[i][1], (char *)unique_id.c_str(), will_Topic, CLEARGRASSTRHsensor[i][3], CLEARGRASSTRHsensor[i][4], CLEARGRASSTRHsensor[i][5], CLEARGRASSTRHsensor[i][6], CLEARGRASSTRHsensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -295,13 +295,13 @@ void CLEARGRASSTRHKPADiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(CLEARGRASSTRHKPAsensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + CLEARGRASSTRHKPAsensor[i][1]; createDiscovery(CLEARGRASSTRHKPAsensor[i][0], (char *)discovery_topic.c_str(), CLEARGRASSTRHKPAsensor[i][1], (char *)unique_id.c_str(), will_Topic, CLEARGRASSTRHKPAsensor[i][3], CLEARGRASSTRHKPAsensor[i][4], CLEARGRASSTRHKPAsensor[i][5], CLEARGRASSTRHKPAsensor[i][6], CLEARGRASSTRHKPAsensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -324,13 +324,13 @@ void MiScaleDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(MiScalesensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + MiScalesensor[i][1]; createDiscovery(MiScalesensor[i][0], (char *)discovery_topic.c_str(), MiScalesensor[i][1], (char *)unique_id.c_str(), will_Topic, MiScalesensor[i][3], MiScalesensor[i][4], MiScalesensor[i][5], MiScalesensor[i][6], MiScalesensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -353,13 +353,13 @@ void MiLampDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(MiLampsensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + MiLampsensor[i][1]; createDiscovery(MiLampsensor[i][0], (char *)discovery_topic.c_str(), MiLampsensor[i][1], (char *)unique_id.c_str(), will_Topic, MiLampsensor[i][3], MiLampsensor[i][4], MiLampsensor[i][5], MiLampsensor[i][6], MiLampsensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -382,13 +382,13 @@ void MiBandDiscovery(char *mac) { trc(F("CreateDiscoverySensor")); trc(MiBandsensor[i][1]); - String discovery_topic = String(subjectBTtoMQTT) + String(mac); + String discovery_topic = String(subjectBTtoMQTT) + "/" + String(mac); String unique_id = String(mac) + "-" + MiBandsensor[i][1]; createDiscovery(MiBandsensor[i][0], (char *)discovery_topic.c_str(), MiBandsensor[i][1], (char *)unique_id.c_str(), will_Topic, MiBandsensor[i][3], MiBandsensor[i][4], MiBandsensor[i][5], MiBandsensor[i][6], MiBandsensor[i][7], - 0, "", "", true, ""); + 0, "", "", false, ""); } BLEdevice device; strcpy(device.macAdr, mac); @@ -428,7 +428,7 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks BLEdata.set("id", (char *)mac_adress.c_str()); mac_adress.replace(":", ""); mac_adress.toUpperCase(); - String mactopic = subjectBTtoMQTT + mac_adress; + String mactopic = subjectBTtoMQTT + String("/") + mac_adress; char mac[mac_adress.length() + 1]; mac_adress.toCharArray(mac, mac_adress.length() + 1); trc("device detected"); @@ -791,7 +791,7 @@ bool BTtoMQTT() trc(HomePresenceId); BLEdata.set("id", (char *)HomePresenceId.c_str()); #endif - String topic = subjectBTtoMQTT + String(d[0].extract); + String topic = subjectBTtoMQTT + String("/") + String(d[0].extract); int rssi = (int)strtol(d[2].extract, NULL, 16) - 256; BLEdata.set("rssi", (int)rssi); #ifdef subjectHomePresence @@ -1000,7 +1000,7 @@ bool process_sensors(int offset, char *rest_data, char *mac_adress) return false; } String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } @@ -1022,7 +1022,7 @@ bool process_scale_v1(char *rest_data, char *mac_adress) // Publish weight String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } @@ -1046,7 +1046,7 @@ bool process_scale_v2(char *rest_data, char *mac_adress) // Publish weight String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } @@ -1068,7 +1068,7 @@ bool process_miband(char *rest_data, char *mac_adress) // Publish weight String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } @@ -1091,7 +1091,7 @@ bool process_milamp(char *rest_data, char *mac_adress) // Publish String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } @@ -1119,7 +1119,7 @@ bool process_cleargrass_air(char *rest_data, char *mac_adress) BLEdata.set("pres", (double)value / 100); String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } @@ -1143,7 +1143,7 @@ bool process_cleargrass(char *rest_data, char *mac_adress) BLEdata.set("hum", (double)value / 10); String mactopic(mac_adress); - mactopic = subjectBTtoMQTT + mactopic; + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char *)mactopic.c_str(), BLEdata); return true; } diff --git a/main/ZmqttDiscovery.ino b/main/ZmqttDiscovery.ino index 6f93af9..6436334 100644 --- a/main/ZmqttDiscovery.ino +++ b/main/ZmqttDiscovery.ino @@ -102,10 +102,9 @@ void createDiscovery(char *sensor_type, if (child_device) { - const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5) + JSON_ARRAY_SIZE(2); - StaticJsonBuffer jsonDeviceBuffer; + StaticJsonBuffer jsonDeviceBuffer; JsonObject &device = jsonDeviceBuffer.createObject(); - device.set("name", Gateway_Name); + device.set("name", gateway_name); device.set("manufacturer", DEVICEMANUFACTURER); device.set("sw_version", OMG_VERSION); JsonArray &identifiers = device.createNestedArray("identifiers"); @@ -119,12 +118,26 @@ void createDiscovery(char *sensor_type, void pubMqttDiscovery() { trc(F("omgStatusDiscovery")); - createDiscovery("binary_sensor", //set sensorType + createDiscovery("binary_sensor", //set Type will_Topic, Gateway_Name, (char *)getUniqueId("", "").c_str(), //set state_topic,name,uniqueId will_Topic, "connectivity", "", //set availability_topic,device_class,value_template, Gateway_AnnouncementMsg, will_Message, "", //set,payload_on,payload_off,unit_of_meas, - 0, //set optimistic,retain, off_delay - Gateway_AnnouncementMsg, will_Message, true, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic, state on, state off + 0, //set off_delay + Gateway_AnnouncementMsg, will_Message, false, "" //set,payload_avalaible,payload_not avalaible ,is a child device, command topic + ); + createDiscovery("switch", //set Type + will_Topic, "restart OMG", (char *)getUniqueId("restart", "").c_str(), //set state_topic,name,uniqueId + will_Topic, "", "", //set availability_topic,device_class,value_template, + "{\"cmd\":\"restart\"}", "", "", //set,payload_on,payload_off,unit_of_meas, + 0, //set off_delay + Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset //set,payload_avalaible,payload_not avalaible ,is a child device, command topic + ); + createDiscovery("switch", //set Type + will_Topic, "erase OMG", (char *)getUniqueId("erase", "").c_str(), //set state_topic,name,uniqueId + will_Topic, "", "", //set availability_topic,device_class,value_template, + "{\"cmd\":\"erase\"}", "", "", //set,payload_on,payload_off,unit_of_meas, + 0, //set off_delay + Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset //set,payload_avalaible,payload_not avalaible ,is a child device, command topic ); #ifdef ZsensorBME280 @@ -173,7 +186,7 @@ void pubMqttDiscovery() #ifdef ZsensorADC trc(F("ADCDiscovery")); - char *ADCsensor[8] = {"sensor", "adc", "adc", "", "{{ value_json.adc }}", "", "", ""}; + char *ADCsensor[8] = {"sensor", "adc", "", "", "{{ value_json.adc }}", "", "", ""}; //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement trc(F("CreateDiscoverySensor")); @@ -231,7 +244,7 @@ void pubMqttDiscovery() #ifdef ZsensorHCSR501 trc(F("HCSR501Discovery")); - char *HCSR501sensor[8] = {"binary_sensor", "hcsr501", "hcsr501", "", "{{value_json.hcsr501}}", "true", "false", ""}; + char *HCSR501sensor[8] = {"binary_sensor", "hcsr501", "", "", "{{value_json.hcsr501}}", "true", "false", ""}; //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement trc(F("CreateDiscoverySensor")); @@ -245,7 +258,7 @@ void pubMqttDiscovery() #ifdef ZsensorGPIOInput trc(F("GPIOInputDiscovery")); - char *GPIOInputsensor[8] = {"binary_sensor", "GPIOInput", "GPIOInput", "", "{{value_json.gpio}}", "HIGH", "LOW", ""}; + char *GPIOInputsensor[8] = {"binary_sensor", "GPIOInput", "", "", "{{value_json.gpio}}", "HIGH", "LOW", ""}; //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement trc(F("CreateDiscoverySensor")); @@ -281,7 +294,7 @@ void pubMqttDiscovery() #ifdef ZactuatorONOFF trc(F("actuatorONOFFDiscovery")); - char *actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "", "ON", "OFF", ""}; + char *actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "", "{\"cmd\":1}", "{\"cmd\":0}", ""}; //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement trc(F("CreateDiscoverySensor")); diff --git a/main/config_BT.h b/main/config_BT.h index f99ca56..967f36f 100644 --- a/main/config_BT.h +++ b/main/config_BT.h @@ -30,8 +30,8 @@ extern void setupBT(); extern bool BTtoMQTT(); extern void MQTTtoBT(char * topicOri, JsonObject& RFdata); /*----------------------BT topics & parameters-------------------------*/ -#define subjectBTtoMQTT "/BTtoMQTT/" -#define subjectMQTTtoBTset "/commands/MQTTtoBT/set" +#define subjectBTtoMQTT "/BTtoMQTT" +#define subjectMQTTtoBTset "/commands/MQTTtoBT/config" #define TimeBtw_Read 55555 //define default time between 2 scans #define MinimumRSSI -100 //default minimum rssi value, all the devices below -90 will not be reported #define Scan_duration 10 //define the time for a scan --WARNING-- changing this value can lead to instability on ESP32 diff --git a/main/main.ino b/main/main.ino index 6e600d2..c09e8b8 100644 --- a/main/main.ino +++ b/main/main.ino @@ -296,7 +296,7 @@ void trc(JsonObject &data) void pub(char *topicori, char *payload, bool retainFlag) { String topic = String(mqtt_topic) + String(topicori); - client.publish((char *)topic.c_str(), payload, retainFlag); + pubMQTT((char *)topic.c_str(), payload, retainFlag); } void pub(char *topicori, JsonObject &data) @@ -502,7 +502,6 @@ bool cmpToMainTopic(char * topicOri, char * toAdd){ } } - void reconnect() { @@ -516,7 +515,10 @@ void reconnect() while (!client.connected()) { trc(F("MQTT connection...")); //F function enable to decrease sram usage - if (client.connect(gateway_name, mqtt_user, mqtt_pass, will_Topic, will_QoS, will_Retain, will_Message)) + char topic[mqtt_topic_max_size]; + strcpy(topic,mqtt_topic); + strcat(topic,will_Topic); + if (client.connect(gateway_name, mqtt_user, mqtt_pass, topic, will_QoS, will_Retain, will_Message)) { trc(F("Connected to broker")); failure_number = 0; @@ -525,10 +527,10 @@ void reconnect() // publish version pub(version_Topic, OMG_VERSION, will_Retain); //Subscribing to topic - char topic[mqtt_topic_max_size]; - strcpy(topic,mqtt_topic); - strcat(topic,subjectMQTTtoX); - if (client.subscribe(topic)) + char topic2[mqtt_topic_max_size]; + strcpy(topic2,mqtt_topic); + strcat(topic2,subjectMQTTtoX); + if (client.subscribe(topic2)) { #ifdef ZgatewayRF client.subscribe(subjectMultiGTWRF); // subject on which other OMG will publish, this OMG will store these msg and by the way don't republish them if they have been already published diff --git a/test/Test_config.h b/test/Test_config.h index 6840491..0e4b8f3 100644 --- a/test/Test_config.h +++ b/test/Test_config.h @@ -176,6 +176,6 @@ char gateway_name[parameters_size * 2] = Gateway_Name; #endif #define TimeBetweenReadingSYS 120000 // time between system readings (like memory) #define subjectSYStoMQTT "/SYStoMQTT" -#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/set" +#define subjectMQTTtoSYSset "/commands/MQTTtoSYS/config" #endif