fixes interval and stuff

This commit is contained in:
Sietse Jonker
2024-02-28 12:06:43 +01:00
parent 503ef68e67
commit 734dca30bc

View File

@@ -128,26 +128,26 @@ bool checkForError(){
if (!sgp.IAQmeasure()) {
Serial.println("SGP30: BAD");
errorSGP30 = true;
return true;
} else {
Serial.println("SGP30: OK");
errorSGP30 = false;
return false;
}
if (isnan(temperature) || isnan(humidity)){
Serial.println("DHT11: BAD");
errorDHT11 = true;
return true;
} else {
Serial.println("DHT11: OK");
errorDHT11 = false;
return false;
}
return false;
}
// function to update when interval is met (see intervalCounter variable)
void update(){
// display sensordata on oled screen
displayData();
webSocket.sendTXT("Temp: " + String(temperature));
webSocket.sendTXT("Humi: " + String(humidity));
webSocket.sendTXT("eCO2: " + String(sgp.eCO2));
@@ -158,6 +158,8 @@ void update(){
// read dht11 sensor
temperature = float(dht.readTemperature());
humidity = float(dht.readHumidity());
checkForError();
}
// function to display data on oled screen
@@ -200,15 +202,9 @@ void setup() {
// loop function
void loop() {
// check for errors
checkForError();
// loop the websocket connection so it stays alive
webSocket.loop();
// display sensordata on oled screen
displayData();
// update when interval is met
if (currentMillis - lastMillis >= interval){
lastMillis = millis();