diff --git a/arduino/node-code/node-code-final.ino b/arduino/node-code/node-code-final.ino index c8b3119..bfb827c 100644 --- a/arduino/node-code/node-code-final.ino +++ b/arduino/node-code/node-code-final.ino @@ -32,6 +32,10 @@ float humidity = 0; uint16_t eCO2 = 0; uint16_t TVOC = 0; bool noise = false; +bool update = false; +double counterBaseline = 15000; +int counterInterval = 5000; + #define USE_SERIAL Serial void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) { @@ -82,7 +86,7 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { } void websocketSetup(){ - for(uint8_t t = 4; t > 0; t--) { + for(uint8_t t = 1; t > 0; t--) { USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t); USE_SERIAL.flush(); delay(1000); @@ -174,18 +178,19 @@ void setup() { void loop() { webSocket.loop(); + if (update){ webSocket.sendTXT("Temp: " + String(temperature)); webSocket.sendTXT("Humi: " + String(humidity)); webSocket.sendTXT("eCO2: " + String(sgp.eCO2)); webSocket.sendTXT("TVOC: " + String(sgp.TVOC)); - + } // if sensor doesnt work print in serialmonitor if (!sgp.IAQmeasure()) { - Serial.println("SGP30: BAD"); + // Serial.println("SGP30: BAD"); return; } else { - Serial.println("SGP30: OK"); + // Serial.println("SGP30: OK"); } // read dht11 sensor @@ -196,8 +201,21 @@ void loop() { displayData(); // get new baseline every 30 seconds - if (counter == 30) { + if (update) { sgp.getIAQBaseline(&eCO2_base, &TVOC_base); } - counter++; + + counter = millis(); + Serial.println("baseline" + String(counterBaseline)); + Serial.println("counter" + String(counter)); + + if (counter >= counterBaseline){ + counterBaseline = counterBaseline + counterInterval; + + update = true; + Serial.println("update"); + } else { + update = false; + Serial.println("no update"); + } } \ No newline at end of file