Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc51711299 | |||
| 7dac483e58 | |||
| 168b042366 | |||
| 8f56efefd5 | |||
| 701631fff7 |
@@ -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,10 +22,20 @@ 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
|
||||
#define CONFIG_MQTT_IDX_Temp <TEMPidx>
|
||||
//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 topic
|
||||
#define CONFIG_MQTT_Hum_TOPIC "EST-C/<SensorName>/Hum"
|
||||
//Combi Custom Mqtt topic
|
||||
#define CONFIG_MQTT_Comb_TOPIC "EST-C/<SensorName>/Combi"
|
||||
32
src/main.cpp
32
src/main.cpp
@@ -21,11 +21,16 @@ 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;
|
||||
|
||||
//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;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
@@ -129,6 +134,8 @@ void loop()
|
||||
Serial.print(cTemp);
|
||||
Serial.println(" C");
|
||||
|
||||
//DomoticzMQTT
|
||||
if (CONFIG_DOMOTICZ_MSG == 1){
|
||||
StaticJsonDocument<100> JSONHum;
|
||||
StaticJsonDocument<100> JSONTemp;
|
||||
StaticJsonDocument<100> JSONComb;
|
||||
@@ -153,12 +160,31 @@ 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
|
||||
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();
|
||||
delay(60000); //1min
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user