Change QOS and Time polling sensors

This commit is contained in:
2020-08-07 14:57:44 +03:00
parent 7dcd044fb5
commit 2785c78704
7 changed files with 59 additions and 105 deletions

View File

@@ -63,15 +63,15 @@ void onMqttConnect(bool sessionPresent) {
// Serial.print("Session present: ");
// Serial.println(sessionPresent);
//uint16_t packetIdSub =
mqttClient.subscribe("/home/smallroom/lamp1_set", 1);
mqttClient.subscribe("/home/smallroom/lamp2_set", 1);
mqttClient.subscribe("/home/smallroom/lamp1_set", 0);
mqttClient.subscribe("/home/smallroom/lamp2_set", 0);
// Serial.print("Subscribing Lamp1, packetId: ");
// Serial.println(packetIdSub);
//packetIdSub = mqttClient.subscribe("/home/kor/lamp2_set", 1);
//Serial.print("Subscribing Lamp2, packetId: ");
//Serial.println(packetIdSub);
mqttClient.publish("/home/smallroom/lamp1", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp2", 1, false, lStat2 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp1", 0, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp2", 0, false, lStat2 ? "1" : "0");
//Serial.println("Publishing at Lamp 1");
//mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
//Serial.println("Publishing at Lamp 2");
@@ -103,11 +103,11 @@ 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/smallroom/lamp1_set") == 0){
if ((char)payload[0] == '1') lStat1 = true;
if (atoi(payload) == 1) lStat1 = true;
else lStat1 = false;
}
if(strcmp(topic, "/home/smallroom/lamp2_set") == 0){
if ((char)payload[0] == '1') lStat2 = true;
if (atoi(payload) == 1) lStat2 = true;
else lStat2 = false;
}
}
@@ -202,7 +202,7 @@ void loop() {
if(lStat1 != oldLStat1){
digitalWrite(R_LED1, lStat1);
oldLStat1 = lStat1;
mqttClient.publish("/home/smallroom/lamp1", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp1", 0, false, lStat1 ? "1" : "0");
// Serial.println("Publishing at Lamp 1");
EEPROM.put(0, lStat1);
EEPROM.commit();
@@ -212,7 +212,7 @@ void loop() {
if(lStat2 != oldLStat2){
digitalWrite(R_LED2, lStat2);
oldLStat2 = lStat2;
mqttClient.publish("/home/smallroom/lamp2", 1, false, lStat2 ? "1" : "0");
mqttClient.publish("/home/smallroom/lamp2", 0, false, lStat2 ? "1" : "0");
// Serial.println("Publishing at Lamp 1");
EEPROM.put(1, lStat2);
EEPROM.commit();