Merge branch '44-als-gebruiker-wil-ik-dat-de-website-automatisch-het-aantal-nodes-dat-ik-heb-aangesloten-op-de' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59 into 44-als-gebruiker-wil-ik-dat-de-website-automatisch-het-aantal-nodes-dat-ik-heb-aangesloten-op-de
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -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);
|
||||
@@ -90,6 +95,7 @@ void nodeReadings::displayData() {
|
||||
display->display();
|
||||
}
|
||||
|
||||
//function
|
||||
void nodeReadings::checkForError(){
|
||||
if (!sgp->IAQmeasure()) {
|
||||
Serial.println("SGP30: BAD");
|
||||
|
120
docs/brainstorm/SoftwareDocumentatie/classes-website.md
Normal file
120
docs/brainstorm/SoftwareDocumentatie/classes-website.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# Nodes
|
||||
|
||||
## Introduction
|
||||
|
||||
The nodes are the devices that are placed in the rooms. The nodes are used to collect the data from the sensors. Every node is connected to the websocket, and sends their data with their mac address in json format. The websocket broadcasts the node data back to all clients, and since our website functions as a client it also receives the data. Every node will, depending on what node, be made into a class.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Sensornode
|
||||
|
||||
- Every node has to have a unique nodeID
|
||||
- Every node has to have their corresponding sensorsvalues in form of arrays
|
||||
|
||||
### Feedbacknodes
|
||||
|
||||
- Every node has to have a unique nodeID
|
||||
- Every node has to have their corresponding feedback in form of a 2D array
|
||||
|
||||
## Class diagrams
|
||||
|
||||
### Node
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
|
||||
Node <-- SensorNode : extends
|
||||
Node <-- FeedbackNode : extends
|
||||
|
||||
class Node {
|
||||
+nodeID
|
||||
+processNodeData()
|
||||
+updateNodeData()
|
||||
}
|
||||
|
||||
class SensorNode {
|
||||
+tempArray
|
||||
+humiArray
|
||||
+eco2Array
|
||||
+tvocArray
|
||||
}
|
||||
|
||||
class FeedbackNode {
|
||||
+feedbackArray
|
||||
}
|
||||
```
|
||||
|
||||
# Graphs
|
||||
|
||||
## Introduction
|
||||
|
||||
The graphs are used to display the data from the sensors. The data is collected by the raspberry pi and then displayed on the graphs. The graphs are made using the [plotly library](https://plotly.com/javascript/) .
|
||||
|
||||
## Requirements
|
||||
|
||||
### Live graphs
|
||||
- Every node has to have a live graph
|
||||
- The graphs has to be updated every 5 seconds
|
||||
- All the data from one node has to fit in one graph
|
||||
|
||||
|
||||
## Class diagrams
|
||||
|
||||
### Graphs
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
|
||||
liveGraph --> graph: extends
|
||||
class graph {
|
||||
+nodeId
|
||||
makeGraph()
|
||||
}
|
||||
|
||||
class liveGraph {
|
||||
+cnt
|
||||
+timeArray
|
||||
+tempArray
|
||||
+humiArray
|
||||
+eco2Array
|
||||
+tvocArray
|
||||
makeGraph()
|
||||
updateGraph()
|
||||
updateData()
|
||||
}
|
||||
|
||||
```
|
||||
## Order of operations
|
||||
|
||||
### Live graphs
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Node
|
||||
participant Raspberry pi
|
||||
participant Website
|
||||
|
||||
Node->>Raspberry pi: sensordata via websocket every 5 seconds
|
||||
Raspberry pi->>Website: Node data via websocket if new data is received from the node
|
||||
Website->>Website: updateGraph()
|
||||
Website->>Website: updateData()
|
||||
```
|
||||
|
||||
1. Every node sends its data to the raspberry pi via websocket every 5 seconds
|
||||
2. The raspberry pi sends the data to the website via websocket if new data is received from the node
|
||||
3. The website updates the data coming from the raspberry pi on its own variables and arrays
|
||||
4. The website updates the live graphs every time new data is received from the websocket
|
||||
|
||||
### Node
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Node
|
||||
participant Raspberry pi
|
||||
participant Website
|
||||
|
||||
Node->>Raspberry pi: node data via websocket every 5 seconds
|
||||
Raspberry pi->>Website: Make a new object depending on what node it is
|
||||
Website->>Website: updateNodeData()
|
||||
Website->>Website: processNodeData()
|
||||
```
|
@@ -1,56 +0,0 @@
|
||||
# Graphs
|
||||
|
||||
## Introduction
|
||||
|
||||
The graphs are used to display the data from the sensors. The data is collected by the raspberry pi and then displayed on the graphs. The graphs are made using the [plotly library](https://plotly.com/javascript/) .
|
||||
|
||||
## Requirements
|
||||
|
||||
### Live graphs
|
||||
- Every node has to have a live graph
|
||||
- The graphs has to be updated every 5 seconds
|
||||
- All the data from one node has to fit in one graph
|
||||
|
||||
|
||||
## Class diagrams
|
||||
|
||||
### Live graphs
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class liveGraph {
|
||||
+nodeId
|
||||
+cnt
|
||||
+timeArray
|
||||
+tempArray
|
||||
+humiArray
|
||||
+eco2Array
|
||||
+tvocArray
|
||||
makeGraph()
|
||||
updateGraph()
|
||||
updateData()
|
||||
}
|
||||
```
|
||||
|
||||
## Order of operations
|
||||
|
||||
### Live graphs
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant Node
|
||||
participant Raspberry pi
|
||||
participant Website
|
||||
|
||||
Node->>Raspberry pi: sensordata via websocket every 5 seconds
|
||||
Raspberry pi->>Website: Node data via websocket if new data is received from the node
|
||||
Website->>Website: updateGraph()
|
||||
Website->>Website: updateData()
|
||||
```
|
||||
|
||||
1. Every node sends its data to the raspberry pi via websocket every 5 seconds
|
||||
2. The raspberry pi sends the data to the website via websocket if new data is received from the node
|
||||
3. The website updates the data coming from the raspberry pi on its own variables and arrays
|
||||
4. The website updates the live graphs every time new data is received from the websocket
|
||||
|
||||
|
@@ -1,7 +1,47 @@
|
||||
class liveGraph {
|
||||
class node {
|
||||
// Constructor to initialize the node
|
||||
constructor(nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
this.temperature = 0;
|
||||
this.humidity = 0;
|
||||
this.eCO2 = 0;
|
||||
this.TVOC = 0;
|
||||
this.connected = false;
|
||||
}
|
||||
// Function to update the data
|
||||
updateData(temperature, humidity, eCO2, TVOC) {
|
||||
this.temperature = temperature;
|
||||
this.humidity = humidity;
|
||||
this.eCO2 = eCO2;
|
||||
this.TVOC = TVOC;
|
||||
}
|
||||
// Function to update the connection status
|
||||
updateConnection() {
|
||||
if (connectedNodes[this.nodeId]) {
|
||||
this.connected = true;
|
||||
} else {
|
||||
this.connected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class feedbackNode extends node {
|
||||
// Constructor to initialize the feedback node
|
||||
constructor(nodeId) {
|
||||
super(nodeId);
|
||||
this.feedback = {};
|
||||
this.answers = 0;
|
||||
}
|
||||
// Function to update the feedback
|
||||
updateFeedback(feedback) {
|
||||
this.feedback = feedback;
|
||||
}
|
||||
}
|
||||
|
||||
class liveGraph extends graph {
|
||||
// Constructor to initialize the graph
|
||||
constructor(id) {
|
||||
this.timeArray = [];
|
||||
super(id);
|
||||
this.tempArray = [];
|
||||
this.humiArray = [];
|
||||
this.eco2Array = [];
|
||||
@@ -60,7 +100,12 @@ class liveGraph {
|
||||
|
||||
let update = {
|
||||
x: [[this.timeArray]],
|
||||
y: [[this.tempArray], [this.humiArray], [this.eco2Array], [this.tvocArray]]
|
||||
y: [
|
||||
[this.tempArray],
|
||||
[this.humiArray],
|
||||
[this.eco2Array],
|
||||
[this.tvocArray],
|
||||
],
|
||||
};
|
||||
|
||||
let olderTime = time.setMinutes(time.getMinutes() - 1);
|
||||
@@ -82,4 +127,46 @@ class liveGraph {
|
||||
this.eco2Array.push(eCO2 / 10);
|
||||
this.tvocArray.push(TVOC / 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class graph {
|
||||
// Constructor to initialize the graph
|
||||
constructor(id) {
|
||||
this.nodeId = "graph" + id;
|
||||
this.timeArray = [];
|
||||
}
|
||||
// Function to create a graph
|
||||
makeGraph(amountOfGraphs, array1, array2, array3, array4) {
|
||||
for (let i = 0; i < amountOfGraphs; i++) {
|
||||
// Create a new line for temperature
|
||||
Plotly.plot(this.nodeId, [
|
||||
{
|
||||
x: this.timeArray, // Use timeArray as x values
|
||||
y: array + i,
|
||||
mode: "lines",
|
||||
line: { color: "#FF0000" },
|
||||
name: "Temperature",
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
// Function to update the graph with new values got from updateData function
|
||||
updateGraph(array1, array2, array3, array4) {
|
||||
let time = new Date();
|
||||
this.timeArray.push(new Date());
|
||||
|
||||
let update = {
|
||||
x: [[this.timeArray]],
|
||||
y: [array1, array2, array3, array4],
|
||||
};
|
||||
|
||||
let olderTime = time.setMinutes(time.getMinutes() - 1);
|
||||
let futureTime = time.setMinutes(time.getMinutes() + 1);
|
||||
let minuteView = {
|
||||
xaxis: {
|
||||
type: "date",
|
||||
range: [olderTime, futureTime],
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user