Files
J1B3-Sensor-boxes/docs/node-documentation/node.md
2024-04-03 11:50:14 +02:00

3.1 KiB

Node

Since the node is what gathers all the data from the sensors, it is the most important part of the system. The node is responsible for reading the data from the sensors, processing it, and sending it to the server.

Hardware

The node is composed of the following hardware components:

Software

The node is programmed using the Arduino IDE. The code is written in C++ and is responsible for reading the data from the sensors, processing it, and sending it to the server. The first couple versions of the code were written by Sietse, and because we all had to use Object Oriented Programming, Dano rewrote the code to be object-oriented. Which is now final version

Libraries

The following libraries are used in the node code:

  • Wire.h
  • Adafruit_SH110X.h
  • Adafruit_SGP30.h
  • DHT.h
  • WiFiMulti.h
  • WiFi.h
  • WebSocketsClient.h
  • nodeCodeHeader.h

Code

The code is divided into the following classes:

  • Node readings
  • Websockets

The two classes that are used are split into the 2 becouse the node readings handels everything about reading information from the sensors and displaying them on the screen, all the local stuff is handeled here so to speak. And into Websockets this handels every thing from connecting to the wifi to sending the data that is recorded from the sensors into json format and sending that data to the websockets so that the data can be prossed over there.

Communication

The node communicates with the server using WebSockets. The node sends the data to our website which uses a reverse proxy to route it to the websocket. The server then processes the data and stores it in the database / puts it on the website. We use the WebSocketsClient library to communicate with the server. Because websocket connections are stateful, we need to keep the connection alive. So we do not use any delays in the code, but instead use the millis() function to keep track of time.

Flow of the data:


flowchart LR
    A(Sensors)
    B(Node)
    D(Websocket)
    E(Website)
    F(DB-Client)
    G(Database)

    A-->|sensordata| B
    B -->|JSONData| D
    D -->|JSONData| E
    D -->|JSONData| F
    F -->|Data| G

Wiring Diagram

The wiring diagram for the node is as follows:

Wiring diagram of node

Fritsing Diagram

fritsing diagram of node

Future Improvements

The node is currently working as intended, but there are some improvements that could be made:

  • The node could be made more energy efficient by putting the ESP32 in deep sleep mode when it is not sending data.
  • The node could be made more robust by adding error handling to the code.
  • The node could be made more secure by adding encryption to the data that is sent to the server.