From 2e9434202ebd0449a968b02460f3de06bfc1e4ef Mon Sep 17 00:00:00 2001 From: lexa Date: Sat, 28 Nov 2020 11:12:16 +0300 Subject: [PATCH] Change int to bool --- KorMYS/src/main.cpp | 10 +++++----- KuhLight_ESP/src/main.cpp | 6 +++--- Sw_BigRoom/src/main.cpp | 12 +++++++----- Sw_Koridor/src/main.cpp | 20 ++++++++++---------- Sw_MidlRoom/src/main.cpp | 10 +++++----- Sw_SmallRoom/src/main.cpp | 10 +++++----- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/KorMYS/src/main.cpp b/KorMYS/src/main.cpp index c4b5ce7..84e1e9e 100644 --- a/KorMYS/src/main.cpp +++ b/KorMYS/src/main.cpp @@ -226,10 +226,10 @@ void sendData(MyMessage msg, bool status) while(send_data == false){ count++; send_data = send(msg.set(status)); - wait(1000, C_SET, V_STATUS); - if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки + wait(1000, C_INTERNAL, V_STATUS); + if ((count == 3)&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки count = 0; // Обнуляем счётчик - send_data = 1; // Выходим из цикла + send_data = true; // Выходим из цикла } } } @@ -240,7 +240,7 @@ void sendData(MyMessage msg, float status) while(send_data == false){ count++; send_data = send(msg.set(status, 1)); - wait(1000, C_SET, V_STATUS); + wait(1000, C_INTERNAL, V_STATUS); if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки count = 0; // Обнуляем счётчик send_data = 1; // Выходим из цикла @@ -254,7 +254,7 @@ void sendData(MyMessage msg, int status) while(send_data == false){ count++; send_data = send(msg.set(status)); - wait(1000, C_SET, V_STATUS); + wait(1000, C_INTERNAL, V_STATUS); if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки count = 0; // Обнуляем счётчик send_data = 1; // Выходим из цикла diff --git a/KuhLight_ESP/src/main.cpp b/KuhLight_ESP/src/main.cpp index dbaff17..87ba59a 100644 --- a/KuhLight_ESP/src/main.cpp +++ b/KuhLight_ESP/src/main.cpp @@ -120,7 +120,7 @@ void loop() { bool switchLight(uint8_t nLamp, int state, bool pub) { digitalWrite(nLamp, state); - if (pub) mqttClient.publish("/home/kuh/lighttbl", 1, false, state ? "1" : "0"); + if (pub) mqttClient.publish("/home/kuh/lighttbl", 1, false, state ? "true" : "false"); return state; } @@ -145,7 +145,7 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { void onMqttConnect(bool sessionPresent) { mqttClient.subscribe("/home/kuh/lighttbl", 1); - mqttClient.publish("/home/kuh/lighttbl", 1, false, digitalRead(LAMP) == 1 ? "1" : "0"); + mqttClient.publish("/home/kuh/lighttbl", 1, false, digitalRead(LAMP) == 1 ? "true" : "false"); digitalWrite(LED_MQ, HIGH); } @@ -158,7 +158,7 @@ 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/kuh/lighttbl") == 0){ - if (atoi(payload) == 1) switchLight(LAMP, 1, false);//lStat2 = true; + if (strcmp("true", payload) == 0) switchLight(LAMP, 1, false);//lStat2 = true; else switchLight(LAMP, 0, false);//lStat2 = false; } } diff --git a/Sw_BigRoom/src/main.cpp b/Sw_BigRoom/src/main.cpp index 529fa7b..24c35bc 100644 --- a/Sw_BigRoom/src/main.cpp +++ b/Sw_BigRoom/src/main.cpp @@ -152,7 +152,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub) EEPROM.commit(); String topic = "/home/bigroom/lamp"; char n = nLamp == R_LED1 ? '1' : '2'; - if (pub) mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0"); + if (pub) mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "true" : "false"); return state; } @@ -176,8 +176,8 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { void onMqttConnect(bool sessionPresent) { mqttClient.subscribe("/home/bigroom/lamp1", 1); mqttClient.subscribe("/home/bigroom/lamp2", 1); - 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", 1, false, lStat1 ? "true" : "false"); + mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "true" : "false"); digitalWrite(B_LED, LOW); } @@ -191,14 +191,16 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) { void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { if(String(topic) == "/home/bigroom/lamp1"){ - if (atoi(payload) == 1) switchLight(R_LED1, 1, false); +// if (atoi(payload) == 1) switchLight(R_LED1, 1, false); + if (strcmp("true", payload) == 0) switchLight(R_LED1, 1, false); //lStat1 = true; else switchLight(R_LED1, 0, false); //lStat1 = false; //rcv = true; } if(String(topic) == "/home/bigroom/lamp2"){ - if (atoi(payload) == 1) switchLight(R_LED2, 1, false); + if (strcmp("true", payload) == 0) switchLight(R_LED2, 1, false); + //if (atoi(payload) == 1) switchLight(R_LED2, 1, false); //lStat1 = true; else switchLight(R_LED2, 0, false); } diff --git a/Sw_Koridor/src/main.cpp b/Sw_Koridor/src/main.cpp index 107bcf1..4a1bc75 100644 --- a/Sw_Koridor/src/main.cpp +++ b/Sw_Koridor/src/main.cpp @@ -57,13 +57,13 @@ void longPress() { //lStat1 = false; switchLight(R_LED, 0, true); - mqttClient.publish("/home/bigroom/lamp1", 0, false, "0"); - mqttClient.publish("/home/bigroom/lamp2", 0, false, "0"); - mqttClient.publish("/home/midroom/lamp1", 0, false, "0"); - mqttClient.publish("/home/midroom/lamp2", 0, false, "0"); - mqttClient.publish("/home/smallroom/lamp1", 0, false, "0"); - mqttClient.publish("/home/smallroom/lamp2", 0, false, "0"); - mqttClient.publish("/home/kuh/lighttbl", 0, false, "0"); + mqttClient.publish("/home/bigroom/lamp1", 0, false, "false"); + mqttClient.publish("/home/bigroom/lamp2", 0, false, "false"); + mqttClient.publish("/home/midroom/lamp1", 0, false, "false"); + mqttClient.publish("/home/midroom/lamp2", 0, false, "false"); + mqttClient.publish("/home/smallroom/lamp1", 0, false, "false"); + mqttClient.publish("/home/smallroom/lamp2", 0, false, "false"); + mqttClient.publish("/home/kuh/lighttbl", 0, false, "false"); } void setup() { @@ -158,7 +158,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub) digitalWrite(nLamp, state); EEPROM.put(0, state); EEPROM.commit(); - if (pub) mqttClient.publish("/home/kor/lamp1", 1, false, state ? "1" : "0"); + if (pub) mqttClient.publish("/home/kor/lamp1", 1, false, state ? "true" : "false"); return state; } @@ -187,7 +187,7 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { void onMqttConnect(bool sessionPresent) { mqttClient.subscribe("/home/kor/lamp1", 1); - mqttClient.publish("/home/kor/lamp1", 0, false, digitalRead(R_LED) == 1 ? "1" : "0"); + mqttClient.publish("/home/kor/lamp1", 0, false, digitalRead(R_LED) == 1 ? "true" : "false"); digitalWrite(B_LED, LOW); } @@ -216,7 +216,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") == 0){ - if (atoi(payload) == 1) switchLight(R_LED, 1, false);//lStat1 = true; + if (strcmp("true", payload) == 0) switchLight(R_LED, 1, false);//lStat1 = true; else switchLight(R_LED, 0, false);//lStat1 = false; //rcv = true; } diff --git a/Sw_MidlRoom/src/main.cpp b/Sw_MidlRoom/src/main.cpp index e47972a..472d643 100644 --- a/Sw_MidlRoom/src/main.cpp +++ b/Sw_MidlRoom/src/main.cpp @@ -117,7 +117,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub) EEPROM.commit(); String topic = "/home/midroom/lamp"; char n = nLamp == R_LED1 ? '1' : '2'; - if (pub) mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0"); + if (pub) mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "true" : "false"); return state; } @@ -141,8 +141,8 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { void onMqttConnect(bool sessionPresent) { mqttClient.subscribe("/home/midroom/lamp1", 1); mqttClient.subscribe("/home/midroom/lamp2", 1); - 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", 1, false, digitalRead(R_LED1) == 1 ? "true" : "false"); + mqttClient.publish("/home/midroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "true" : "false"); digitalWrite(B_LED, LOW); } @@ -155,11 +155,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") == 0){ - if (atoi(payload) == 1) switchLight(R_LED1, 1, false);//lStat1 = true; + if (strcmp("true", payload) == 0) switchLight(R_LED1, 1, false);//lStat1 = true; else switchLight(R_LED1, 0, false);//lStat1 = false; } if(strcmp(topic, "/home/midroom/lamp2") == 0){ - if (atoi(payload) == 1) switchLight(R_LED2, 1, false);//lStat2 = true; + if (strcmp("true", payload) == 0) switchLight(R_LED2, 1, false);//lStat2 = true; else switchLight(R_LED2, 0, false);//lStat2 = false; } } diff --git a/Sw_SmallRoom/src/main.cpp b/Sw_SmallRoom/src/main.cpp index c3fce9c..b2b4226 100644 --- a/Sw_SmallRoom/src/main.cpp +++ b/Sw_SmallRoom/src/main.cpp @@ -125,7 +125,7 @@ bool switchLight(uint8_t nLamp, int state, bool pub) EEPROM.commit(); String topic = "/home/smallroom/lamp"; char n = nLamp == R_LED1 ? '1' : '2'; - if (pub) mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "1" : "0"); + if (pub) mqttClient.publish(String(topic + n).c_str(), 1, false, state ? "true" : "false"); return state; } @@ -155,8 +155,8 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { void onMqttConnect(bool sessionPresent) { mqttClient.subscribe("/home/smallroom/lamp1", 1); mqttClient.subscribe("/home/smallroom/lamp2", 1); - 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", 1, false, digitalRead(R_LED1) == 1 ? "true" : "false"); + mqttClient.publish("/home/smallroom/lamp2", 1, false, digitalRead(R_LED2) == 1 ? "true" : "false"); digitalWrite(B_LED, LOW); } @@ -169,11 +169,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") == 0){ - if (atoi(payload) == 1) switchLight(R_LED1, 1, false);//lStat1 = true; + if (strcmp("true", payload) == 0) switchLight(R_LED1, 1, false);//lStat1 = true; else switchLight(R_LED1, 0, false);//lStat1 = false; } if(strcmp(topic, "/home/smallroom/lamp2") == 0){ - if (atoi(payload) == 1) switchLight(R_LED2, 1, false);//lStat2 = true; + if (strcmp("true", payload) == 0) switchLight(R_LED2, 1, false);//lStat2 = true; else switchLight(R_LED2, 0, false);//lStat2 = false; } }