Hoofdletters update
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user