Refactor JSON parsing and data handling functions
This commit is contained in:
@@ -2,15 +2,17 @@
|
||||
|
||||
### parsing JSON
|
||||
|
||||
The data that is send by the nodes is send in json data. We chose this becouse we can easily use the data within javascript, this is called parsing. We use the parced data and send that in to the next function to make the data more acceseble to use in further instences.
|
||||
|
||||
```js
|
||||
const jsonData = JSON.parse(event.data);
|
||||
// Use the parsed JSON data as needed
|
||||
handleIncomingData(jsonData);
|
||||
```
|
||||
|
||||
### Pro
|
||||
|
||||
Here is the function that receves the parced JSON data and set it into variables.
|
||||
|
||||
```js
|
||||
function handleIncomingData(data) {
|
||||
nodeNumber = data.node;
|
||||
temperature = data.Temp;
|
||||
@@ -20,7 +22,7 @@ function handleIncomingData(data) {
|
||||
|
||||
processNodeData(nodeNumber, temperature, humidity, CO2, TVOC);
|
||||
}
|
||||
|
||||
```
|
||||
function processNodeData(nodeNumber, temperature, humidity, CO2, TVOC) {
|
||||
// Initialize the array for this node if it doesn't exist yet
|
||||
if (!sensorData[nodeNumber]) {
|
||||
|
Reference in New Issue
Block a user