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