Files
J1B3-Sensor-boxes/docs/rpi-documentation/websockets.md

1.8 KiB

Websockets

Introduction

Why are we going to use websockets?

With websockets you can establish a connection between the client and the server, and both can send data fast to each other. This is useful for real-time applications like for our project to plot live graphs of the data we are collecting from the sensors.

How to use websockets

There are different languages to serve websockets with, but we are going to use Python with the library websockets. This library is easy to use and has a lot of documentation.

Issues

Ports

We can only use certain ports like 113, 80, 443. These are common ports and are not blocked by firewalls. Something in the network is blocking all other ports which makes it hard to use websockets.

A solution for this is to use a reverse proxy. (See Reverse Proxy)

Classes

For the websockets we are going to use 2 classes. One for the nodes and one for the websites. The nodes are going to send data to the website and have multiple variables like temperature, humidity, eCO2, TVOC and sound. The website is going to send data to the nodes like names and settings. For this they have to use a userName and password.

classDiagram

client --> Website : website client
client --> Node : esp32 client
Website --> Node : settings

namespace raspberry pi clients {
    class client {
        +MacAdress
        sendData()
    }

    class Node {
        +eCO2
        +Temperature
        +Humidity
        +TVOC
        +Sound
        +Settings
        changeNodeName(name)
        updateData(data)
    }

    class Website {
        +userName
        +password
        changeNodeName(data)
    }
}

Sources:

Written by Sam & Sietse