function layout added
This commit is contained in:
parent
9396c59e86
commit
14fea73572
@ -4,3 +4,74 @@ created by caliskan at 19.04.2023
|
|||||||
This file contains all functions, which handle the different cases.
|
This file contains all functions, which handle the different cases.
|
||||||
Every function should return json format with the wanted data from the database
|
Every function should return json format with the wanted data from the database
|
||||||
"""
|
"""
|
||||||
|
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
|
||||||
|
@ -4,5 +4,7 @@ created by caliskan at 19.04.2023
|
|||||||
contains all constants for the backend architecture of the smart garden project
|
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"
|
MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io"
|
||||||
|
RASPI_CLIENT_ID = "lorem ipsum"
|
||||||
|
BACKEND_CLIENT_ID = "lorem ipsum"
|
||||||
|
@ -11,9 +11,12 @@ Used protocol for interaction: mqtt (paho-mqtt module)
|
|||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
from defines import MQTT_BROKER_LOCAL, MQTT_BROKER_GLOBAL
|
from defines import MQTT_BROKER_LOCAL, MQTT_BROKER_GLOBAL
|
||||||
from plantdatabase import PlantDataBase
|
from plantdatabase import PlantDataBase
|
||||||
|
from data_handling_functions import data_handler
|
||||||
|
|
||||||
|
|
||||||
def on_message(client, userdata, message):
|
def on_message(client, userdata, message):
|
||||||
print(f'message received! {message.topic}')
|
print(f'message received! {message.topic}')
|
||||||
|
data_handler(client, message)
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
@ -29,11 +32,10 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
client.subscribe("Robot/Data/Picture")
|
client.subscribe("Robot/Data/Picture")
|
||||||
|
|
||||||
# FrontEnd topics
|
# FrontEnd topics
|
||||||
client.subscribe("BackEnd/Data/SensorData")
|
client.subscribe("BackEnd/Action/All")
|
||||||
client.subscribe("BackEnd/Data/SensorDataAll")
|
client.subscribe("BackEnd/Action/GetPosition")
|
||||||
client.subscribe("BackEnd/Data/Position")
|
client.subscribe("BackEnd/Action/GetBattery")
|
||||||
client.subscribe("BackEnd/Data/Battery")
|
client.subscribe("BackEnd/Action/GetAllData")
|
||||||
client.subscribe("BackEnd/Data/Picture")
|
|
||||||
|
|
||||||
# END TOPIC SUBSCRIPTIONS
|
# END TOPIC SUBSCRIPTIONS
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user