Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59
This commit is contained in:
@@ -28,26 +28,42 @@ async def process_data(data):
|
|||||||
Then after this we code in the infromation we want to put inside of the 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.
|
The data collected from the websocket is json data, so this has to be changed.
|
||||||
```js
|
```js
|
||||||
cursor = mydb.cursor()
|
//Making a variable for the database connection
|
||||||
// the segments in wich the infromation will be sent.
|
cursor = mydb.cursor()
|
||||||
query = "INSERT INTO `Measurement` (NodeID, Type, Value) VALUES (%s, %s, %s)"
|
//Making a variable for the database connection
|
||||||
// the json data collected from the websocket gets collected and transformed into data usable by python.
|
MACDataReading = mydb.cursor()
|
||||||
mrdata = json.loads(data)
|
//find the correct section and interact with it.
|
||||||
//variables get the different types of data.
|
MACDataReading.execute("SELECT MAC FROM Node")
|
||||||
mrtemp = (mrdata['Temp'])
|
//the query for what needs to be inserted into the database ( atleast where it has to go).
|
||||||
mrhumi = (mrdata['Humi'])
|
query = "INSERT INTO `Measurement` (NodeID, Type, Value) VALUES (%s, %s, %s)"
|
||||||
mrco = (mrdata['eCO2'])
|
//the recieved data from the websocket is json data so needs to be changed.
|
||||||
mrtvoc = (mrdata['TVOC'])
|
processedData = json.loads(data)
|
||||||
mrnode = (mrdata['node'])
|
//variables about the recieved data points.
|
||||||
//an array is made to holster the different information clusters, for the time being it holds the infromation of one node.
|
processedTemp = (processedData['Temp'])
|
||||||
mrarray = [(1, "Temp", mrtemp), (1, "Humi", mrhumi), (1, "eCO2", mrco), (1, "TVOC", mrtvoc)]
|
processedHumi = (processedData['Humi'])
|
||||||
// a for statement to go trough the array.
|
processedECo = (processedData['eCO2'])
|
||||||
for i in mrarray:
|
processedTvoc = (processedData['TVOC'])
|
||||||
print(query ,i)
|
processedMAC = (processedData['node'])
|
||||||
cursor.execute(query, i)
|
//change the recieved macadress to a tuple.
|
||||||
//commit the information to the database.
|
MACTuple = (processedMAC,)
|
||||||
mydb.commit()
|
//fetch the data from the database an[d put it in an array.
|
||||||
// if the connection to the database can't be made this error wil show with further information.
|
MACDataFetching = MACDataReading.fetchall()
|
||||||
|
MACArray = list(MACDataFetching)
|
||||||
|
|
||||||
|
//see if the fetched data is not in the gotten array.
|
||||||
|
//otehrwise insert it into the database directly.
|
||||||
|
if MACTuple not in MACArray:
|
||||||
|
addingNode = "INSERT INTO `Node` (MAC) VALUES (%s)"
|
||||||
|
cursor.execute(addingNode, MACTuple)
|
||||||
|
mydb.commit()
|
||||||
|
//the websocket data that needs to be sent to the database.
|
||||||
|
pushingDataArray = [(1, "Temp", processedTemp), (1, "Humi", processedHumi), (1, "eCO2", processedECo), (1, "TVOC", processedTvoc)]
|
||||||
|
// forloop, go allong the array.
|
||||||
|
for i in pushingDataArray:
|
||||||
|
print(query ,i)
|
||||||
|
cursor.execute(query, i)
|
||||||
|
mydb.commit()
|
||||||
|
// show me the error it there is one.
|
||||||
except mysql.connector.Error as err:
|
except mysql.connector.Error as err:
|
||||||
print("MySQL Error:", err)
|
print("MySQL Error:", err)
|
||||||
finally:
|
finally:
|
||||||
|
@@ -66,4 +66,18 @@ Sam, tft scherm, rest api ombouwen om data in node tabel te douwen
|
|||||||
Dano: Adding comments for OOP Arduino
|
Dano: Adding comments for OOP Arduino
|
||||||
Bram: Python send node data to database
|
Bram: Python send node data to database
|
||||||
Sam: flask rerouten to use put recuest
|
Sam: flask rerouten to use put recuest
|
||||||
Sietse: WireFrame
|
Sietse: WireFrame
|
||||||
|
|
||||||
|
21/03/2024
|
||||||
|
|
||||||
|
Sietse: fritsing node documentation
|
||||||
|
Bram: personal documetation.
|
||||||
|
Sam: Rest api improvements
|
||||||
|
Dano: prepering for retro and making docu for aruidno
|
||||||
|
|
||||||
|
22/03/2024
|
||||||
|
|
||||||
|
Bram: Fritsing, documentation for code
|
||||||
|
Sietse: Database
|
||||||
|
Dano: Docuemtation for arduino
|
||||||
|
Sam:
|
Reference in New Issue
Block a user