@@ -115,4 +115,7 @@ dmypy.json | |||
.pyre/ | |||
# VSCode | |||
.vscode/ | |||
.vscode/ | |||
# | |||
~* |
@@ -18,27 +18,28 @@ def data_sensordata(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): | |||
def data_position(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): | |||
# TODO: Publish as json | |||
# TODO: Forward to frontend in json format | |||
pass | |||
def data_battery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): | |||
# TODO: Publish as json | |||
# TODO: Forward to frontend in json format | |||
pass | |||
# FrontEnd Channel Reactions | |||
def action_drive(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): | |||
client.publish('Robot/Action/Drive', message.payload).decode("utf-8") | |||
# TODO: ROBOT READY CHECK | |||
client.publish(Topics['ROBOT_ACTION_DRIVE'], message.payload).decode("utf-8") | |||
def action_getposition(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): | |||
client.publish('Robot/Action/GetPosition') | |||
client.publish(Topics['ROBOT_ACTION_GETPOSITION']) | |||
def action_getbattery(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): | |||
client.publish(Topics.drive) | |||
client.publish(Topics['ROBOT_ACTION_GETBATTERY']) | |||
def action_getalldata(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
@@ -34,29 +34,29 @@ def on_connect(client: mqtt.Client, userdata, flags, rc): | |||
# TOPIC SUBSCRIPTIONS | |||
# From Robot: | |||
client.subscribe(Topics['robot_data_sensordata']) | |||
client.message_callback_add(Topics['robot_data_sensordata'], data_functions.data_sensordata) | |||
client.subscribe(Topics['ROBOT_DATA_SENSORDATA']) | |||
client.message_callback_add(Topics['ROBOT_DATA_SENSORDATA'], data_functions.data_sensordata) | |||
client.subscribe(Topics['robot_data_position']) | |||
client.message_callback_add(Topics['robot_data_position'], data_functions.data_position) | |||
client.subscribe(Topics['ROBOT_DATA_POSITION']) | |||
client.message_callback_add(Topics['ROBOT_DATA_POSITION'], data_functions.data_position) | |||
client.subscribe(Topics['robot_data_battery']) | |||
client.message_callback_add(Topics['robot_data_battery'], data_functions.data_sensordata) | |||
client.subscribe(Topics['ROBOT_DATA_BATTERY']) | |||
client.message_callback_add(Topics['ROBOT_DATA_BATTERY'], data_functions.data_sensordata) | |||
# client.subscribe('Robot/Data/Picture') | |||
# From FrontEnd: | |||
client.subscribe(Topics['backend_action_drive']) | |||
client.message_callback_add(Topics['backend_action_drive'], data_functions.action_drive) | |||
client.subscribe(Topics['BACKEND_ACTION_DRIVE']) | |||
client.message_callback_add(Topics['BACKEND_ACTION_DRIVE'], data_functions.action_drive) | |||
client.subscribe(Topics['backend_action_getposition']) | |||
client.message_callback_add(Topics['backend_action_getposition'], data_functions.action_getposition) | |||
client.subscribe(Topics['BACKEND_ACTION_GETPOSITION']) | |||
client.message_callback_add(Topics['BACKEND_ACTION_GETPOSITION'], data_functions.action_getposition) | |||
client.subscribe(Topics['backend_action_getbattery']) | |||
client.message_callback_add(Topics['backend_action_getbattery'], data_functions.action_getbattery) | |||
client.subscribe(Topics['BACKEND_ACTION_GETBATTERY']) | |||
client.message_callback_add(Topics['BACKEND_ACTION_GETBATTERY'], data_functions.action_getbattery) | |||
client.subscribe(Topics['backend_action_getalldata']) | |||
client.message_callback_add(Topics['backend_action_getalldata'], data_functions.action_getalldata) | |||
client.subscribe(Topics['BACKEND_ACTION_GETALLDATA']) | |||
client.message_callback_add(Topics['BACKEND_ACTION_GETALLDATA'], data_functions.action_getalldata) | |||
# END TOPIC SUBSCRIPTIONS | |||
else: |
@@ -42,12 +42,12 @@ class PlantDataBase: | |||
def insert_measurement_data(self, plant_id, | |||
sensordata_temp, | |||
sensordata_humidity, | |||
sensordata_ground_humidity, | |||
sensordata_soil_moisture, | |||
pest_infestation, | |||
light_intensity): | |||
self.cur.execute(f"INSERT INTO measurement_values (plant_ID, sensordata_temp, sensordata_humidity," | |||
f" sensordata_soil_moisture, pest_infestation, light_intensity) VALUES " | |||
f"({plant_id}, {sensordata_temp}, {sensordata_humidity}, {sensordata_ground_humidity}, {pest_infestation}" | |||
f"({plant_id}, {sensordata_temp}, {sensordata_humidity}, {sensordata_soil_moisture}, {pest_infestation}" | |||
f", {light_intensity})") | |||
self.conn.commit() | |||
@@ -6,29 +6,29 @@ contains all constants for the backend architecture of the smart garden project | |||
MQTT_BROKER_LOCAL = "lorem ipsum" | |||
MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io" | |||
RASPI_CLIENT_ID = "lorem ipsum" | |||
BACKEND_CLIENT_ID = "lorem ipsum" | |||
RASPI_CLIENT_ID = "smart_farming_raspi" | |||
BACKEND_CLIENT_ID = "smart_farming_server" | |||
# Topics: | |||
Topics = { | |||
"robot_action_drive": "ROBOT/ACTION/DRIVE", | |||
"robot_action_getposition": "ROBOT/ACTION/GETPOSITION", | |||
"robot_action_getbattery": "ROBOT/ACTION/GETBATTERY", | |||
"ROBOT_ACTION_DRIVE": "ROBOT/ACTION/DRIVE", | |||
"ROBOT_ACTION_GETPOSITION": "ROBOT/ACTION/GETPOSITION", | |||
"ROBOT_ACTION_GETBATTERY": "ROBOT/ACTION/GETBATTERY", | |||
"robot_data_sensordata": "ROBOT/DATA/SENSORDATA", | |||
"robot_data_battery": "ROBOT/DATA/BATTERY", | |||
"robot_data_position": "ROBOT/DATA/POSITION", | |||
"robot_data_picture": "ROBOT/DATA/PICTURE", | |||
"ROBOT_DATA_SENSORDATA": "ROBOT/DATA/SENSORDATA", | |||
"ROBOT_DATA_BATTERY": "ROBOT/DATA/BATTERY", | |||
"ROBOT_DATA_POSITION": "ROBOT/DATA/POSITION", | |||
"ROBOT_DATA_PICTURE": "ROBOT/DATA/PICTURE", | |||
"backend_action_drive": "BACKEND/ACTION/DRIVE", | |||
"backend_action_getposition": "BACKEND/ACTION/GETPOSITION", | |||
"backend_action_getbattery": "BACKEND/ACTION/GETBATTERY", | |||
"backend_action_getalldata": "BACKEND/ACTION/GETALLDATA", | |||
"BACKEND_ACTION_DRIVE": "BACKEND/ACTION/DRIVE", | |||
"BACKEND_ACTION_GETPOSITION": "BACKEND/ACTION/GETPOSITION", | |||
"BACKEND_ACTION_GETBATTERY": "BACKEND/ACTION/GETBATTERY", | |||
"BACKEND_ACTION_GETALLDATA": "BACKEND/ACTION/GETALLDATA", | |||
"backend_data_sensordata": "BACKEND/DATA/SENSORDATA", | |||
"backend_data_sensordataall": "BACKEND/DATA/SENSORDATA_ALL", | |||
"backend_data_position": "BACKEND/DATA/POSITION", | |||
"backend_data_battery": "BACKEND/DATA/BATTERY", | |||
"backend_data_picture": "BACKEND/DATA/PICTURE" | |||
"BACKEND_DATA_SENSORDATA": "BACKEND/DATA/SENSORDATA", | |||
"BACKEND_DATA_SENSORDATAALL": "BACKEND/DATA/SENSORDATA_ALL", | |||
"BACKEND_DATA_POSITION": "BACKEND/DATA/POSITION", | |||
"BACKEND_DATA_BATTERY": "BACKEND/DATA/BATTERY", | |||
"BACKEND_DATA_PICTURE": "BACKEND/DATA/PICTURE" | |||
} |