finishes up code for node

This commit is contained in:
sietse jonker
2024-02-27 19:46:52 +01:00
parent 5558289ba2
commit dcb2f37694

View File

@@ -1,5 +1,5 @@
// Sietse Jonker & Dano Bosch
// 13/02/2024
// 27/02/2024
#include <Wire.h>
#include <Adafruit_SH110X.h>
@@ -9,7 +9,6 @@
#include <WiFi.h>
#include <WebSocketsClient.h>
#define MICPIN 6
#define DHTPIN 7
#define SCL 9
@@ -28,18 +27,18 @@ Adafruit_SGP30 sgp;
WebSocketsClient webSocket;
// define variables
uint16_t TVOC_base;
uint16_t eCO2_base;
uint16_t TVOC_base, eCO2_base;
uint16_t counter = 0;
float temperature = 0;
float humidity = 0;
uint16_t eCO2 = 0;
uint16_t TVOC = 0;
bool noise = false;
bool update = false;
unsigned long currentCounter;
unsigned long lastCounter;
uint16_t interval = 5000
uint16_t interval = 5000;
bool errorSGP30 = false;
bool errorDHT11 = false;
// hexdump function for websockets binary handler
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
@@ -130,8 +129,8 @@ bool checkForError(){
errorSGP30 = false;
}
if (isnan(temperature || isnan(humidity)){
Serial.println("DHT11: BAD")
if (isnan(temperature) || isnan(humidity)){
Serial.println("DHT11: BAD");
} else {
Serial.println("DHT11: OK");
errorDHT11 = false;
@@ -200,32 +199,8 @@ 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));
sgp.getIAQBaseline(&eCO2_base, &TVOC_base);
}
// if sensor doesnt work print in serialmonitor
if (!sgp.IAQmeasure()) {
// Serial.println("SGP30: BAD");
return;
} else {
// Serial.println("SGP30: OK");
}
// read dht11 sensor
temperature = float(dht.readTemperature());
humidity = float(dht.readHumidity());
// display sensordata on oled screen
displayData();
if (currentCounter - lastCounter >= interval){
lastcounter = millis()
lastCounter = millis();
update();
}