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

@@ -11,10 +11,11 @@
//RemoteDebug Debug;
//#endif
#define MAINTOPIC "home"
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";
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
@@ -134,7 +135,7 @@ void loop() {
cRun = millis();
char v[11];
ultoa(cRun, v, 10);
mqttClient.publish("/home/bigroom/millislamp", 0, false, v);
mqttClient.publish(MAINTOPIC"/bigroom/millislamp", 0, false, v);
//debugI("*Publish Millis: %u");
}
// Debug.handle();
@@ -146,7 +147,7 @@ bool switchLight(uint8_t nLamp, bool state, bool pub)
digitalWrite(nLamp, state);
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
EEPROM.commit();
String topic = "/home/bigroom/lamp";
String topic = MAINTOPIC"/bigroom/lamp";
char n = nLamp == R_LED1 ? '1' : '2';
//if (pub){
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
@@ -173,12 +174,12 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
}
void onMqttConnect(bool sessionPresent) {
mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp1_set", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp2_set", 1, false, lStat2 ? "1" : "0");
mqttClient.subscribe("/home/bigroom/lamp1_set", 1);
mqttClient.subscribe("/home/bigroom/lamp2_set", 1);
mqttClient.publish(MAINTOPIC"/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
mqttClient.publish(MAINTOPIC"/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
mqttClient.publish(MAINTOPIC"/bigroom/lamp1_set", 1, false, lStat1 ? "1" : "0");
mqttClient.publish(MAINTOPIC"/bigroom/lamp2_set", 1, false, lStat2 ? "1" : "0");
mqttClient.subscribe(MAINTOPIC"/bigroom/lamp1_set", 1);
mqttClient.subscribe(MAINTOPIC"/bigroom/lamp2_set", 1);
digitalWrite(B_LED, LOW);
}
@@ -192,7 +193,7 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
char s[10];
strncpy(s, payload, len);
if(String(topic) == "/home/bigroom/lamp1_set"){
if(String(topic) == MAINTOPIC"/bigroom/lamp1_set"){
// if (atoi(payload) == 1) switchLight(R_LED1, 1, false);
if (strncmp("1", payload, 1) == 0){
switchLight(R_LED1, true, false);
@@ -205,7 +206,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
// debugI("*Switch from MQTT F1: %s", s);
}
}
if(String(topic) == "/home/bigroom/lamp2_set"){
if(String(topic) == MAINTOPIC"/bigroom/lamp2_set"){
if (strncmp("1", payload, 1) == 0){
switchLight(R_LED2, true, false);
// debugI("*Switch from MQTT T2: %s", s);