New iobroker

This commit is contained in:
2021-12-31 12:37:48 +03:00
parent 149cb3b5b6
commit 585365267f
17 changed files with 170 additions and 158 deletions

View File

@@ -5,7 +5,8 @@
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
const char* mqtt_server = "192.168.1.111";
#define TOPIC "home/"
#define LED_WF (12)
#define LED_MQ (13)
@@ -115,7 +116,7 @@ void loop() {
ultoa(millis(), v, 10);
digitalWrite(LED_WRK, LOW);
led_ms = millis();
mqttClient.publish("/home/kuh/ltblmillis", 0, false, v);
mqttClient.publish(TOPIC"kuh/ltblmillis", 0, false, v);
}
nSec = 0;
}
@@ -129,7 +130,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
if (pub){
digitalWrite(LED_WRK, LOW);
led_ms = millis();
mqttClient.publish("/home/kuh/lighttbl", 1, false, state ? "1" : "0");
mqttClient.publish(TOPIC"kuh/lighttbl", 1, false, state ? "1" : "0");
}
return state;
}
@@ -154,9 +155,9 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
}
void onMqttConnect(bool sessionPresent) {
mqttClient.publish("/home/kuh/lighttbl_set", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
mqttClient.subscribe("/home/kuh/lighttbl_set", 1);
mqttClient.publish("/home/kuh/lighttbl", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
mqttClient.publish(TOPIC"kuh/lighttbl_set", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
mqttClient.subscribe(TOPIC"kuh/lighttbl_set", 1);
mqttClient.publish(TOPIC"kuh/lighttbl", 1, false, digitalRead(LAMP) == 1 ? "1" : "0");
digitalWrite(LED_MQ, HIGH);
}
@@ -171,7 +172,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
char pl[6];
strncpy(pl, payload, len);
pl[len] = '\0';
if(strcmp(topic, "/home/kuh/lighttbl_set") == 0){
if(strcmp(topic, TOPIC"kuh/lighttbl_set") == 0){
if (strncmp("1", pl, 1) == 0) switchLight(LAMP, 1, true);//lStat2 = true;
else switchLight(LAMP, 0, true);//lStat2 = false;
}