Add processEnqueteNodeData function to handle enquete node data
This commit is contained in:
@@ -32,9 +32,32 @@ async def processSensorNodeData(data, nodeID):
|
||||
cursor.close()
|
||||
mydb.close()
|
||||
|
||||
async def processEnqueteNodeData(data, nodeID):
|
||||
try:
|
||||
mydb = dbLogin()
|
||||
cursor = mydb.cursor()
|
||||
|
||||
query = "INSERT INTO `Response` (Node_NodeID, Question_QuestionID, Response) VALUES (%s, %s, %s)"
|
||||
processedData = json.loads(data)
|
||||
|
||||
processedQuestionID = (processedData['QuestionID'])
|
||||
processedResponse = (processedData['Response'])
|
||||
|
||||
pushingDataArray = [(nodeID, processedQuestionID, processedResponse)]
|
||||
|
||||
for i in pushingDataArray:
|
||||
cursor.execute(query, i)
|
||||
mydb.commit()
|
||||
except mysql.connector.Error as err:
|
||||
print("MySQL Error:", err)
|
||||
finally:
|
||||
cursor.close()
|
||||
mydb.close()
|
||||
|
||||
|
||||
|
||||
async def receive_data():
|
||||
uri = "ws://145.92.8.114/ws"
|
||||
|
||||
try:
|
||||
async with websockets.connect(uri) as websocket:
|
||||
while True:
|
||||
@@ -44,12 +67,7 @@ async def receive_data():
|
||||
processedData = json.loads(data)
|
||||
macAdress = processedData['node']
|
||||
|
||||
if processedData["Temp"]:
|
||||
type = 'sensor'
|
||||
else:
|
||||
type = 'enquete'
|
||||
|
||||
|
||||
type = await getNodeType(macAdress)
|
||||
|
||||
await getNodeInfo('sensor')
|
||||
await getNodeInfo('enquete')
|
||||
@@ -67,15 +85,6 @@ async def receive_data():
|
||||
except websockets.ConnectionClosedError as e:
|
||||
print("WebSocket connection closed:", e)
|
||||
|
||||
async def processEnqueteNodeData(data):
|
||||
mydb = dbLogin()
|
||||
cursor = mydb.cursor()
|
||||
|
||||
query = "INSERT INTO `Response` (NodeID, QuestionID, Response) VALUES (%s, %s, %s)"
|
||||
processedData = json.loads(data)
|
||||
|
||||
|
||||
|
||||
async def main():
|
||||
await receive_data()
|
||||
|
||||
@@ -130,8 +139,16 @@ async def getNodeID(macAdress):
|
||||
|
||||
return nodeID
|
||||
|
||||
async def getNodeType(macAdress):
|
||||
id = (macAdress,)
|
||||
mydb = dbLogin()
|
||||
cursor = mydb.cursor()
|
||||
cursor.execute("""SELECT Type FROM Node WHERE MAC = %s""", id)
|
||||
data = cursor.fetchall()
|
||||
|
||||
Type = data[0][0]
|
||||
|
||||
return Type
|
||||
|
||||
async def newNode(mac, type):
|
||||
id = (mac, type,)
|
||||
|
Reference in New Issue
Block a user