diff --git a/software/backend/data_handling_functions.py b/software/backend/data_handling_functions.py index a495826..1bd1ca6 100644 --- a/software/backend/data_handling_functions.py +++ b/software/backend/data_handling_functions.py @@ -3,4 +3,75 @@ 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 -""" \ No newline at end of file +""" +import paho.mqtt.client as mqtt + + +def data_handler(client: mqtt.Client, message) -> dict: + """ + main entrypoint for a message handling method + :param client: + :param message: + :return: + """ + if message.topic.startwith('BackEnd'): + + if message.topic == "BackEnd/Action/All": + action_all(client, message) + elif message.topic == "BackEnd/Action/GetPosition": + action_get_position(client, message) + elif message.topic == "BackEnd/Action/GetBattery": + action_get_battery(client, message) + elif message.topic == "BackEnd/Action/GetAllData": + action_get_all_data(client, message) + + elif message.topic.startwith('Robot'): + + if message.topic == "Robot/Data/SensorData": + data_sensordata(client, message) + elif message.topic == "Robot/Data/Position": + data_position(client, message) + elif message.topic == "Robot/Data/Battery": + data_battery(client, message) + elif message.topic == "Robot/Data/Picture": + data_picture(client, message) + + +# START ACTION FUNCTION DEFINITIONS + +def action_all(client, message): + pass + + +def action_get_position(client, message): + pass + + +def action_get_battery(client, message): + pass + + +def action_get_all_data(client, message): + pass + + +# END ACTION FUNCTION DEFINITIONS + +# START ROBOT FUNCTION DEFINITIONS + +def data_sensordata(client, message): + pass + + +def data_position(client, message): + pass + + +def data_battery(client, message): + pass + + +def data_picture(client, message): + pass + +# END ROBOT FUNCTION DEFINITIONS diff --git a/software/backend/defines.py b/software/backend/defines.py index 2574007..947b4d6 100644 --- a/software/backend/defines.py +++ b/software/backend/defines.py @@ -4,5 +4,7 @@ created by caliskan at 19.04.2023 contains all constants for the backend architecture of the smart garden project """ -MQTT_BROKER_LOCAL = "" +MQTT_BROKER_LOCAL = "lorem ipsum" MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io" +RASPI_CLIENT_ID = "lorem ipsum" +BACKEND_CLIENT_ID = "lorem ipsum" diff --git a/software/backend/main.py b/software/backend/main.py index 40a9505..872e863 100644 --- a/software/backend/main.py +++ b/software/backend/main.py @@ -11,9 +11,12 @@ Used protocol for interaction: mqtt (paho-mqtt module) import paho.mqtt.client as mqtt from defines import MQTT_BROKER_LOCAL, MQTT_BROKER_GLOBAL from plantdatabase import PlantDataBase +from data_handling_functions import data_handler + def on_message(client, userdata, message): print(f'message received! {message.topic}') + data_handler(client, message) def on_connect(client, userdata, flags, rc): @@ -29,11 +32,10 @@ def on_connect(client, userdata, flags, rc): client.subscribe("Robot/Data/Picture") # FrontEnd topics - client.subscribe("BackEnd/Data/SensorData") - client.subscribe("BackEnd/Data/SensorDataAll") - client.subscribe("BackEnd/Data/Position") - client.subscribe("BackEnd/Data/Battery") - client.subscribe("BackEnd/Data/Picture") + client.subscribe("BackEnd/Action/All") + client.subscribe("BackEnd/Action/GetPosition") + client.subscribe("BackEnd/Action/GetBattery") + client.subscribe("BackEnd/Action/GetAllData") # END TOPIC SUBSCRIPTIONS else: