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

@@ -14,7 +14,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/"
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
@@ -60,13 +61,13 @@ void oneClick()
// {
// //lStat1 = false;
// switchLight(R_LED, 0, true);
// mqttClient.publish("/home/bigroom/lamp1_set", 0, false, "false");
// mqttClient.publish("/home/bigroom/lamp2_set", 0, false, "false");
// mqttClient.publish("/home/midroom/lamp1_set", 0, false, "false");
// mqttClient.publish("/home/midroom/lamp2_set", 0, false, "false");
// mqttClient.publish("/home/smallroom/lamp1_set", 0, false, "false");
// mqttClient.publish("/home/smallroom/lamp2_set", 0, false, "false");
// mqttClient.publish("/home/kuh/lighttbl", 0, false, "false");
// mqttClient.publish(TOPIC"bigroom/lamp1_set", 0, false, "false");
// mqttClient.publish(TOPIC"bigroom/lamp2_set", 0, false, "false");
// mqttClient.publish(TOPIC"midroom/lamp1_set", 0, false, "false");
// mqttClient.publish(TOPIC"midroom/lamp2_set", 0, false, "false");
// mqttClient.publish(TOPIC"smallroom/lamp1_set", 0, false, "false");
// mqttClient.publish(TOPIC"smallroom/lamp2_set", 0, false, "false");
// mqttClient.publish(TOPIC"kuh/lighttbl", 0, false, "false");
// }
void setup() {
@@ -152,7 +153,7 @@ void loop() {
// digitalWrite(R_LED, lStat1);
// oldLStat1 = lStat1;
// if(!rcv)
// mqttClient.publish("/home/kor/lamp1", 0, false, lStat1 ? "1" : "0");
// mqttClient.publish(TOPIC"kor/lamp1", 0, false, lStat1 ? "1" : "0");
// else
// rcv = false;
// EEPROM.put(0, lStat1);
@@ -162,7 +163,7 @@ void loop() {
cRun = millis();
char v[11];
ultoa(cRun, v, 10);
mqttClient.publish("/home/kor/millislamp", 0, false, v);
mqttClient.publish(TOPIC"kor/millislamp", 0, false, v);
}
}
@@ -172,7 +173,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
EEPROM.put(0, state);
EEPROM.commit();
//if (pub)
mqttClient.publish("/home/kor/lamp1", 1, false, state ? "1" : "0");
mqttClient.publish(TOPIC"kor/lamp1", 1, false, state ? "1" : "0");
return state;
}
@@ -200,9 +201,9 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
}
void onMqttConnect(bool sessionPresent) {
mqttClient.publish("/home/kor/lamp1", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
mqttClient.publish("/home/kor/lamp1_set", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
mqttClient.subscribe("/home/kor/lamp1_set", 1);
mqttClient.publish(TOPIC"kor/lamp1", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
mqttClient.publish(TOPIC"kor/lamp1_set", 0, false, digitalRead(R_LED) == 1 ? "1" : "0");
mqttClient.subscribe(TOPIC"kor/lamp1_set", 1);
digitalWrite(B_LED, LOW);
}
@@ -230,7 +231,7 @@ 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/kor/lamp1_set") == 0){
if(strcmp(topic, TOPIC"kor/lamp1_set") == 0){
if (strncmp("1", payload, 1) == 0) switchLight(R_LED, 1, false);//lStat1 = true;
else switchLight(R_LED, 0, false);//lStat1 = false;
//rcv = true;