Almost done with the OOP

This commit is contained in:
Dano van den Bosch
2024-03-19 16:15:02 +01:00
parent a8f6491736
commit a4b8ae0dca
8 changed files with 114 additions and 27 deletions

View File

@@ -1,5 +1,8 @@
#include "arduino.h"
#include "nodeCodeHeader.h"
#include <WebSocketsClient.h>
WebSocketsClient webSocket;
nodeReadings::nodeReadings() {
}
@@ -23,7 +26,7 @@ void nodeReadings::setup(){
void nodeReadings::loop() {
// loop the websocket connection so it stays alive
webSocket.loop();
// webSocket.loop();
// update when interval is met
if (currentMillis - lastMillis >= interval){
@@ -65,4 +68,37 @@ void nodeReadings::update(){
// check if any errors occured when reading sensors
checkForError();
}
void nodeReadings::displayData() {
// clear display for new info
display.clearDisplay();
// display the data on the oled screen
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0,0);
display.println("Temperature: " + String(temperature) + " C");
display.println("Humidity: " + String(humidity) + " %");
display.println("eCO2: " + String(sgp.eCO2) + " ppm");
display.println("TVOC: " + String(sgp.TVOC) + " ppb");
display.display();
}
void nodeReadings::checkForError(){
if (!sgp.IAQmeasure()) {
Serial.println("SGP30: BAD");
errorSGP30 = true;
} else {
Serial.println("SGP30: OK");
errorSGP30 = false;
}
if (isnan(temperature) || isnan(humidity)){
Serial.println("DHT11: BAD");
errorDHT11 = true;
} else {
Serial.println("DHT11: OK");
errorDHT11 = false;
}
}