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

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