OOP made in arduino 👍
This commit is contained in:
@@ -1,41 +1,19 @@
|
||||
#include "arduino.h"
|
||||
// #include <arduino.h>
|
||||
#include "nodeCodeHeader.h"
|
||||
#include <WebSocketsClient.h>
|
||||
// #include <DHT.h>
|
||||
// #include <Adafruit_SH110X.h>
|
||||
|
||||
WebSocketsClient webSocket;
|
||||
|
||||
nodeReadings::nodeReadings() {
|
||||
}
|
||||
|
||||
void nodeReadings::setup(){
|
||||
// make serial connection at 115200 baud
|
||||
Serial.begin(115200);
|
||||
dht = new DHT(DHTPIN, DHTTYPE);
|
||||
display = new Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
webSocket = new WebSocketsClient();
|
||||
sgp = new Adafruit_SGP30();
|
||||
|
||||
// tell display what settings to use
|
||||
display.begin(i2c_adress, true);
|
||||
display.clearDisplay();
|
||||
resetValues();
|
||||
|
||||
// tell sensors to start reading
|
||||
dht.begin();
|
||||
sgp.begin();
|
||||
|
||||
pinMode(MICPIN, INPUT);
|
||||
pinMode(DHTPIN, INPUT);
|
||||
|
||||
}
|
||||
|
||||
void nodeReadings::loop() {
|
||||
// loop the websocket connection so it stays alive
|
||||
// webSocket.loop();
|
||||
|
||||
// update when interval is met
|
||||
if (currentMillis - lastMillis >= interval){
|
||||
lastMillis = millis();
|
||||
update();
|
||||
}
|
||||
|
||||
// update the counter
|
||||
currentMillis = millis();
|
||||
}
|
||||
|
||||
void nodeReadings::resetValues() {
|
||||
@@ -51,20 +29,53 @@ void nodeReadings::resetValues() {
|
||||
noise = false;
|
||||
}
|
||||
|
||||
void nodeReadings::setup(){
|
||||
// DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
|
||||
// make serial connection at 115200 baud
|
||||
Serial.begin(115200);
|
||||
|
||||
// tell display what settings to use
|
||||
display->begin(i2c_adress, true);
|
||||
display->clearDisplay();
|
||||
|
||||
// tell sensors to start reading
|
||||
dht->begin();
|
||||
sgp->begin();
|
||||
|
||||
pinMode(MICPIN, INPUT);
|
||||
pinMode(DHTPIN, INPUT);
|
||||
|
||||
}
|
||||
|
||||
void nodeReadings::loop() {
|
||||
// loop the websocket connection so it stays alive
|
||||
// webSocket->loop();
|
||||
|
||||
// update when interval is met
|
||||
if (currentMillis - lastMillis >= interval){
|
||||
lastMillis = millis();
|
||||
update();
|
||||
}
|
||||
|
||||
// update the counter
|
||||
currentMillis = millis();
|
||||
}
|
||||
|
||||
void nodeReadings::update(){
|
||||
|
||||
// display sensordata on oled screen
|
||||
displayData();
|
||||
|
||||
// webSocket.sendTXT("{\"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp.eCO2) + "\",\"TVOC\":\"" + String(sgp.TVOC) + "\"}");
|
||||
webSocket.sendTXT("{\"node\": \"" + String(WiFi.macAddress()) + "\", \"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp.eCO2) + "\",\"TVOC\":\"" + String(sgp.TVOC) + "\"}");
|
||||
// webSocket->sendTXT("{\"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp->eCO2) + "\",\"TVOC\":\"" + String(sgp->TVOC) + "\"}");
|
||||
webSocket->sendTXT("{\"node\": \"" + String(WiFi.macAddress()) + "\", \"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp->eCO2) + "\",\"TVOC\":\"" + String(sgp->TVOC) + "\"}");
|
||||
|
||||
sgp.getIAQBaseline(&eCO2_base, &TVOC_base);
|
||||
sgp->getIAQBaseline(&eCO2_base, &TVOC_base);
|
||||
|
||||
// read dht11 sensor
|
||||
temperature = float(dht.readTemperature());
|
||||
humidity = float(dht.readHumidity());
|
||||
temperature = float(dht->readTemperature());
|
||||
humidity = float(dht->readHumidity());
|
||||
|
||||
// check if any errors occured when reading sensors
|
||||
checkForError();
|
||||
@@ -72,21 +83,21 @@ void nodeReadings::update(){
|
||||
|
||||
void nodeReadings::displayData() {
|
||||
// clear display for new info
|
||||
display.clearDisplay();
|
||||
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();
|
||||
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()) {
|
||||
if (!sgp->IAQmeasure()) {
|
||||
Serial.println("SGP30: BAD");
|
||||
errorSGP30 = true;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user