New iobroker
This commit is contained in:
@@ -20,7 +20,9 @@
|
||||
#define WIFI_SSID "wf-home"
|
||||
#define WIFI_PASSWORD "0ndthnrf"
|
||||
#define MY_HOSTNAME "ESP8266_GW"
|
||||
#define MQTT_SERV "192.168.1.250"
|
||||
//#define MQTT_SERV "192.168.1.250"
|
||||
#define MQTT_SERV "192.168.1.111"
|
||||
#define TOPIC "home/"
|
||||
|
||||
#define MAX_PAGE (4)
|
||||
#define MAX_HSP (99)
|
||||
@@ -68,7 +70,8 @@ Ticker mqttReconnectTimer;
|
||||
WiFiEventHandler wifiConnectHandler;
|
||||
WiFiEventHandler wifiDisconnectHandler;
|
||||
Ticker wifiReconnectTimer;
|
||||
const char* mqtt_server = "192.168.1.250";
|
||||
//const char* mqtt_server = "192.168.1.250";
|
||||
const char* mqtt_server = "192.168.1.111";
|
||||
char v[12];
|
||||
|
||||
struct contacts
|
||||
|
||||
@@ -185,7 +185,7 @@ void loop()
|
||||
if (!vvannaSent1){
|
||||
vvannaSent1 = true;
|
||||
vvannaSent0 = false;
|
||||
mqttClient.publish("/home/vt/vvanna", 1, false, "1");
|
||||
mqttClient.publish(TOPIC"vt/vvanna", 1, false, "1");
|
||||
}
|
||||
}
|
||||
else if(hum <= wUstavki.hSP){
|
||||
@@ -193,7 +193,7 @@ void loop()
|
||||
if (!vvannaSent0){
|
||||
vvannaSent0 = true;
|
||||
vvannaSent1 = false;
|
||||
mqttClient.publish("/home/vt/vvanna", 1, false, "0");
|
||||
mqttClient.publish(TOPIC"vt/vvanna", 1, false, "0");
|
||||
}
|
||||
}
|
||||
} // loop ()
|
||||
@@ -229,7 +229,7 @@ void buttLongClick()
|
||||
lcd.setBacklight(255);
|
||||
if (page == 3){
|
||||
pcf.write(LED_RED, 1);
|
||||
mqttClient.publish("/home/vt/flood", 1, false, "0");
|
||||
mqttClient.publish(TOPIC"vt/flood", 1, false, "0");
|
||||
return;
|
||||
}
|
||||
if (modeEdit == 0){
|
||||
@@ -272,7 +272,7 @@ void chkCount()
|
||||
wCounter.QC += 0.01f;
|
||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||
sprintf(v, "%.2f", wCounter.QC);
|
||||
mqttClient.publish("/home/vt/qcold", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qcold", 1, false, v);
|
||||
Serial.printf("QCold=%f\n", wCounter.QC);
|
||||
//pcf.write(7, led);
|
||||
//led = !led;
|
||||
@@ -281,13 +281,13 @@ void chkCount()
|
||||
wCounter.QH += 0.01f;
|
||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||
sprintf(v, "%.2f", wCounter.QH);
|
||||
mqttClient.publish("/home/vt/qhot", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qhot", 1, false, v);
|
||||
Serial.printf("QHot=%f\n", wCounter.QH);
|
||||
//pcf.write(7, led);
|
||||
//led = !led;
|
||||
}
|
||||
if(c_flood.chngDown((b >> FLOOD) & 0x01)){
|
||||
mqttClient.publish("/home/vt/flood", 1, false, "1");
|
||||
mqttClient.publish(TOPIC"vt/flood", 1, false, "1");
|
||||
pcf.write(LED_RED, 0);
|
||||
//Send MQTT Flood
|
||||
Serial.printf("Flood\n");
|
||||
@@ -495,7 +495,7 @@ void chkLight()
|
||||
#endif
|
||||
lOn = true;
|
||||
digitalWrite(VENT_TUAL, LOW);
|
||||
mqttClient.publish("/home/vt/vtual", 1, false, "1");
|
||||
mqttClient.publish(TOPIC"vt/vtual", 1, false, "1");
|
||||
//sec = 0;
|
||||
}
|
||||
if(lOn) sec = 0;
|
||||
@@ -516,7 +516,7 @@ void chkLight()
|
||||
#endif
|
||||
lOn = false;
|
||||
digitalWrite(VENT_TUAL, HIGH);
|
||||
mqttClient.publish("/home/vt/vtual", 1, false, "0");
|
||||
mqttClient.publish(TOPIC"vt/vtual", 1, false, "0");
|
||||
sec = 0;
|
||||
}
|
||||
}
|
||||
@@ -567,30 +567,30 @@ void onMqttConnect(bool sessionPresent) {
|
||||
// //Serial1.println(packetIdSub);
|
||||
//packetIdSub =
|
||||
sprintf(v, "%.2f", wCounter.QH);
|
||||
mqttClient.publish("/home/vt/qhot", 1, false, v);
|
||||
mqttClient.publish("/home/vt/qhot_set", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qhot", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qhot_set", 1, false, v);
|
||||
sprintf(v, "%.2f", wCounter.QC);
|
||||
mqttClient.publish("/home/vt/qcold", 1, false, v);
|
||||
mqttClient.publish("/home/vt/qcold_set", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qcold", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qcold_set", 1, false, v);
|
||||
itoa(wUstavki.hDB, v, 10);
|
||||
mqttClient.publish("/home/vt/hdb", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/hdb", 1, false, v);
|
||||
itoa(wUstavki.hSP, v, 10);
|
||||
mqttClient.publish("/home/vt/hsp", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/hsp", 1, false, v);
|
||||
itoa(ventUst.tWork, v, 10);
|
||||
mqttClient.publish("/home/vt/twork", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/twork", 1, false, v);
|
||||
itoa(ventUst.tPause, v, 10);
|
||||
mqttClient.publish("/home/vt/tpause", 1, false, v);
|
||||
mqttClient.subscribe("/home/vt/qhot_set", 1);
|
||||
mqttClient.subscribe("/home/vt/qcold_set", 1);
|
||||
mqttClient.subscribe("/home/vt/tpause_set", 1);
|
||||
mqttClient.subscribe("/home/vt/twork_set", 1);
|
||||
mqttClient.subscribe("/home/vt/hsp_set", 1);
|
||||
mqttClient.subscribe("/home/vt/hdb_set", 1);
|
||||
mqttClient.subscribe("/home/vt/flood", 1);
|
||||
mqttClient.publish(TOPIC"vt/tpause", 1, false, v);
|
||||
mqttClient.subscribe(TOPIC"vt/qhot_set", 1);
|
||||
mqttClient.subscribe(TOPIC"vt/qcold_set", 1);
|
||||
mqttClient.subscribe(TOPIC"vt/tpause_set", 1);
|
||||
mqttClient.subscribe(TOPIC"vt/twork_set", 1);
|
||||
mqttClient.subscribe(TOPIC"vt/hsp_set", 1);
|
||||
mqttClient.subscribe(TOPIC"vt/hdb_set", 1);
|
||||
mqttClient.subscribe(TOPIC"vt/flood", 1);
|
||||
////Serial1.print("Subscribing Lamp2, packetId: ");
|
||||
////Serial1.println(packetIdSub);
|
||||
////Serial1.println("Publishing at Lamp 1");
|
||||
//mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
|
||||
//mqttClient.publish(TOPIC"kor/lamp2", 1, false, lStat2 ? "1" : "0");
|
||||
////Serial1.println("Publishing at Lamp 2");
|
||||
|
||||
pcf.write(LED_BLUE, 0);
|
||||
@@ -621,43 +621,43 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
if(strcmp(topic, "/home/vt/qhot_set") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/qhot_set") == 0){
|
||||
wCounter.QH = atof(payload);
|
||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||
sprintf(v, "%.2f", wCounter.QH);
|
||||
mqttClient.publish("/home/vt/qhot", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qhot", 1, false, v);
|
||||
} else
|
||||
if(strcmp(topic, "/home/vt/qcold_set") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/qcold_set") == 0){
|
||||
wCounter.QC = atof(payload);
|
||||
ee.writeBlock(0, (uint8_t*)&wCounter, sizeof(wCounter));
|
||||
sprintf(v, "%.2f", wCounter.QC);
|
||||
mqttClient.publish("/home/vt/qcold", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/qcold", 1, false, v);
|
||||
} else
|
||||
if(strcmp(topic, "/home/vt/tpause_set") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/tpause_set") == 0){
|
||||
ventUst.tPause = atoi(payload);
|
||||
ee.writeBlock(16, (uint8_t*)&ventUst, sizeof(wCounter));
|
||||
itoa(ventUst.tPause, v, 10);
|
||||
mqttClient.publish("/home/vt/tpause", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/tpause", 1, false, v);
|
||||
} else
|
||||
if(strcmp(topic, "/home/vt/twork_set") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/twork_set") == 0){
|
||||
ventUst.tWork = atoi(payload);
|
||||
ee.writeBlock(16, (uint8_t*)&ventUst, sizeof(wCounter));
|
||||
itoa(ventUst.tWork, v, 10);
|
||||
mqttClient.publish("/home/vt/twork", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/twork", 1, false, v);
|
||||
} else
|
||||
if(strcmp(topic, "/home/vt/hsp_set") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/hsp_set") == 0){
|
||||
wUstavki.hSP = atoi(payload);
|
||||
ee.writeBlock(8, (uint8_t*)&wUstavki, sizeof(wCounter));
|
||||
itoa(wUstavki.hSP, v, 10);
|
||||
mqttClient.publish("/home/vt/hsp", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/hsp", 1, false, v);
|
||||
} else
|
||||
if(strcmp(topic, "/home/vt/hdb_set") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/hdb_set") == 0){
|
||||
wUstavki.hDB = atoi(payload);
|
||||
ee.writeBlock(8, (uint8_t*)&wUstavki, sizeof(wCounter));
|
||||
itoa(wUstavki.hDB, v, 10);
|
||||
mqttClient.publish("/home/vt/hdb", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/hdb", 1, false, v);
|
||||
} else
|
||||
if(strcmp(topic, "/home/vt/flood") == 0){
|
||||
if(strcmp(topic, TOPIC"vt/flood") == 0){
|
||||
pcf.write(LED_RED, !atoi(payload));
|
||||
c_flood = atoi(payload);
|
||||
}
|
||||
@@ -672,15 +672,15 @@ void onMqttPublish(uint16_t packetId) {
|
||||
|
||||
void sendData(){
|
||||
sprintf(v, "%.2f", temp);
|
||||
mqttClient.publish("/home/vt/vtemp", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/vtemp", 1, false, v);
|
||||
sprintf(v, "%.2f", hum);
|
||||
mqttClient.publish("/home/vt/vhum", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/vhum", 1, false, v);
|
||||
sprintf(v, "%.2f", cTemp);
|
||||
mqttClient.publish("/home/vt/tcold", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/tcold", 1, false, v);
|
||||
sprintf(v, "%.2f", hTemp);
|
||||
mqttClient.publish("/home/vt/thot", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/thot", 1, false, v);
|
||||
sprintf(v, "%.2f", mws);
|
||||
mqttClient.publish("/home/vt/wpress", 1, false, v);
|
||||
mqttClient.publish(TOPIC"vt/wpress", 1, false, v);
|
||||
Serial.print("millis: "); Serial.print(millis());
|
||||
Serial.println(" Sent data");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user