diff --git a/src/config.h-Example b/src/config.h-Example index e10b44d..1814cbe 100644 --- a/src/config.h-Example +++ b/src/config.h-Example @@ -13,6 +13,7 @@ IPAddress local_IP(192,168,1,10); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); IPAddress dns(1,1,1,1); + // MQTT Config #define CONFIG_MQTT_HOST "" #define CONFIG_MQTT_PORT 1883 @@ -21,7 +22,8 @@ IPAddress dns(1,1,1,1); #define CONFIG_MQTT_CLIENT_ID "TempProbe" //Domoticz Config -#define CONFIG_MQTT_TOPIC "domoticz/in" +#define CONFIG_DOMOTICZ_MSG 1 +#define CONFIG_MQTT_DOMOTICZ_TOPIC "domoticz/in" //IDX for virtual Temp + Humidity sensor #define CONFIG_MQTT_IDX_Comb //IDX for virtual Temp sensor @@ -29,7 +31,8 @@ IPAddress dns(1,1,1,1); //IDX for virtual Humidity sensor #define CONFIG_MQTT_IDX_Hum - +//Custom mqtt msg +#define CONFIG_CUSTOM_MSG 1 //Temprature Custom Mqtt topic #define CONFIG_MQTT_Temp_TOPIC "EST-C//Temp" //Humidity Custom Mqtt topi diff --git a/src/main.cpp b/src/main.cpp index 04011c2..264924d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ const char* mqttPassword = CONFIG_MQTT_PASS; const char* mqttClientId = CONFIG_MQTT_CLIENT_ID; //Domoticz -const char* domotopic = CONFIG_MQTT_TOPIC; +const char* domotopic = CONFIG_MQTT_DOMOTICZ_TOPIC; const int idxcomb = CONFIG_MQTT_IDX_Comb; const int idxtemp = CONFIG_MQTT_IDX_Temp; const int idxhum = CONFIG_MQTT_IDX_Hum; @@ -133,39 +133,50 @@ void loop() Serial.print(cTemp); Serial.println(" C"); - StaticJsonDocument<100> JSONHum; - StaticJsonDocument<100> JSONTemp; - StaticJsonDocument<100> JSONComb; + //DomoticzMQTT + if (CONFIG_DOMOTICZ_MSG == 1){ + StaticJsonDocument<100> JSONHum; + StaticJsonDocument<100> JSONTemp; + StaticJsonDocument<100> JSONComb; - JSONHum["idx"] = idxhum; - JSONHum["nvalue"] = RoundHumidity; - JSONHum["svalue"] = "0"; - - JSONTemp["idx"] = idxtemp; - JSONTemp["nvalue"] = 0; - JSONTemp["svalue"] = String(cTemp) ; + JSONHum["idx"] = idxhum; + JSONHum["nvalue"] = RoundHumidity; + JSONHum["svalue"] = "0"; + + JSONTemp["idx"] = idxtemp; + JSONTemp["nvalue"] = 0; + JSONTemp["svalue"] = String(cTemp) ; - JSONComb["idx"] = idxcomb; - JSONComb["nvalue"] = 0; - JSONComb["svalue"] = String(cTemp) + String(";") + String(CalcHumidity) + String(";0"); + JSONComb["idx"] = idxcomb; + JSONComb["nvalue"] = 0; + JSONComb["svalue"] = String(cTemp) + String(";") + String(CalcHumidity) + String(";0"); - char buffer1[256]; - char buffer2[256]; - char buffer3[256]; - serializeJson(JSONTemp, buffer1); - serializeJson(JSONHum, buffer2); - serializeJson(JSONComb, buffer3); + char buffer1[256]; + char buffer2[256]; + char buffer3[256]; + serializeJson(JSONTemp, buffer1); + serializeJson(JSONHum, buffer2); + serializeJson(JSONComb, buffer3); + + if (client.publish(domotopic, buffer1) == true) { + Serial.println("Published Domoticz MQTT messages"); + } else { + Serial.println("Error Domoticz sending MQTT messages"); + } + client.publish(domotopic, buffer2); + client.publish(domotopic, buffer3); + } - if (client.publish(domotopic, buffer1) == true) { - Serial.println("Published MQTT messages"); - } else { - Serial.println("Error sending MQTT messages"); - } - client.publish(domotopic, buffer2); - client.publish(domotopic, buffer3); //Custom Mqtt - client.publish(custom_temperature_topic, String(cTemp).c_str(), true); - client.publish(custom_humidity_topic, String(CalcHumidity).c_str(), true); - client.loop(); - delay(60000); //1min + if (CONFIG_CUSTOM_MSG == 1){ + if (client.publish(custom_temperature_topic, String(cTemp).c_str(), true) == true) { + Serial.println("Published Custom MQTT messages"); + } else { + Serial.println("Error Custom sending MQTT messages"); + } + + client.publish(custom_humidity_topic, String(CalcHumidity).c_str(), true); + client.loop(); + delay(60000); //1min + } } \ No newline at end of file