moved websocket class to work with esp
This commit is contained in:
@@ -3,20 +3,20 @@
|
||||
// #include <WebSocketsClient.h>
|
||||
|
||||
|
||||
|
||||
// websockets webSocketClass;
|
||||
nodeReadings esp32Node;
|
||||
websockets webSocketClass;
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
esp32Node.setup();
|
||||
webSocketClass.websocketSetup();
|
||||
// webSocketClass.websocketSetup();
|
||||
esp32Node.resetValues();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
esp32Node.loop();
|
||||
webSocketClass.loop();
|
||||
// webSocketClass.loop();
|
||||
|
||||
}
|
||||
|
@@ -9,7 +9,8 @@ nodeReadings::nodeReadings() {
|
||||
dht = new DHT(DHTPIN, DHTTYPE);
|
||||
display = new Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
webSocket = new WebSocketsClient();
|
||||
// webSocket = new WebSocketsClient();
|
||||
webSocket = new websockets(); //nu naar eigen class
|
||||
sgp = new Adafruit_SGP30();
|
||||
|
||||
resetValues();
|
||||
@@ -46,13 +47,15 @@ void nodeReadings::setup(){
|
||||
|
||||
pinMode(MICPIN, INPUT);
|
||||
pinMode(DHTPIN, INPUT);
|
||||
|
||||
webSocket->websocketSetup();
|
||||
|
||||
// webSocketClass.websocketSetup();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void nodeReadings::loop() {
|
||||
// loop the websocket connection so it stays alive
|
||||
// webSocket->loop();
|
||||
|
||||
// update when interval is met
|
||||
if (currentMillis - lastMillis >= interval){
|
||||
lastMillis = millis();
|
||||
@@ -61,6 +64,9 @@ void nodeReadings::loop() {
|
||||
|
||||
// update the counter
|
||||
currentMillis = millis();
|
||||
|
||||
// loop the websocket connection so it stays alive
|
||||
webSocket->loop();
|
||||
}
|
||||
|
||||
void nodeReadings::update(){
|
||||
@@ -69,7 +75,7 @@ void nodeReadings::update(){
|
||||
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->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);
|
||||
|
||||
|
@@ -7,8 +7,9 @@
|
||||
#include <Adafruit_SH110X.h>
|
||||
// #include "headerFile.h"
|
||||
#include <DHT.h>
|
||||
#include <WebSocketsClient.h>
|
||||
// #include <WebSocketsClient.h>
|
||||
#include <Adafruit_SGP30.h>
|
||||
#include "websockets.h"
|
||||
|
||||
// define pins on esp32
|
||||
#define MICPIN 6
|
||||
@@ -40,7 +41,8 @@ public:
|
||||
private:
|
||||
DHT *dht;
|
||||
Adafruit_SH1106G *display;
|
||||
WebSocketsClient *webSocket;
|
||||
// WebSocketsClient *webSocket;
|
||||
websockets *webSocket;
|
||||
Adafruit_SGP30 *sgp;
|
||||
|
||||
uint16_t TVOC_base, eCO2_base;
|
||||
|
@@ -80,4 +80,11 @@ void websockets::webSocketEvent(WStype_t type, uint8_t * payload, size_t length)
|
||||
}
|
||||
}
|
||||
|
||||
void websockets::sendMyText(String message) {
|
||||
|
||||
webSocket->sendTXT(message);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -19,6 +19,7 @@ class websockets {
|
||||
void websocketSetup();
|
||||
void loop();
|
||||
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length);
|
||||
void sendMyText(String message);
|
||||
|
||||
private:
|
||||
WebSocketsClient *webSocket;
|
||||
|
Reference in New Issue
Block a user