Change int to bool

This commit is contained in:
2020-11-28 11:12:16 +03:00
parent 364d581d2f
commit 2e9434202e
6 changed files with 35 additions and 33 deletions

View File

@@ -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; // Выходим из цикла

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}