diff --git a/docs/rpi-documentation/Databaseconnection.md b/docs/rpi-documentation/Databaseconnection.md index de44bb4..46f49fa 100644 --- a/docs/rpi-documentation/Databaseconnection.md +++ b/docs/rpi-documentation/Databaseconnection.md @@ -13,6 +13,7 @@ import json ``` Then we began the process of connecting with both the websocket and the database. +First-off, we began making a connection to the database by using a mysql library in wich we gave the log in in order to connect to our ow database. ```js //the data that has to be pushed needs to be async def process_data(data): @@ -23,6 +24,10 @@ async def process_data(data): password="*********", database="*******" ) +``` +Then after this we code in the infromation we want to put inside of the database. +The data collected from the websocket is json data, so this has to be changed. +```js cursor = mydb.cursor() // the segments in wich the infromation will be sent. query = "INSERT INTO `Measurement` (NodeID, Type, Value) VALUES (%s, %s, %s)" @@ -48,16 +53,21 @@ async def process_data(data): finally: cursor.close() mydb.close() +``` +After fully connecting t othe database, making statements of what to put there and telling the code what to do, we ofcourse need to write the code to connect to the weebsocket. +We begin by telling our websocket id and what type of port we are using. +Then we will collect live data from the conected websocket, store it in a variable, and then in the previous code +```js //here the connection to the websocked is made async def receive_data(): - uri = "ws://145.92.8.114/ws" + uri = "****************" try: async with websockets.connect(uri) as websocket: while True: // the data collected from the websocket is. data = await websocket.recv() - // dara recieved conformation. + // data recieved: conformation. print(f"Received data: {data}") await process_data(data) // error sowing.