diff --git a/ESP12SmallRoom/src/main.cpp b/ESP12SmallRoom/src/main.cpp index 42987ea..21ed795 100644 --- a/ESP12SmallRoom/src/main.cpp +++ b/ESP12SmallRoom/src/main.cpp @@ -100,7 +100,7 @@ void loop() { rel_hum += (htu.readHumidity() - rel_hum) / 6.0f; digitalWrite(PWR_SENS, LOW); } - if(++measCnt == 9){ + if(++measCnt == 29){ digitalWrite(PWR_SENS, HIGH); measCnt = 0; } @@ -146,8 +146,8 @@ void publishMin() dtostrf(rel_hum, 6, 1, strFVal); client.publish("/home/smallroom/rel_hum", strFVal); } - itoa(cRun, strFVal, 10); - client.publish("/home/smallroom/millis", strFVal); + // itoa(cRun, strFVal, 10); + // client.publish("/home/smallroom/millis", strFVal); //digitalWrite(LED_BLUE, LOW); } } diff --git a/ESP_MidRoom/src/main.cpp b/ESP_MidRoom/src/main.cpp index 663bbc9..906d61e 100644 --- a/ESP_MidRoom/src/main.cpp +++ b/ESP_MidRoom/src/main.cpp @@ -103,32 +103,8 @@ void setup() { } Serial1.println(); mhz19.begin(Serial); - //char myVersion[4]; - //mhz19.getVersion(myVersion); - - // //Serial1.print("\nFirmware Version: "); - // for(byte i = 0; i < 4; i++) - // { - // //Serial1.print(myVersion[i]); - // if(i == 1) - // //Serial1.print("."); - // } - // //Serial1.println(""); - - // //Serial1.print("Range: "); - // //Serial1.println(mhz19.getRange()); - // //Serial1.print("Background CO2: "); - // //Serial1.println(mhz19.getBackgroundCO2()); - // //Serial1.print("Temperature Cal: "); - // //Serial1.println(mhz19.getTempAdjustment()); - // //Serial1.print("ABC Status: "); mhz19.getABC() ? //Serial1.println("ON") : //Serial1.println("OFF"); - //Serial1.println(F("End Begin MH-Z19")); - Wire.begin(); - //Serial1.println(F("Begin BME")); bool status = bme.begin(BME280_ADDRESS_ALTERNATE); - - if (!status) { //Serial1.println(F("Could not find a valid BME280 sensor, check wiring, address, sensor ID!")); } @@ -162,56 +138,34 @@ void loop() { if (digitalRead(MOV_SENS) != old_mov){ old_mov = digitalRead(MOV_SENS); //Serial1.println(F("Change mov detected")); - mqttClient.publish("/home/midroom/move", 1, false, old_mov ? "1" : "0"); + mqttClient.publish("/home/midroom/move", 0, false, old_mov ? "1" : "0"); } if(cRun + 999 < millis()){ cRun = millis(); - //if(mqttClient.connected()) digitalWrite(R_LED, LOW); else digitalWrite(R_LED, HIGH); adc = analogRead(A0); - // Serial1.print(F("ADC: "));Serial1.println(adc); - // Serial1.print(F("MQTT: "));Serial1.println(mqttClient.connected()); if(abs(adc - lastADC) > 50){ lastADC = adc; itoa(adc, v, 10); - mqttClient.publish("/home/midroom/light", 1, false, v); + mqttClient.publish("/home/midroom/light", 0, false, v); } - if(meas){ - //Serial1.println(adc); - // Serial1.println("Measure"); - + if(minCnt % 20 == 0){ + co2 = mhz19.getCO2(); +/* Serial1.print("CO2: "); + Serial1.println(co2); */ + digitalWrite(P_SENS, HIGH); + bme.begin(BME280_ADDRESS_ALTERNATE); + delay(10); pt = bme.readPressure(); tt = bme.readTemperature(); ht = bme.readHumidity(); -/* Serial1.print(F("T: ")); - Serial1.print(tt); - Serial1.print(F("\tH: ")); - Serial1.print(ht); - Serial1.print(F("\tP: ")); - Serial1.println(pt); */ if(!isnan(pt)) - p += (pt - p) / 60.0f ; -/* else - { - Serial1.println(F("Error BME")); - } */ - + p = pt;//+= (pt - p) / 60.0f ; if(!isnan(tt)) - t += (tt - t) / 30.0f ; + t = tt;//+= (tt - t) / 30.0f ; if(!isnan(ht)) - h += (ht - h) / 30.0f ; + h = ht;//+= (ht - h) / 30.0f ; digitalWrite(P_SENS, LOW); - meas = false; - } - else{ - if(minCnt % 5 == 0){ - co2 = mhz19.getCO2(); -/* Serial1.print("CO2: "); - Serial1.println(co2); */ - digitalWrite(P_SENS, HIGH); - bme.begin(BME280_ADDRESS_ALTERNATE); - meas = true; - } } if(++minCnt == 60){ minCnt = 0; @@ -240,11 +194,11 @@ void loop() { itoa(millis(), v, 10); if(mqttClient.connected()){ mqttClient.publish("/home/midroom/millis", 0, false, v); - dtostrf(t, 5, 1,v); - mqttClient.publish("/home/midroom/temp", 0, false, v); - //Serial1.println("Publish1"); - dtostrf(h, 5, 1,v); - mqttClient.publish("/home/midroom/humid", 0, false, v); + // dtostrf(t, 5, 1,v); + // mqttClient.publish("/home/midroom/temp", 0, false, v); + // //Serial1.println("Publish1"); + // dtostrf(h, 5, 1,v); + // mqttClient.publish("/home/midroom/humid", 0, false, v); g_led.start(); } } diff --git a/KuhLight_ESP/src/main.cpp b/KuhLight_ESP/src/main.cpp index 8da1b4d..3ffc528 100644 --- a/KuhLight_ESP/src/main.cpp +++ b/KuhLight_ESP/src/main.cpp @@ -56,8 +56,8 @@ void onMqttConnect(bool sessionPresent) { Serial.println("Connected to MQTT."); Serial.print("Session present: "); Serial.println(sessionPresent); - mqttClient.subscribe("/home/kuh/lighttbl_set", 1); - mqttClient.publish("/home/kuh/lighttbl", 1, false, light ? "1" : "0"); + mqttClient.subscribe("/home/kuh/lighttbl_set", 0); + mqttClient.publish("/home/kuh/lighttbl", 0, false, light ? "1" : "0"); digitalWrite(LED_MQ, HIGH); } @@ -88,7 +88,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties if(strcmp(topic, "/home/kuh/lighttbl_set") == 0){ light = atoi(payload); digitalWrite(LAMP, light); - mqttClient.publish("/home/kuh/lighttbl", 1, false, light ? "1" : "0"); + mqttClient.publish("/home/kuh/lighttbl", 0, false, light ? "1" : "0"); } } @@ -167,7 +167,7 @@ void loop() { lastSense = millis(); light = !light; digitalWrite(LAMP, light); - mqttClient.publish("/home/kuh/lighttbl", 1, false, light ? "1" : "0"); + mqttClient.publish("/home/kuh/lighttbl", 0, false, light ? "1" : "0"); Serial.println("Change state"); Serial.println(light); } @@ -181,7 +181,7 @@ void loop() { if(mqttClient.connected()){ char v[11]; itoa(millis(), v, 10); - mqttClient.publish("/home/kuh/ltblmillis", 1, false, v); + mqttClient.publish("/home/kuh/ltblmillis", 0, false, v); Serial.print("Millis: "); Serial.println(millis()); } diff --git a/Sw_BigRoom/src/main.cpp b/Sw_BigRoom/src/main.cpp index cdf60eb..92b8630 100644 --- a/Sw_BigRoom/src/main.cpp +++ b/Sw_BigRoom/src/main.cpp @@ -268,10 +268,10 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { } void onMqttConnect(bool sessionPresent) { - mqttClient.subscribe("/home/bigroom/lamp1_set", 1); - mqttClient.subscribe("/home/bigroom/lamp2_set", 1); - mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0"); - mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0"); + mqttClient.subscribe("/home/bigroom/lamp1_set", 0); + mqttClient.subscribe("/home/bigroom/lamp2_set", 0); + mqttClient.publish("/home/bigroom/lamp1", 0, false, lStat1 ? "1" : "0"); + mqttClient.publish("/home/bigroom/lamp2", 0, false, lStat2 ? "1" : "0"); digitalWrite(B_LED, LOW); } @@ -290,11 +290,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/bigroom/lamp1_set") == 0){ - if ((char)payload[0] == '1') lStat1 = true; + if (atoi(payload) == 1) lStat1 = true; else lStat1 = false; } if(strcmp(topic, "/home/bigroom/lamp2_set") == 0){ - if ((char)payload[0] == '1') lStat2 = true; + if (atoi(payload) == 1) lStat2 = true; else lStat2 = false; } } @@ -379,14 +379,14 @@ void loop() { if(lStat1 != oldLStat1){ digitalWrite(R_LED1, lStat1); oldLStat1 = lStat1; - mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0"); + mqttClient.publish("/home/bigroom/lamp1", 0, false, lStat1 ? "1" : "0"); EEPROM.put(0, lStat1); EEPROM.commit(); } if(lStat2 != oldLStat2){ digitalWrite(R_LED2, lStat2); oldLStat2 = lStat2; - mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0"); + mqttClient.publish("/home/bigroom/lamp2", 0, false, lStat2 ? "1" : "0"); EEPROM.put(1, lStat2); EEPROM.commit(); } diff --git a/Sw_Koridor/src/main.cpp b/Sw_Koridor/src/main.cpp index 9946888..49669ae 100644 --- a/Sw_Koridor/src/main.cpp +++ b/Sw_Koridor/src/main.cpp @@ -60,13 +60,13 @@ void onMqttConnect(bool sessionPresent) { // Serial.print("Session present: "); // Serial.println(sessionPresent); //uint16_t packetIdSub = - mqttClient.subscribe("/home/kor/lamp1_set", 1); + mqttClient.subscribe("/home/kor/lamp1_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/kor/lamp1", 1, false, lStat1 ? "1" : "0"); + mqttClient.publish("/home/kor/lamp1", 0, false, lStat1 ? "1" : "0"); //Serial.println("Publishing at Lamp 1"); //mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0"); //Serial.println("Publishing at Lamp 2"); @@ -98,7 +98,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_set") == 0){ - if ((char)payload[0] == '1') lStat1 = true; + if (atoi(payload) == 1) lStat1 = true; else lStat1 = false; } } @@ -122,12 +122,12 @@ void oneClick() void longPress() { lStat1 = false; - mqttClient.publish("/home/bigroom/lamp1_set", 1, false, "0"); - mqttClient.publish("/home/bigroom/lamp2_set", 1, false, "0"); - mqttClient.publish("/home/midroom/lamp1_set", 1, false, "0"); - mqttClient.publish("/home/midroom/lamp2_set", 1, false, "0"); - mqttClient.publish("/home/smallroom/lamp1_set", 1, false, "0"); - mqttClient.publish("/home/smallroom/lamp2_set", 1, false, "0"); + mqttClient.publish("/home/bigroom/lamp1_set", 0, false, "0"); + mqttClient.publish("/home/bigroom/lamp2_set", 0, false, "0"); + mqttClient.publish("/home/midroom/lamp1_set", 0, false, "0"); + mqttClient.publish("/home/midroom/lamp2_set", 0, false, "0"); + mqttClient.publish("/home/smallroom/lamp1_set", 0, false, "0"); + mqttClient.publish("/home/smallroom/lamp2_set", 0, false, "0"); } void setup() { @@ -200,7 +200,7 @@ void loop() { if(lStat1 != oldLStat1){ digitalWrite(R_LED, lStat1); oldLStat1 = lStat1; - mqttClient.publish("/home/kor/lamp1", 1, false, lStat1 ? "1" : "0"); + mqttClient.publish("/home/kor/lamp1", 0, false, lStat1 ? "1" : "0"); EEPROM.put(0, lStat1); EEPROM.commit(); } diff --git a/Sw_MidlRoom/src/main.cpp b/Sw_MidlRoom/src/main.cpp index 9b4f697..f415f5b 100644 --- a/Sw_MidlRoom/src/main.cpp +++ b/Sw_MidlRoom/src/main.cpp @@ -47,10 +47,10 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { } void onMqttConnect(bool sessionPresent) { - mqttClient.subscribe("/home/midroom/lamp1_set", 1); - mqttClient.subscribe("/home/midroom/lamp2_set", 1); - mqttClient.publish("/home/midroom/lamp1", 1, false, lStat1 ? "1" : "0"); - mqttClient.publish("/home/midroom/lamp2", 1, false, lStat2 ? "1" : "0"); + mqttClient.subscribe("/home/midroom/lamp1_set", 0); + mqttClient.subscribe("/home/midroom/lamp2_set", 0); + mqttClient.publish("/home/midroom/lamp1", 0, false, lStat1 ? "1" : "0"); + mqttClient.publish("/home/midroom/lamp2", 0, false, lStat2 ? "1" : "0"); digitalWrite(B_LED, LOW); } @@ -69,11 +69,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/midroom/lamp1_set") == 0){ - if ((char)payload[0] == '1') lStat1 = true; + if (atoi(payload) == 1) lStat1 = true; else lStat1 = false; } if(strcmp(topic, "/home/midroom/lamp2_set") == 0){ - if ((char)payload[0] == '1') lStat2 = true; + if (atoi(payload) == 1) lStat2 = true; else lStat2 = false; } } @@ -158,14 +158,14 @@ void loop() { if(lStat1 != oldLStat1){ digitalWrite(R_LED1, lStat1); oldLStat1 = lStat1; - mqttClient.publish("/home/midroom/lamp1", 1, false, lStat1 ? "1" : "0"); + mqttClient.publish("/home/midroom/lamp1", 0, false, lStat1 ? "1" : "0"); EEPROM.put(0, lStat1); EEPROM.commit(); } if(lStat2 != oldLStat2){ digitalWrite(R_LED2, lStat2); oldLStat2 = lStat2; - mqttClient.publish("/home/midroom/lamp2", 1, false, lStat2 ? "1" : "0"); + mqttClient.publish("/home/midroom/lamp2", 0, false, lStat2 ? "1" : "0"); EEPROM.put(1, lStat2); EEPROM.commit(); } diff --git a/Sw_SmallRoom/src/main.cpp b/Sw_SmallRoom/src/main.cpp index ed5c953..6a3aa37 100644 --- a/Sw_SmallRoom/src/main.cpp +++ b/Sw_SmallRoom/src/main.cpp @@ -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();