New iobroker
This commit is contained in:
@@ -7,7 +7,9 @@
|
||||
|
||||
const char* ssid = "wf-home";
|
||||
const char* password = "0ndthnrf";
|
||||
const char* mqtt_server = "192.168.1.250";
|
||||
//const char* mqtt_server = "192.168.1.250";
|
||||
const char* mqtt_server = "192.168.1.111";
|
||||
#define TOPIC "home/"
|
||||
|
||||
AsyncMqttClient mqttClient;
|
||||
Ticker mqttReconnectTimer;
|
||||
@@ -115,7 +117,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
|
||||
digitalWrite(nLamp, state);
|
||||
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
||||
EEPROM.commit();
|
||||
String topic = "/home/midroom/lamp";
|
||||
String topic = TOPIC"midroom/lamp";
|
||||
char n = nLamp == R_LED1 ? '1' : '2';
|
||||
//if (pub)
|
||||
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
|
||||
@@ -140,12 +142,12 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
}
|
||||
|
||||
void onMqttConnect(bool sessionPresent) {
|
||||
mqttClient.publish("/home/midroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||
mqttClient.publish("/home/midroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||
mqttClient.publish("/home/midroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||
mqttClient.publish("/home/midroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||
mqttClient.subscribe("/home/midroom/lamp1_set", 1);
|
||||
mqttClient.subscribe("/home/midroom/lamp2_set", 1);
|
||||
mqttClient.publish(TOPIC"midroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||
mqttClient.publish(TOPIC"midroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||
mqttClient.publish(TOPIC"midroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
|
||||
mqttClient.publish(TOPIC"midroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
|
||||
mqttClient.subscribe(TOPIC"midroom/lamp1_set", 1);
|
||||
mqttClient.subscribe(TOPIC"midroom/lamp2_set", 1);
|
||||
digitalWrite(B_LED, LOW);
|
||||
}
|
||||
|
||||
@@ -157,11 +159,11 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
||||
}
|
||||
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
if(strcmp(topic, "/home/midroom/lamp1_set") == 0){
|
||||
if(strcmp(topic, TOPIC"midroom/lamp1_set") == 0){
|
||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED1, 1, false);//lStat1 = true;
|
||||
else switchLight(R_LED1, 0, false);//lStat1 = false;
|
||||
}
|
||||
if(strcmp(topic, "/home/midroom/lamp2_set") == 0){
|
||||
if(strcmp(topic, TOPIC"midroom/lamp2_set") == 0){
|
||||
if (strncmp("1", payload, 1) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
|
||||
else switchLight(R_LED2, 0, false);//lStat2 = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user