From 6c3b523208ad6d22a17d664f10712f309f19511f Mon Sep 17 00:00:00 2001 From: Sietse Jonker Date: Wed, 13 Mar 2024 14:44:32 +0100 Subject: [PATCH] Update webSocket message format and add classes for websockets --- .../node-code-final/node-code-final.ino | 4 +- docs/rpi-documentation/websockets.md | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/arduino/node-code/node-code-final/node-code-final.ino b/arduino/node-code/node-code-final/node-code-final.ino index ff9485a..682b509 100644 --- a/arduino/node-code/node-code-final/node-code-final.ino +++ b/arduino/node-code/node-code-final/node-code-final.ino @@ -60,7 +60,7 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload); // send message to server when Connected - webSocket.sendTXT("Connected"); + webSocket.sendTXT("{\"message\": \"Connected\"}"); break; case WStype_TEXT: // USE_SERIAL.printf("[WSc] get text: %s\n", payload); @@ -86,7 +86,7 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { // special function to setup websocket void websocketSetup(){ - WiFiMulti.addAP("iotroam", "WFXRLtSwN2"); + WiFiMulti.addAP("iotroam", "vbK9gbDBIB"); WiFiMulti.addAP("LansanKPN-boven", "19sander71vlieland14"); while(WiFiMulti.run() != WL_CONNECTED) { diff --git a/docs/rpi-documentation/websockets.md b/docs/rpi-documentation/websockets.md index e69d2b8..96cc060 100644 --- a/docs/rpi-documentation/websockets.md +++ b/docs/rpi-documentation/websockets.md @@ -14,7 +14,43 @@ We can only use certain ports like 113, 80, 443. These are common ports and are A solution for this is to use a reverse proxy. (See [Reverse Proxy](./Reverse-Proxy.md)) +## 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. + +``` mermaid +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: * https://websockets.readthedocs.io/en/stable/index.html -**Written by Sam** \ No newline at end of file +**Written by Sam & Sietse** \ No newline at end of file