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:
@@ -62,6 +62,7 @@ namespace User {
|
||||
+Settings
|
||||
GetData()
|
||||
}
|
||||
|
||||
class EnqueteNode {
|
||||
+Co2
|
||||
+Temperature
|
||||
|
@@ -5,9 +5,12 @@ The data we collected originated from live "nodes" which were small boxes equipp
|
||||
|
||||
This collected data needed to be transmitted to a database to facilitate its presentation on a website we were developing. The website would retrieve the data from the database and display it in various formats.
|
||||
|
||||
Given the critical nature of this data connection for our project, it was imperative that it functioned reliably. Bram was tasked with designing a connection in Python between the WebSocket (live server) and the database (data storage).
|
||||
This is what the connection would be inserted.
|
||||

|
||||
|
||||
Since we had the WebSocket data on a Raspberry Pi, it made sense to implement the connection on the Pi itself. This presented an opportunity for Bram to acquire knowledge about Python, considering he initially lacked experience with this programming language.
|
||||
Given the high demand of this data connection for our project, it was imprtant that it was reliably. Bram was given the task to designing a connection in Python between the WebSocket (live server) and the database (data storage).
|
||||
|
||||
Since we had the WebSocket data on a Raspberry Pi, it made sense to make the connection on the Pi itself. This became an opportunity for Bram to gain knowledge about Python, considering he originaly didn't have experience with this programming language.
|
||||
## Python code + explaination
|
||||
In the given Raspberry Pi, a file named "data.py" was created, from which this script could be called when needed.
|
||||
|
||||
@@ -68,7 +71,6 @@ The MAC address is then taken and turned into a tuple. This is done because the
|
||||
#make a tuple of the MAC by placing a comma.
|
||||
MACTuple = (processedMAC,)
|
||||
```
|
||||
|
||||
Coming back to the previous lines of code, the data which was first asked for is now gathered and put into an array.
|
||||
|
||||
This array is then examined, and all the data is compared to the newly obtained MAC address.
|
||||
|
BIN
docs/rpi-documentation/MyConnection.png
Normal file
BIN
docs/rpi-documentation/MyConnection.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
@@ -73,7 +73,7 @@ async def main():
|
||||
The following function is made to set the different node types appart, this is done by putting down these global variables.
|
||||
These variables are doen this way because the python-scope could not reach inside some parts of the files.
|
||||
|
||||
A bit further a array is made to holde the node info. this is so the information of the node can be sepperated and held.
|
||||
A bit further a array is made to holde the node info. this is done so the information of the node can be sepperated and held.
|
||||
|
||||
After the array, a type tuple is made. (A tuple is a type of info which acts in a way like a array. For more info visit https://www.w3schools.com/python/python_tuples.asp)
|
||||
|
||||
@@ -81,7 +81,7 @@ Then another connection to the database is made to gather all existing mac-addre
|
||||
|
||||
Then a for-loop is made to see if the incomming MAC is existing, if this isn't the case, add it to the array.
|
||||
|
||||
After, if the given type from the previous function is a sensor-, or questionaire-node
|
||||
After, if the given type from the previous function is a sensor- or questionaire-node it sends the infromation to the given function. These are located inside of the classes.
|
||||
```py
|
||||
#By python's scuffed we had to use global variables.
|
||||
async def getNodeInfo(type):
|
||||
@@ -120,7 +120,7 @@ async def getNodeInfo(type):
|
||||
```
|
||||
The next function acts as a node ID fetcher, it searches the database for information regarding the nodeID's.
|
||||
|
||||
Like the previous function, It adds the new ID id this is not yet existent.
|
||||
Like the previous function, It adds the new ID id if this is not yet existent.
|
||||
```py
|
||||
async def getNodeID(macAdress):
|
||||
id = (macAdress,)
|
||||
|
@@ -4,11 +4,10 @@ This File and class are dedicated to storing/using data that is related to the q
|
||||
By doing this a lot of space is saved on the main file and the readability wil increase.
|
||||
|
||||
By doing this, it also solves the issues with the very precise naming and the often similar types of names.
|
||||
This way it ensures no confusion on what the purpous of each segement is.
|
||||
|
||||
First up this page imports different types of information, like the library's and the needed files and/or Node.
|
||||
|
||||
This way it ensures that there is no confusion on what the
|
||||
purpose of each segement is.
|
||||
|
||||
First up on this page it imports different types of information, like the library's and the needed files and/or Node.
|
||||
```py
|
||||
#Importing different librarys.
|
||||
import mysql.connector
|
||||
@@ -49,7 +48,7 @@ It then creates variables with the data to put it in an array.
|
||||
|
||||
This array then gets sorted and pushed thogether with the query to correctly sort it and push it to the database.
|
||||
|
||||
In case of an error, it also asks for errors and prints it.
|
||||
In case of an error, it also asks for the error and prints it for more clear fixing.
|
||||
```py
|
||||
#making a database connection to then load in the processed data.
|
||||
async def processEnqueteNodeData(data, nodeID):
|
||||
@@ -76,6 +75,5 @@ In case of an error, it also asks for errors and prints it.
|
||||
cursor.close()
|
||||
mydb.close()
|
||||
```
|
||||
|
||||
### code
|
||||
https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59/-/blob/main/server/web-data-connection/enqueteNodeClass.py
|
||||
|
@@ -1,6 +1,6 @@
|
||||
## General node file.
|
||||
This File includes several main (verry important) components:
|
||||
The Node parent class and the database log- function.
|
||||
The Node parent class and the database log-in function.
|
||||
|
||||
The database funcion is used in almost every class and almost every function, so I put it here in a centeral location.
|
||||
|
||||
|
Reference in New Issue
Block a user