1
0

Compare commits

5 Commits
Domo ... master

Author SHA1 Message Date
bc51711299 *added missed file 2021-12-14 21:39:38 +01:00
7dac483e58 Added combined json msg 2021-12-14 21:39:16 +01:00
168b042366 Added config options for type of mqtt message
Added toggle for Domoticz and custom Mqtt messages
2021-12-12 18:23:10 +01:00
8f56efefd5 Update 'src/config.h-Example' 2021-03-15 23:47:39 +00:00
701631fff7 Added custom Mqtt topic for temp/hum sensor 2021-03-11 19:21:52 +01:00
2 changed files with 67 additions and 30 deletions

View File

@@ -13,6 +13,7 @@ IPAddress local_IP(192,168,1,10);
IPAddress gateway(192,168,1,1); IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0); IPAddress subnet(255,255,255,0);
IPAddress dns(1,1,1,1); IPAddress dns(1,1,1,1);
// MQTT Config // MQTT Config
#define CONFIG_MQTT_HOST "<MQTT-Addres>" #define CONFIG_MQTT_HOST "<MQTT-Addres>"
#define CONFIG_MQTT_PORT 1883 #define CONFIG_MQTT_PORT 1883
@@ -21,10 +22,20 @@ IPAddress dns(1,1,1,1);
#define CONFIG_MQTT_CLIENT_ID "TempProbe" #define CONFIG_MQTT_CLIENT_ID "TempProbe"
//Domoticz Config //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 //IDX for virtual Temp + Humidity sensor
#define CONFIG_MQTT_IDX_Comb <TEMP+HUMidx> #define CONFIG_MQTT_IDX_Comb <TEMP+HUMidx>
//IDX for virtual Temp sensor //IDX for virtual Temp sensor
#define CONFIG_MQTT_IDX_Temp <TEMPidx> #define CONFIG_MQTT_IDX_Temp <TEMPidx>
//IDX for virtual Humidity sensor //IDX for virtual Humidity sensor
#define CONFIG_MQTT_IDX_Hum <HUMidx> #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 topic
#define CONFIG_MQTT_Hum_TOPIC "EST-C/<SensorName>/Hum"
//Combi Custom Mqtt topic
#define CONFIG_MQTT_Comb_TOPIC "EST-C/<SensorName>/Combi"

View File

@@ -21,11 +21,16 @@ const char* mqttPassword = CONFIG_MQTT_PASS;
const char* mqttClientId = CONFIG_MQTT_CLIENT_ID; const char* mqttClientId = CONFIG_MQTT_CLIENT_ID;
//Domoticz //Domoticz
const char* domotopic = CONFIG_MQTT_TOPIC; const char* domotopic = CONFIG_MQTT_DOMOTICZ_TOPIC;
const int idxcomb = CONFIG_MQTT_IDX_Comb; const int idxcomb = CONFIG_MQTT_IDX_Comb;
const int idxtemp = CONFIG_MQTT_IDX_Temp; const int idxtemp = CONFIG_MQTT_IDX_Temp;
const int idxhum = CONFIG_MQTT_IDX_Hum; const int idxhum = CONFIG_MQTT_IDX_Hum;
//CustomMqtt
const char* custom_temperature_topic = CONFIG_MQTT_Temp_TOPIC;
const char* custom_humidity_topic = CONFIG_MQTT_Hum_TOPIC ;
const char* custom_combi_topic = CONFIG_MQTT_Comb_TOPIC ;
WiFiClient espClient; WiFiClient espClient;
PubSubClient client(espClient); PubSubClient client(espClient);
@@ -129,6 +134,8 @@ void loop()
Serial.print(cTemp); Serial.print(cTemp);
Serial.println(" C"); Serial.println(" C");
//DomoticzMQTT
if (CONFIG_DOMOTICZ_MSG == 1){
StaticJsonDocument<100> JSONHum; StaticJsonDocument<100> JSONHum;
StaticJsonDocument<100> JSONTemp; StaticJsonDocument<100> JSONTemp;
StaticJsonDocument<100> JSONComb; StaticJsonDocument<100> JSONComb;
@@ -153,12 +160,31 @@ void loop()
serializeJson(JSONComb, buffer3); serializeJson(JSONComb, buffer3);
if (client.publish(domotopic, buffer1) == true) { if (client.publish(domotopic, buffer1) == true) {
Serial.println("Published MQTT messages"); Serial.println("Published Domoticz MQTT messages");
} else { } else {
Serial.println("Error sending MQTT messages"); Serial.println("Error Domoticz sending MQTT messages");
} }
client.publish(domotopic, buffer2); client.publish(domotopic, buffer2);
client.publish(domotopic, buffer3); client.publish(domotopic, buffer3);
}
//Custom Mqtt
if (CONFIG_CUSTOM_MSG == 1){
StaticJsonDocument<100> JSONCustomComb;
JSONCustomComb["humidity"] = roundf(CalcHumidity * 100) / 100;
JSONCustomComb["temperature"] = roundf(cTemp * 100) / 100;
char buffer4[256];
serializeJson(JSONCustomComb, buffer4);
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.publish(custom_combi_topic, buffer4);
client.loop(); client.loop();
delay(60000); //1min delay(60000); //1min
}
} }