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