diff --git a/server/web-data-connection/datatransfer.md b/server/web-data-connection/datatransfer.md index d1f9547..0304d65 100644 --- a/server/web-data-connection/datatransfer.md +++ b/server/web-data-connection/datatransfer.md @@ -43,7 +43,7 @@ async def receive_data(): await getNodeInfo('sensor') await getNodeInfo('enquete') - #get the node id and use it in functions seperate from this file. + #Get the node id and use it in functions seperate from this file. if macAdress in sensorNodeArray: nodeID = await getNodeID(macAdress) await SensorNode.processSensorNodeData(data, nodeID) @@ -52,23 +52,23 @@ async def receive_data(): await EnqueteNode.processEnqueteNodeData(data, nodeID) else: await newNode(macAdress, type) - # error message if smth went wrong + # Error message if smth went wrong except websockets.ConnectionClosedError as e: print("WebSocket connection closed:", e) -#wait for data to come in. +#Wait for data to come in. async def main(): await receive_data() ``` Here we have a case of python's scoping, it couldn't read the variables correctly and by making them global the variables were now available for all functions. ```py -#by python's scuffed we had to use global variables. +#By python's scuffed we had to use global variables. async def getNodeInfo(type): print("getNodeINfo") global sensorNodeArray global enqueteNodeArray - #new array which is needed. + #New array which is needed. nodeInfoArray = [] id = (type,) @@ -77,7 +77,7 @@ async def getNodeInfo(type): cursor.execute("""SELECT MAC FROM Node WHERE Type = %s""", id) nodeInfo = cursor.fetchall() - #go along each tuple in nodeinfo and each item in tuple, append(item) + #Go along each tuple in nodeinfo and each item in tuple, append(item) for tuples in nodeInfo: for item in tuples: nodeInfoArray.append(item) @@ -85,12 +85,12 @@ async def getNodeInfo(type): cursor.close() mydb.close() - #if the type is a sensor do this, + #If the type is a sensor do this, if type == 'sensor': sensorNodeArray = nodeInfoArray return sensorNodeArray - #else, this if statement + #Else, this if statement elif type == 'enquete': enqueteNodeArray = nodeInfoArray return enqueteNodeArray @@ -99,13 +99,13 @@ Here the database gets hinted to gain info of the existing nodes and find their ```py async def getNodeID(macAdress): id = (macAdress,) - #the db login is on a different page. + #The db login is on a different page. mydb = dbLogin() cursor = mydb.cursor() cursor.execute("""SELECT nodeID FROM Node WHERE MAC = %s""", id) data = cursor.fetchall() - #again, all tuples in data, all items for all tuples, nodeID + #Again, all tuples in data, all items for all tuples, nodeID for tuples in data: for item in tuples: nodeID = item diff --git a/server/web-data-connection/enqueteClassFile.md b/server/web-data-connection/enqueteClassFile.md index 7ab0c54..a89eb58 100644 --- a/server/web-data-connection/enqueteClassFile.md +++ b/server/web-data-connection/enqueteClassFile.md @@ -5,7 +5,7 @@ This is done this way to make the code more visable and more clear. #Importing different librarys. import mysql.connector import json -#importing different classes. +#Importing different classes. from classes_data import Node from classes_data import dbLogin ``` @@ -32,10 +32,10 @@ class EnqueteNode(Node): EnqueteNode.questionID = (processedData['QuestionID']) EnqueteNode.response = (processedData['Response']) - #an array with the data to push. + #An array with the data to push. pushingDataArray = [(EnqueteNode.questionID, nodeID, EnqueteNode.response)] - #push the data according to the query to the database. + #Push the data according to the query to the database. for i in pushingDataArray: print(EnqueteNode.__query, i) cursor.execute(EnqueteNode.__query, i) diff --git a/server/web-data-connection/generalDatabaseFile.md b/server/web-data-connection/generalDatabaseFile.md index 81e7c49..c82813d 100644 --- a/server/web-data-connection/generalDatabaseFile.md +++ b/server/web-data-connection/generalDatabaseFile.md @@ -2,7 +2,7 @@ The general node file includes the database connecting and a node connection class. This is done so the files don't go back and forth with the db connection, this otherwise would have caused problems. ```py -#importing a database library to connect to the database. +#Importing a database library to connect to the database. import mysql.connector def dbLogin(): @@ -15,7 +15,7 @@ def dbLogin(): return mydb # A general class which acts as a database connector and a node identifyer class Node(): - + def __init__(self, macAdress): self.macAdress = macAdress self.id = None @@ -26,7 +26,7 @@ class Node(): cursor = mydb.cursor() cursor.execute("""SELECT nodeID FROM Node WHERE MAC = %s""", id) data = cursor.fetchall() - #again go along all tuple items. and asign them to the ID + #Again go along all tuple items. and asign them to the ID for tuples in data: for item in tuples: self.id = item diff --git a/server/web-data-connection/sensorNodeClassFile.md b/server/web-data-connection/sensorNodeClassFile.md index f4d7fc9..db8f197 100644 --- a/server/web-data-connection/sensorNodeClassFile.md +++ b/server/web-data-connection/sensorNodeClassFile.md @@ -14,7 +14,7 @@ class SensorNode(Node): #A private query only to be used in this class. __query = "INSERT INTO `Measurement` (NodeID, Type, Value) VALUES (%s, %s, %s)" - #all variables to be used. + #All variables to be used. def __init__(self, macAdress, temp, humi, eCO2, TVOC): super().__init__(macAdress) self.temperature = temp @@ -22,7 +22,7 @@ class SensorNode(Node): self.eCO2 = eCO2 self.TVOC = TVOC - #a function to connect to the database, grab the info which is given, and push this to the database. + #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: mydb = dbLogin()