Minor changes

This commit is contained in:
Luis Waldhauser 2023-05-10 15:58:27 +02:00
parent 48a4bbe710
commit b8cb4f6217
4 changed files with 50 additions and 47 deletions

View File

@ -4,7 +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 = "lorem ipsum" MQTT_BROKER_LOCAL = "192.168.0.199"
MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io" MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io"
RASPI_CLIENT_ID = "smart_farming_raspi" RASPI_CLIENT_ID = "smart_farming_raspi"
BACKEND_CLIENT_ID = "smart_farming_server" BACKEND_CLIENT_ID = "smart_farming_server"
@ -21,19 +21,25 @@ Topics = {
"ROBOT_DATA_PICTURE": "ROBOT/DATA/PICTURE", "ROBOT_DATA_PICTURE": "ROBOT/DATA/PICTURE",
"BACKEND_ACTION_DRIVE": "BACKEND/ACTION/DRIVE", "BACKEND_ACTION_DRIVE": "BACKEND/ACTION/DRIVE",
"BACKEND_ACTION_DRIVEPALL": "BACKEND/ACTION/DRIVEALL",
"BACKEND_ACTION_GETPOSITION": "BACKEND/ACTION/GETPOSITION", "BACKEND_ACTION_GETPOSITION": "BACKEND/ACTION/GETPOSITION",
"BACKEND_ACTION_GETBATTERY": "BACKEND/ACTION/GETBATTERY", "BACKEND_ACTION_GETBATTERY": "BACKEND/ACTION/GETBATTERY",
"BACKEND_ACTION_GETALLDATA": "BACKEND/ACTION/GETALLDATA", "BACKEND_ACTION_GETALLDATA": "BACKEND/ACTION/GETALLDATA",
"BACKEND_ACTION_NEWPLANT": "BACKEND/ACTION/NEWPLANT",
"BACKEND_ACTION_CONFIGUREPLANT": "BACKEND/ACTION/CONFIGUREPLANT",
"BACKEND_ACTION_DELETEPLANT": "BACKEND/ACTION/DELETEPLANT",
"BACKEND_ACTION_PLANTCOUNT": "BACKEND/ACTION/PLANTCOUNT",
"BACKEND_DATA_SENSORDATA": "BACKEND/DATA/SENSORDATA", "BACKEND_DATA_SENSORDATA": "BACKEND/DATA/SENSORDATA",
"BACKEND_DATA_SENSORDATAALL": "BACKEND/DATA/SENSORDATA_ALL", "BACKEND_DATA_SENSORDATAALL": "BACKEND/DATA/SENSORDATA_ALL",
"BACKEND_DATA_POSITION": "BACKEND/DATA/POSITION", "BACKEND_DATA_POSITION": "BACKEND/DATA/POSITION",
"BACKEND_DATA_BATTERY": "BACKEND/DATA/BATTERY", "BACKEND_DATA_BATTERY": "BACKEND/DATA/BATTERY",
"BACKEND_DATA_PICTURE": "BACKEND/DATA/PICTURE" "BACKEND_DATA_PICTURE": "BACKEND/DATA/PICTURE",
"BACKEND_DATA_PLANTCOUNT": "BACKEND/DATA/PLANTCOUNT",
} }
# MQTT Messages: # MQTT Messages:
# region Robot -> Backend # region Robot -> Backend
@ -79,7 +85,8 @@ PLANTDATA = {
"Brightness": 0, "Brightness": 0,
"PlantID": 0, "PlantID": 0,
"Timestamp": "", "Timestamp": "",
"MeasurementID": 0 "MeasurementID": 0,
"PlantName": ""
} }
ALLPLANTDATA = [ ALLPLANTDATA = [
@ -102,14 +109,29 @@ BATTERY = {
"Timestamp": "" "Timestamp": ""
} }
PLANTCOUNT = {
"CurrenCount": 0,
"maxCount": 0
}
# endregion # endregion
# region Frontend -> Backend # region Frontend -> Backend
DRIVE = { DRIVE = {
"PlantID": 0 "PlantName": ""
} }
NEWPLANT = PLANTDATA
CONFIGUREPLANT = PLANTDATA
DELETEPLANT = {
"PlantID": ""
}
# DRIVEALL -> no message needed
# GETPOSITION -> no message needed # GETPOSITION -> no message needed
# GETBATTERY -> no message needed # GETBATTERY -> no message needed

View File

@ -7,7 +7,7 @@ from defines import Topics, SENSORDATA
def measure_send_data(plantID, actionID, client: mqtt.Client): def measure_send_data(plantID, actionID, client: mqtt.Client):
""" """
Reads all sensors and publishes data via MQTT Reads all sensors and publishes data via MQTT in form of SENSORDATA
Args: Args:
plantID (_type_): plant to measure plantID (_type_): plant to measure
@ -39,21 +39,18 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client):
client (mqtt.Client): current mqtt client for publishing client (mqtt.Client): current mqtt client for publishing
""" """
# FIXME Change to color code driving # FIXME Change to color code driving
# errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/plant_{plantID}.py') errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/plant_{plantID}.py')
# # errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plantID}') # errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plantID}')
# TODO Error Message # TODO Error Message
# if errorCode != 0: if errorCode != 0:
# print(f"Robot Error {errorCode} occurred") print(f"Robot Error {errorCode} occurred")
# print("Drive Plant aborted, Robot at starting position") print("Drive Plant aborted, Robot at starting position")
# return return
print("Measuring Sensors") print("Measuring Sensors")
#FIXME Sensor not working
measure_send_data(plantID, actionID, client) measure_send_data(plantID, actionID, client)
print("Robot driving home") print("Robot driving home")
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}')
@ -74,12 +71,12 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client):
def drive_plant(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): def drive_plant(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
""" """
Function to drive to plant according to request Function to drive to plant according to request
Starting Drive in Thread Starting Drive in Thread to not block main programm
Args: Args:
clients (mqtt.Client): current mqtt client clients (mqtt.Client): current mqtt client
userdata (_type_): _description_ userdata (_type_): _description_
message (mqtt.MQTTMessage): received message message (mqtt.MQTTMessage): received DRIVE message with PlantID and ActionID
""" """
dictMessage = json.loads(str(message.payload.decode("UTF-8"))) dictMessage = json.loads(str(message.payload.decode("UTF-8")))
plantID = dictMessage["PlantID"] plantID = dictMessage["PlantID"]
@ -94,7 +91,7 @@ def drive_plant(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
""" """
Callback function for GPS position request Callback function for GPS position request
Function to send actual GPS position via MQTT Function to send actual GPS position via MQTT in form of POSITION
Args: Args:
clients (mqtt.Client): current mqtt client clients (mqtt.Client): current mqtt client
@ -112,7 +109,7 @@ def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
def get_BatteryStatus(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): def get_BatteryStatus(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
""" """
Callback function for battery status request Callback function for battery status request
Function to read battery status from ev3 and send via MQTT Function to read battery status from ev3 and send via MQTT in form of BATTERY
8,5V -> 100% 8,5V -> 100%
5V -> 0% 5V -> 0%

View File

@ -10,7 +10,6 @@ Interaction with the EV3 via SSH
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import functions import functions
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL
@ -54,12 +53,8 @@ def main():
print("Starting Loop") print("Starting Loop")
while True: while True:
# print("Looping")
# time.sleep(1)
pass pass
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -14,8 +14,8 @@ def readDHT22():
Exception: If DHT22 not connected properly Exception: If DHT22 not connected properly
Returns: Returns:
float: air temperature in °C float: temperature [°C]
float: air humidity % float: humidity [%]
""" """
try: try:
dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False) dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
@ -40,7 +40,7 @@ def readTSL2561():
Exception: If TSL2561 not connected properly Exception: If TSL2561 not connected properly
Returns: Returns:
int: brightness in Lux int: brightness [Lux]
""" """
try: try:
tsl2561 = adafruit_tsl2561.TSL2561(board.I2C()) tsl2561 = adafruit_tsl2561.TSL2561(board.I2C())
@ -118,14 +118,3 @@ def readPosition():
""" """
position = "" position = ""
return position return position
# for Testing only
def main():
sensors = RaspySensors()
test = sensors.readSensors()
print("Data:" + json.dumps(test))
if __name__ == "__main__":
main()