just comment

This commit is contained in:
2021-12-12 19:11:03 +03:00
parent 620e954716
commit 149cb3b5b6
16 changed files with 432 additions and 64 deletions

View File

@@ -126,7 +126,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub)
String topic = "/home/smallroom/lamp";
char n = nLamp == R_LED1 ? '1' : '2';
//if (pub)
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "true" : "false");
mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0");
return state;
}
@@ -154,10 +154,10 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
}
void onMqttConnect(bool sessionPresent) {
mqttClient.publish("/home/smallroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "true" : "false");
mqttClient.publish("/home/smallroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "true" : "false");
mqttClient.publish("/home/smallroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "true" : "false");
mqttClient.publish("/home/smallroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "true" : "false");
mqttClient.publish("/home/smallroom/lamp1", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp1_set", 1, false, digitalRead(R_LED1) == 1 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp2_set", 1, false, digitalRead(R_LED2) == 1 ? "1" : "0");
mqttClient.subscribe("/home/smallroom/lamp1_set", 1);
mqttClient.subscribe("/home/smallroom/lamp2_set", 1);
digitalWrite(B_LED, LOW);
@@ -172,11 +172,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/smallroom/lamp1_set") == 0){
if (strncmp("true", payload, 4) == 0) switchLight(R_LED1, 1, false);//lStat1 = true;
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/smallroom/lamp2_set") == 0){
if (strncmp("true", payload, 4) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
if (strncmp("1", payload, 1) == 0) switchLight(R_LED2, 1, false);//lStat2 = true;
else switchLight(R_LED2, 0, false);//lStat2 = false;
}
}