Change int to bool
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user