repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data_handling_functions.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. created by caliskan at 19.04.2023
  3. This file contains all functions, which handle the different cases.
  4. Every function should return json format with the wanted data from the database
  5. """
  6. import paho.mqtt.client as mqtt
  7. from plantdatabase import PlantDataBase
  8. def data_handler(client: mqtt.Client, message: mqtt.MQTTMessage, mydatabase: PlantDataBase) -> None:
  9. """
  10. main entrypoint for a message handling method
  11. :param mydatabase: database with plant data
  12. :param client: mqtt client
  13. :param message: received message
  14. :return: None
  15. """
  16. if message.topic.startswith('Robot'):
  17. if message.topic == 'Robot/Action/SensorData':
  18. data_sensordata(client, message)
  19. elif message.topic == 'Robot/Action/Position':
  20. data_position(client, message)
  21. elif message.topic == 'Robot/Action/Battery':
  22. data_battery(client, message)
  23. elif message.topic.startswith('BackEnd'):
  24. if message.topic == 'BackEnd/Action/Drive':
  25. action_drive(client, message)
  26. elif message.topic == 'BackEnd/Action/GetPosition':
  27. action_getposition(client)
  28. elif message.topic == 'BackEnd/Action/GetBattery':
  29. action_getbattery(client)
  30. elif message.topic == 'BackEnd/Action/GetAllData':
  31. action_getalldata(client)
  32. # Robot Channel Reactions
  33. def data_sensordata(client: mqtt.Client, message: mqtt.MQTTMessage):
  34. # TODO: Store data in database
  35. pass
  36. def data_position(client: mqtt.Client, message: mqtt.MQTTMessage):
  37. # TODO: Publish as json
  38. pass
  39. def data_battery(client: mqtt.Client, message: mqtt.MQTTMessage):
  40. # TODO: Publish as json
  41. pass
  42. # FrontEnd Channel Reactions
  43. def action_drive(client: mqtt.Client, message: mqtt.MQTTMessage):
  44. client.publish('Robot/Action/Drive', message.payload).decode("utf-8")
  45. def action_getposition(client: mqtt.Client):
  46. client.publish('Robot/Action/GetPosition')
  47. def action_getbattery(client: mqtt.Client):
  48. client.publish('Robot/Action/GetBattery')
  49. def action_getalldata(client: mqtt.Client):
  50. # TODO: get data from database
  51. pass