Merge branch 'main' of gitlab.fdmci.hva.nl:propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59

This commit is contained in:
Bram Barbieri
2024-03-27 11:27:36 +01:00
4 changed files with 83 additions and 50 deletions

View File

@@ -1,25 +1,12 @@
# Talk with building management # Talk with building management
## Questions for BM ## Questions for building management
1. Design of page? (current page, new design or own idea) 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? 3. Do they think they can work with the incomming feedback from the enquete?
4. Design of the node? (plastic or wood) 4. Design of the node? (plastic or wood)
## Feedback: ## 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 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.
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

View File

@@ -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

View File

@@ -6,15 +6,11 @@ import json
sensorNodeArray = [] sensorNodeArray = []
enqueteNodeArray = [] enqueteNodeArray = []
async def processSensorNodeData(data): async def processSensorNodeData(data, nodeID):
try: try:
mydb = dbLogin() mydb = dbLogin()
cursor = mydb.cursor() 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)" query = "INSERT INTO `Measurement` (NodeID, Type, Value) VALUES (%s, %s, %s)"
processedData = json.loads(data) processedData = json.loads(data)
@@ -23,18 +19,8 @@ async def processSensorNodeData(data):
processedeCO2 = (processedData['eCO2']) processedeCO2 = (processedData['eCO2'])
processedTVOC = (processedData['TVOC']) processedTVOC = (processedData['TVOC'])
processedMAC = (processedData['node']) processedMAC = (processedData['node'])
MACTuple = (processedMAC,)
# MACDataFetching = MACDataReading.fetchall() pushingDataArray = [(nodeID, "Temp", processedTemp), (nodeID, "Humi", processedHumi), (nodeID, "eCO2", processedeCO2), (nodeID, "TVOC", processedTVOC)]
# 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)]
for i in pushingDataArray: for i in pushingDataArray:
print(query ,i) print(query ,i)
cursor.execute(query, i) cursor.execute(query, i)
@@ -46,9 +32,30 @@ async def processSensorNodeData(data):
cursor.close() cursor.close()
mydb.close() mydb.close()
async def processEnqueteNodeData(data, nodeID):
try:
mydb = dbLogin()
cursor = mydb.cursor()
query = "INSERT INTO `Reply` (Result, Node_NodeID, Question_QuestionID) VALUES (%s, %s, %s)"
processedData = json.loads(data)
processedQuestionID = (processedData['QuestionID'])
processedResponse = (processedData['Response'])
pushingDataArray = [(processedResponse, nodeID, processedQuestionID)]
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(): async def receive_data():
uri = "ws://145.92.8.114/ws" uri = "ws://145.92.8.114/ws"
try: try:
async with websockets.connect(uri) as websocket: async with websockets.connect(uri) as websocket:
while True: while True:
@@ -58,7 +65,7 @@ async def receive_data():
processedData = json.loads(data) processedData = json.loads(data)
macAdress = processedData['node'] macAdress = processedData['node']
if processedData["Temp"]: if "Temp" in processedData:
type = 'sensor' type = 'sensor'
else: else:
type = 'enquete' type = 'enquete'
@@ -66,26 +73,19 @@ async def receive_data():
await getNodeInfo('sensor') await getNodeInfo('sensor')
await getNodeInfo('enquete') await getNodeInfo('enquete')
print(str(sensorNodeArray)) print(sensorNodeArray)
if str(macAdress) in sensorNodeArray: if macAdress in sensorNodeArray:
await processSensorNodeData(data) nodeID = await getNodeID(macAdress)
elif str(macAdress) in enqueteNodeArray: await processSensorNodeData(data, nodeID)
await processEnqueteNodeData(data) elif macAdress in enqueteNodeArray:
nodeID = await getNodeID(macAdress)
await processEnqueteNodeData(data, nodeID)
else: else:
await newNode(macAdress, type) await newNode(macAdress, type)
except websockets.ConnectionClosedError as e: except websockets.ConnectionClosedError as e:
print("WebSocket connection closed:", 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(): async def main():
await receive_data() await receive_data()
@@ -100,6 +100,9 @@ def dbLogin():
return mydb return mydb
async def getNodeInfo(type): async def getNodeInfo(type):
global sensorNodeArray
global enqueteNodeArray
nodeInfoArray = [] nodeInfoArray = []
id = (type,) id = (type,)
@@ -113,6 +116,9 @@ async def getNodeInfo(type):
nodeInfoArray.append(item) nodeInfoArray.append(item)
print(nodeInfoArray) print(nodeInfoArray)
cursor.close()
mydb.close()
if type == 'sensor': if type == 'sensor':
sensorNodeArray = nodeInfoArray sensorNodeArray = nodeInfoArray
print(sensorNodeArray) print(sensorNodeArray)
@@ -123,8 +129,18 @@ async def getNodeInfo(type):
return enqueteNodeArray 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()
for tuples in data:
for item in tuples:
nodeID = item
return nodeID
async def newNode(mac, type): async def newNode(mac, type):
id = (mac, type,) id = (mac, type,)
@@ -136,4 +152,3 @@ async def newNode(mac, type):
mydb.commit() mydb.commit()
asyncio.run(main()) asyncio.run(main())