12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """
- created by caliskan at 19.04.2023
-
- This file contains all functions, which handle the different cases.
- Every function should return json format with the wanted data from the database
- """
- import paho.mqtt.client as mqtt
- from plantdatabase import PlantDataBase
-
-
- def data_handler(client: mqtt.Client, message: mqtt.MQTTMessage, mydatabase: PlantDataBase) -> None:
- """
- main entrypoint for a message handling method
- :param mydatabase: database with plant data
- :param client: mqtt client
- :param message: received message
- :return: None
- """
- if message.topic.startswith('Robot'):
- if message.topic == 'Robot/Action/SensorData':
- data_sensordata(client, message)
- elif message.topic == 'Robot/Action/Position':
- data_position(client, message)
- elif message.topic == 'Robot/Action/Battery':
- data_battery(client, message)
- elif message.topic.startswith('BackEnd'):
- if message.topic == 'BackEnd/Action/Drive':
- action_drive(client, message)
- elif message.topic == 'BackEnd/Action/GetPosition':
- action_getposition(client)
- elif message.topic == 'BackEnd/Action/GetBattery':
- action_getbattery(client)
- elif message.topic == 'BackEnd/Action/GetAllData':
- action_getalldata(client)
-
-
- # Robot Channel Reactions
-
- def data_sensordata(client: mqtt.Client, message: mqtt.MQTTMessage):
- # TODO: Store data in database
- pass
-
-
- def data_position(client: mqtt.Client, message: mqtt.MQTTMessage):
- # TODO: Publish as json
- pass
-
-
- def data_battery(client: mqtt.Client, message: mqtt.MQTTMessage):
- # TODO: Publish as json
- pass
-
-
- # FrontEnd Channel Reactions
-
- def action_drive(client: mqtt.Client, message: mqtt.MQTTMessage):
- client.publish('Robot/Action/Drive', message.payload).decode("utf-8")
-
-
- def action_getposition(client: mqtt.Client):
- client.publish('Robot/Action/GetPosition')
-
-
- def action_getbattery(client: mqtt.Client):
- client.publish('Robot/Action/GetBattery')
-
-
- def action_getalldata(client: mqtt.Client):
- # TODO: get data from database
- pass
|