1
0

Added config options for type of mqtt message

Added toggle for Domoticz and custom Mqtt messages
This commit is contained in:
2021-12-12 18:23:10 +01:00
parent 8f56efefd5
commit 168b042366
2 changed files with 47 additions and 33 deletions

View File

@@ -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 "<MQTT-Addres>"
#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 <TEMP+HUMidx>
//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 <HUMidx>
//Custom mqtt msg
#define CONFIG_CUSTOM_MSG 1
//Temprature Custom Mqtt topic
#define CONFIG_MQTT_Temp_TOPIC "EST-C/<SensorName>/Temp"
//Humidity Custom Mqtt topi

View File

@@ -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,6 +133,8 @@ void loop()
Serial.print(cTemp);
Serial.println(" C");
//DomoticzMQTT
if (CONFIG_DOMOTICZ_MSG == 1){
StaticJsonDocument<100> JSONHum;
StaticJsonDocument<100> JSONTemp;
StaticJsonDocument<100> JSONComb;
@@ -157,15 +159,24 @@ void loop()
serializeJson(JSONComb, buffer3);
if (client.publish(domotopic, buffer1) == true) {
Serial.println("Published MQTT messages");
Serial.println("Published Domoticz MQTT messages");
} else {
Serial.println("Error sending MQTT messages");
Serial.println("Error Domoticz sending MQTT messages");
}
client.publish(domotopic, buffer2);
client.publish(domotopic, buffer3);
}
//Custom Mqtt
client.publish(custom_temperature_topic, String(cTemp).c_str(), true);
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
}
}