adds last changes to code that clean it up
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Sietse Jonker & Dano Bosch
|
||||
// 27/02/2024
|
||||
|
||||
// include these libraries
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_SH110X.h>
|
||||
#include <Adafruit_SGP30.h>
|
||||
@@ -9,6 +10,7 @@
|
||||
#include <WiFi.h>
|
||||
#include <WebSocketsClient.h>
|
||||
|
||||
// define pins on esp32
|
||||
#define MICPIN 6
|
||||
#define DHTPIN 7
|
||||
#define SCL 9
|
||||
@@ -91,6 +93,7 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
||||
// special function to setup websocket
|
||||
void websocketSetup(){
|
||||
WiFiMulti.addAP("iotroam", "vbK9gbDBIB");
|
||||
WiFiMulti.addAP("LansanKPN-boven", "19sander71vlieland14");
|
||||
|
||||
while(WiFiMulti.run() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
@@ -117,6 +120,7 @@ void resetValues() {
|
||||
TVOC = 0;
|
||||
noise = false;
|
||||
lastCounter = 0;
|
||||
currentCounter = 0;
|
||||
}
|
||||
|
||||
// function to check for errors in sensors
|
||||
@@ -124,16 +128,21 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,9 +155,6 @@ void update(){
|
||||
|
||||
sgp.getIAQBaseline(&eCO2_base, &TVOC_base);
|
||||
|
||||
// if sensor doesnt work print in serialmonitor
|
||||
|
||||
|
||||
// read dht11 sensor
|
||||
temperature = float(dht.readTemperature());
|
||||
humidity = float(dht.readHumidity());
|
||||
@@ -198,7 +204,7 @@ void setup() {
|
||||
// loop function
|
||||
void loop() {
|
||||
webSocket.loop();
|
||||
|
||||
|
||||
if (currentCounter - lastCounter >= interval){
|
||||
lastCounter = millis();
|
||||
update();
|
||||
|
Reference in New Issue
Block a user