From 970b7eaa41a1fd111412dfefb99957240445e73e Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Tue, 26 Mar 2024 22:46:50 +0100 Subject: [PATCH 1/8] it works yippee (depending on what node sends it data the script will send it to the corresponding table with automatic node numbering) --- server/data.py | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/server/data.py b/server/data.py index e6acb5d..c932aa2 100644 --- a/server/data.py +++ b/server/data.py @@ -6,15 +6,11 @@ import json sensorNodeArray = [] enqueteNodeArray = [] -async def processSensorNodeData(data): +async def processSensorNodeData(data, nodeID): try: mydb = dbLogin() cursor = mydb.cursor() - # MACDataReading = mydb.cursor() - # MACDataReading.execute("SELECT MAC FROM Node") - - print('some_response') query = "INSERT INTO `Measurement` (NodeID, Type, Value) VALUES (%s, %s, %s)" processedData = json.loads(data) @@ -23,18 +19,8 @@ async def processSensorNodeData(data): processedeCO2 = (processedData['eCO2']) processedTVOC = (processedData['TVOC']) processedMAC = (processedData['node']) - MACTuple = (processedMAC,) - # MACDataFetching = MACDataReading.fetchall() - # MACArray = list(MACDataFetching) - - - # if MACTuple not in MACArray: - # addingNode = "INSERT INTO `Node` (MAC) VALUES (%s)" - # cursor.execute(addingNode, MACTuple) - # mydb.commit() - - pushingDataArray = [(1, "Temp", processedTemp), (1, "Humi", processedHumi), (1, "eCO2", processedeCO2), (1, "TVOC", processedTVOC)] + pushingDataArray = [(nodeID, "Temp", processedTemp), (nodeID, "Humi", processedHumi), (nodeID, "eCO2", processedeCO2), (nodeID, "TVOC", processedTVOC)] for i in pushingDataArray: print(query ,i) cursor.execute(query, i) @@ -63,15 +49,19 @@ async def receive_data(): else: type = 'enquete' + + await getNodeInfo('sensor') await getNodeInfo('enquete') - print(str(sensorNodeArray)) + print(sensorNodeArray) - if str(macAdress) in sensorNodeArray: - await processSensorNodeData(data) - elif str(macAdress) in enqueteNodeArray: - await processEnqueteNodeData(data) + if macAdress in sensorNodeArray: + nodeID = await getNodeID(macAdress) + await processSensorNodeData(data, nodeID) + elif macAdress in enqueteNodeArray: + nodeID = await getNodeID(macAdress) + await processEnqueteNodeData(data, nodeID) else: await newNode(macAdress, type) except websockets.ConnectionClosedError as e: @@ -100,6 +90,9 @@ def dbLogin(): return mydb async def getNodeInfo(type): + global sensorNodeArray + global enqueteNodeArray + nodeInfoArray = [] id = (type,) @@ -113,6 +106,9 @@ async def getNodeInfo(type): nodeInfoArray.append(item) print(nodeInfoArray) + cursor.close() + mydb.close() + if type == 'sensor': sensorNodeArray = nodeInfoArray print(sensorNodeArray) @@ -123,6 +119,17 @@ async def getNodeInfo(type): return enqueteNodeArray +async def getNodeID(macAdress): + id = (macAdress,) + mydb = dbLogin() + cursor = mydb.cursor() + cursor.execute("""SELECT nodeID FROM Node WHERE MAC = %s""", id) + data = cursor.fetchall() + + nodeID = data[0][0] + + return nodeID + From 17f6ba8376a357cf90891b7c5b4a51e3e90d69c2 Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Tue, 26 Mar 2024 23:03:26 +0100 Subject: [PATCH 2/8] Add WebSocket data sender scripts --- server/bullshitSenderENQUETE.py | 31 +++++++++++++++++++ ...lshitSender.py => bullshitSenderSENSOR.py} | 0 2 files changed, 31 insertions(+) create mode 100644 server/bullshitSenderENQUETE.py rename server/{bullshitSender.py => bullshitSenderSENSOR.py} (100%) diff --git a/server/bullshitSenderENQUETE.py b/server/bullshitSenderENQUETE.py new file mode 100644 index 0000000..1c58863 --- /dev/null +++ b/server/bullshitSenderENQUETE.py @@ -0,0 +1,31 @@ +import asyncio +import websockets +import json +import random +import time + +async def send_data(uri): + async with websockets.connect(uri) as websocket: + print("Connected to WebSocket server") + + while True: + data = { + "node": "69:42:08:F5:00:00", + "Response": str(round(random.uniform(0, 2))), + "QuestionID": str(round(random.uniform(0, 90))), + } + await websocket.send(json.dumps(data)) + print("Data sent") + + response = await websocket.recv() + print("Received message:", response) + + await asyncio.sleep(2) # Wait a bit before sending the next message + +# Start the WebSocket connection +while True: + try: + asyncio.get_event_loop().run_until_complete(send_data("ws://145.92.8.114/ws")) + except Exception as e: + print("Exception:", e) + time.sleep(1) # Wait a bit before trying to reconnect \ No newline at end of file diff --git a/server/bullshitSender.py b/server/bullshitSenderSENSOR.py similarity index 100% rename from server/bullshitSender.py rename to server/bullshitSenderSENSOR.py From d9a603886c8925789dfcf93649b11e87f750d41f Mon Sep 17 00:00:00 2001 From: Dano van den Bosch Date: Tue, 26 Mar 2024 23:03:28 +0100 Subject: [PATCH 3/8] geboubeheer gesprec documentation --- docs/brainstorm/bebouwBeheer.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/docs/brainstorm/bebouwBeheer.md b/docs/brainstorm/bebouwBeheer.md index eb72943..4a36d3d 100644 --- a/docs/brainstorm/bebouwBeheer.md +++ b/docs/brainstorm/bebouwBeheer.md @@ -9,17 +9,4 @@ ## Feedback: -BM had some good feedback points about the page it self, about the idea and some good pointers for the execution. They would also look into making the data they are already messuring acceseble for us. The things they had to say about the website is: they found the first design a bit unorgenised and said that they had -Sietse design -te klein scherm eigenlijk (1) -naamgeving -zoekfunctie? -opvragen en filteren (idiot proof) -wit zodat niet opvallen -opschreiven wat het doet -hoogtes? - - - - -2x in database \ No newline at end of file +BM had some good feedback points about the page it self, about the idea and some good pointers for the execution. They would also look into making the data they are already messuring acceseble for us. The things they had to say about the website is: they found the first design a bit unorgenised and said that would rather see the second design with were you can select the node you want to see, mayby also a search function to specify the node that is displayed. What also was said was to try to make it idiot proof becouse not all of the BM people are technicly active to put it that way. They had some things to say about the node design, like mayby make the collor white to make it better with blending into the white walls of the total aryea. Thay also asked the question of does it matter at what hight the node is placed. One other thing they said was to write something onto the node to make it clear to the people in the area what it was doeing something like ReaderNode^tm^. And the last thing they said was if we thought about how to make it fandelising sudents proof \ No newline at end of file From 379a8b0f844628ff7a19c27aed76114d54addf6c Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Tue, 26 Mar 2024 23:03:34 +0100 Subject: [PATCH 4/8] Add processEnqueteNodeData function to handle enquete node data --- server/data.py | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/server/data.py b/server/data.py index c932aa2..a863857 100644 --- a/server/data.py +++ b/server/data.py @@ -31,10 +31,33 @@ async def processSensorNodeData(data, nodeID): finally: cursor.close() mydb.close() + +async def processEnqueteNodeData(data, nodeID): + try: + mydb = dbLogin() + cursor = mydb.cursor() + + query = "INSERT INTO `Response` (Node_NodeID, Question_QuestionID, Response) VALUES (%s, %s, %s)" + processedData = json.loads(data) + + processedQuestionID = (processedData['QuestionID']) + processedResponse = (processedData['Response']) + + pushingDataArray = [(nodeID, processedQuestionID, processedResponse)] + + for i in pushingDataArray: + cursor.execute(query, i) + mydb.commit() + except mysql.connector.Error as err: + print("MySQL Error:", err) + finally: + cursor.close() + mydb.close() + + async def receive_data(): uri = "ws://145.92.8.114/ws" - try: async with websockets.connect(uri) as websocket: while True: @@ -44,13 +67,8 @@ async def receive_data(): processedData = json.loads(data) macAdress = processedData['node'] - if processedData["Temp"]: - type = 'sensor' - else: - type = 'enquete' - + type = await getNodeType(macAdress) - await getNodeInfo('sensor') await getNodeInfo('enquete') @@ -67,15 +85,6 @@ async def receive_data(): except websockets.ConnectionClosedError as e: print("WebSocket connection closed:", e) -async def processEnqueteNodeData(data): - mydb = dbLogin() - cursor = mydb.cursor() - - query = "INSERT INTO `Response` (NodeID, QuestionID, Response) VALUES (%s, %s, %s)" - processedData = json.loads(data) - - - async def main(): await receive_data() @@ -130,8 +139,16 @@ async def getNodeID(macAdress): return nodeID +async def getNodeType(macAdress): + id = (macAdress,) + mydb = dbLogin() + cursor = mydb.cursor() + cursor.execute("""SELECT Type FROM Node WHERE MAC = %s""", id) + data = cursor.fetchall() + Type = data[0][0] + return Type async def newNode(mac, type): id = (mac, type,) From fb9088e2b1549968e11bbca026551aa069179253 Mon Sep 17 00:00:00 2001 From: Dano van den Bosch Date: Tue, 26 Mar 2024 23:06:36 +0100 Subject: [PATCH 5/8] spell check --- docs/brainstorm/bebouwBeheer.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/brainstorm/bebouwBeheer.md b/docs/brainstorm/bebouwBeheer.md index 4a36d3d..45891bc 100644 --- a/docs/brainstorm/bebouwBeheer.md +++ b/docs/brainstorm/bebouwBeheer.md @@ -1,12 +1,12 @@ # Talk with building management -## Questions for BM +## Questions for building management 1. Design of page? (current page, new design or own idea) -2. What do they expect of a page made for BM? +2. What do they expect of a page made for building management? 3. Do they think they can work with the incomming feedback from the enquete? 4. Design of the node? (plastic or wood) ## Feedback: -BM had some good feedback points about the page it self, about the idea and some good pointers for the execution. They would also look into making the data they are already messuring acceseble for us. The things they had to say about the website is: they found the first design a bit unorgenised and said that would rather see the second design with were you can select the node you want to see, mayby also a search function to specify the node that is displayed. What also was said was to try to make it idiot proof becouse not all of the BM people are technicly active to put it that way. They had some things to say about the node design, like mayby make the collor white to make it better with blending into the white walls of the total aryea. Thay also asked the question of does it matter at what hight the node is placed. One other thing they said was to write something onto the node to make it clear to the people in the area what it was doeing something like ReaderNode^tm^. And the last thing they said was if we thought about how to make it fandelising sudents proof \ No newline at end of file +building management had some good feedback points about the page itself, about the idea, and some good pointers for the execution. They would also look into making the data they are already measuring accessible for us. The things they had to say about the website are: they found the first design a bit unorganized and said that they would rather see the second design where you can select the node you want to see, maybe also a search function to specify the node that is displayed. What also was said was to try to make it idiot-proof because not all of the building management people are technically active, to put it that way. They had some things to say about the node design, like maybe make the color white to make it better with blending into the white walls of the total area. They also asked the question of does it matter at what height the node is placed. One other thing they said was to write something onto the node to make it clear to the people in the area what it was doing, something like ReaderNodeā„¢. And the last thing they said was if we thought about how to make it vandalizing students proof. \ No newline at end of file From 75ff84ee70f1142bf6ea5ce7e3d349b39fabc238 Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Tue, 26 Mar 2024 23:19:15 +0100 Subject: [PATCH 6/8] Refactor database queries and update variable names --- server/data.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/data.py b/server/data.py index a863857..cb93efa 100644 --- a/server/data.py +++ b/server/data.py @@ -37,13 +37,13 @@ async def processEnqueteNodeData(data, nodeID): mydb = dbLogin() cursor = mydb.cursor() - query = "INSERT INTO `Response` (Node_NodeID, Question_QuestionID, Response) VALUES (%s, %s, %s)" + query = "INSERT INTO `Reply` (Result, Node_NodeID, Question_QuestionID) VALUES (%s, %s, %s)" processedData = json.loads(data) processedQuestionID = (processedData['QuestionID']) processedResponse = (processedData['Response']) - pushingDataArray = [(nodeID, processedQuestionID, processedResponse)] + pushingDataArray = [(processedResponse, nodeID, processedQuestionID)] for i in pushingDataArray: cursor.execute(query, i) @@ -67,8 +67,11 @@ async def receive_data(): processedData = json.loads(data) macAdress = processedData['node'] - type = await getNodeType(macAdress) - + if "Temp" in processedData: + type = 'sensor' + else: + type = 'enquete' + await getNodeInfo('sensor') await getNodeInfo('enquete') @@ -135,7 +138,9 @@ async def getNodeID(macAdress): cursor.execute("""SELECT nodeID FROM Node WHERE MAC = %s""", id) data = cursor.fetchall() - nodeID = data[0][0] + for tuples in data: + for item in tuples: + nodeID = item return nodeID @@ -146,8 +151,10 @@ async def getNodeType(macAdress): cursor.execute("""SELECT Type FROM Node WHERE MAC = %s""", id) data = cursor.fetchall() - Type = data[0][0] - + for tuples in data: + for item in tuples: + Type = item + return Type async def newNode(mac, type): From 5ce77d54efdecd7980c3996256cbde240b607a00 Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Tue, 26 Mar 2024 23:20:05 +0100 Subject: [PATCH 7/8] remove unesecarry code --- server/data.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/server/data.py b/server/data.py index cb93efa..c2e7a89 100644 --- a/server/data.py +++ b/server/data.py @@ -143,19 +143,6 @@ async def getNodeID(macAdress): nodeID = item return nodeID - -async def getNodeType(macAdress): - id = (macAdress,) - mydb = dbLogin() - cursor = mydb.cursor() - cursor.execute("""SELECT Type FROM Node WHERE MAC = %s""", id) - data = cursor.fetchall() - - for tuples in data: - for item in tuples: - Type = item - - return Type async def newNode(mac, type): id = (mac, type,) @@ -166,5 +153,4 @@ async def newNode(mac, type): print("new node assigned") mydb.commit() -asyncio.run(main()) - +asyncio.run(main()) \ No newline at end of file From 6735a498ca5a257db6f5a42d8c41d94fe0093965 Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Tue, 26 Mar 2024 23:20:28 +0100 Subject: [PATCH 8/8] Remove unnecessary whitespace in data.py --- server/data.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/data.py b/server/data.py index c2e7a89..3157c8a 100644 --- a/server/data.py +++ b/server/data.py @@ -54,8 +54,6 @@ async def processEnqueteNodeData(data, nodeID): cursor.close() mydb.close() - - async def receive_data(): uri = "ws://145.92.8.114/ws" try: