From c52da69a529d2755cbf929d12c69c4faeef227e5 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 13 Feb 2024 16:26:54 +0100 Subject: [PATCH 1/2] Start websocket --- server/Websocket.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 server/Websocket.py diff --git a/server/Websocket.py b/server/Websocket.py new file mode 100644 index 0000000..407038c --- /dev/null +++ b/server/Websocket.py @@ -0,0 +1,21 @@ +import websockets; +import asyncio; + + +async def handler(websocket): + while True: + #Save the incoming message in variable message. + message = await websocket.recv() + print(message) + + +async def main(): + async with websockets.serve(handler, "145.92.8.114" , 8001): + await asyncio.Future() # run forever + + +if __name__ == "__main__": + asyncio.run(main()) + + +#https://websockets.readthedocs.io/en/stable/reference/sync/server.html#websockets.sync.server.serve \ No newline at end of file From 90b540e519c8b704d9dc6db5afff49ab519a4428 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 13 Feb 2024 16:33:34 +0100 Subject: [PATCH 2/2] Start websockets documentation --- docs/rpi-documentation/websockets.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/rpi-documentation/websockets.md b/docs/rpi-documentation/websockets.md index ff80e29..c5a612e 100644 --- a/docs/rpi-documentation/websockets.md +++ b/docs/rpi-documentation/websockets.md @@ -1,3 +1,14 @@ # Websockets -## Introduction \ No newline at end of file +## 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. + + + + +#### Sources: +* https://websockets.readthedocs.io/en/stable/index.html \ No newline at end of file