documentation python classes updated.
This commit is contained in:
@@ -36,8 +36,9 @@ At the start of every class the "__init__" function is called.
|
||||
For further information visit https://www.w3schools.com/python/gloss_python_class_init.asp)
|
||||
|
||||
The parent node is able to be further evolved, but for now is able do always provide the node ID to all child-classes.
|
||||
and a variable with the MAC-addresses.
|
||||
```py
|
||||
# A general class which acts as a database connector and a node identifyer
|
||||
# A general class which acts as a database connector and a node identifier
|
||||
class Node():
|
||||
|
||||
def __init__(self, macAdress):
|
||||
@@ -48,7 +49,7 @@ The function below uses the infromation from the database to find the correspond
|
||||
|
||||
It searches inside of the database and finds a match with the given MAC-address.
|
||||
|
||||
It frist makes a connection with the database by calling the previous function, then it executes the given querry, and searches for the node ID corresponding with the inserted MAC-address.
|
||||
It first makes a connection with the database by calling the previous function, then it executes the given querry, and searches for the node ID corresponding with the inserted MAC-address.
|
||||
|
||||
After this search, it inserts that given id into the ID variable.
|
||||
```py
|
||||
|
@@ -1,7 +1,10 @@
|
||||
## Sensor Node class
|
||||
This class is made to get the info of the sensor-nodes and send this to the database.
|
||||
This is done this way to make the code more clear and readable.
|
||||
This class is made with a intention to store/transfer the data collected from the several node's that are going to be placed around school.
|
||||
|
||||
This is done to reduce confusion on what every function is meant to do.
|
||||
|
||||
This file imports the needed files/classes to function.
|
||||
Aswell as the important librarys.I
|
||||
```py
|
||||
#Import library's
|
||||
import mysql.connector
|
||||
@@ -10,9 +13,18 @@ import json
|
||||
from classes_data import Node
|
||||
from classes_data import dbLogin
|
||||
```
|
||||
The class then (being a child class) creates a private query.
|
||||
This is done this way because no other files need this query so it is only logical to private this.
|
||||
|
||||
After this the "__init__"function is called.
|
||||
(In javascript this is known as the "constructor".
|
||||
For further information visit https://www.w3schools.com/python/gloss_python_class_init.asp)
|
||||
|
||||
The "__init__" here makes variables for all the data the node needs to collect and sends to the database.
|
||||
|
||||
After this a function to send the gotten data to the databse is made.
|
||||
|
||||
The function gets all the data, puts this in an array to then send it to the database according to the given query so it gets placed correctly.
|
||||
```py
|
||||
#A class to send data to the database. child class of "Node"
|
||||
class SensorNode(Node):
|
||||
@@ -26,7 +38,16 @@ class SensorNode(Node):
|
||||
self.humidity = humi
|
||||
self.eCO2 = eCO2
|
||||
self.TVOC = TVOC
|
||||
```
|
||||
The function starts with getting the database connection with the "dblogin" function and gains the the data from the websocket in the variable "processedData".
|
||||
|
||||
This data is then split up into different types, these are then inserted into an array.
|
||||
|
||||
The newly made array then gets pulled appart and the query is then combined with each segment, thereby succesfully inserting the data into it and then pushing it to the database following its guidline.
|
||||
|
||||
In case of a database error, a function is made to show said error.
|
||||
This helps with identifying problems and potentially fixing it.
|
||||
```py
|
||||
#A function to connect to the database, grab the info which is given, and push this to the database.
|
||||
async def processSensorNodeData(data, nodeID):
|
||||
try:
|
||||
|
Reference in New Issue
Block a user