From f94c452a19a28fbc7dec4afe78fcad5b9a5b6a0e Mon Sep 17 00:00:00 2001 From: Dano van den Bosch Date: Thu, 21 Mar 2024 11:31:03 +0100 Subject: [PATCH] added comments --- arduino/node-code/nodeCodeFinal/nodeCodeFinal.ino | 2 -- arduino/node-code/nodeCodeFinal/nodeCodeHeader.cpp | 12 +++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arduino/node-code/nodeCodeFinal/nodeCodeFinal.ino b/arduino/node-code/nodeCodeFinal/nodeCodeFinal.ino index d984954..acb3434 100644 --- a/arduino/node-code/nodeCodeFinal/nodeCodeFinal.ino +++ b/arduino/node-code/nodeCodeFinal/nodeCodeFinal.ino @@ -4,12 +4,10 @@ nodeReadings esp32Node; void setup() { - // put your setup code here, to run once: esp32Node.setup(); esp32Node.resetValues(); } void loop() { - // put your main code here, to run repeatedly: esp32Node.loop(); } diff --git a/arduino/node-code/nodeCodeFinal/nodeCodeHeader.cpp b/arduino/node-code/nodeCodeFinal/nodeCodeHeader.cpp index cac49f7..e69dd42 100644 --- a/arduino/node-code/nodeCodeFinal/nodeCodeHeader.cpp +++ b/arduino/node-code/nodeCodeFinal/nodeCodeHeader.cpp @@ -2,16 +2,19 @@ nodeReadings::nodeReadings() { + //Making all the new object as defined in the .h file dht = new DHT(DHTPIN, DHTTYPE); display = new Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); - webSocket = new websockets(); //nu naar eigen class + webSocket = new websockets(); sgp = new Adafruit_SGP30(); + //setting the reding for every 5 sec interval = 5000; resetValues(); } +//Script for simpley reseting every value to 0 void nodeReadings::resetValues() { counter = 0; eCO2 = 0; @@ -25,6 +28,7 @@ void nodeReadings::resetValues() { noise = false; } +//Setup for initilising the dht and sgp sensors. Also the display is set up. void nodeReadings::setup(){ // make serial connection at 115200 baud Serial.begin(115200); @@ -63,6 +67,7 @@ void nodeReadings::update(){ // display sensordata on oled screen displayData(); + //send the data to the websockets webSocket->sendMyText("{\"node\": \"" + String(WiFi.macAddress()) + "\", \"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp->eCO2) + "\",\"TVOC\":\"" + String(sgp->TVOC) + "\"}"); sgp->getIAQBaseline(&eCO2_base, &TVOC_base); @@ -83,13 +88,14 @@ void nodeReadings::displayData() { display->setTextSize(2); display->setTextColor(SH110X_WHITE); display->setCursor(0,0); - display->println("Temp: " + String(int(temperature)) + " C"); - display->println("Humi: " + String(int(humidity)) + " %"); + display->println("Temp: " + String(int(temperature)) + "C"); + display->println("Humi: " + String(int(humidity)) + "%"); display->println("eCO2: " + String(sgp->eCO2));// + " ppm"); display->println("TVOC: " + String(sgp->TVOC));// + " ppb"); display->display(); } +//function void nodeReadings::checkForError(){ if (!sgp->IAQmeasure()) { Serial.println("SGP30: BAD");