Browse Source

Minor changes

master
Luis Waldhauser 1 year ago
parent
commit
b8cb4f6217

+ 34
- 12
software/roboter/raspy/defines.py 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
"""

MQTT_BROKER_LOCAL = "lorem ipsum"
MQTT_BROKER_LOCAL = "192.168.0.199"
MQTT_BROKER_GLOBAL = "mqtt.eclipseprojects.io"
RASPI_CLIENT_ID = "smart_farming_raspi"
BACKEND_CLIENT_ID = "smart_farming_server"
@@ -21,27 +21,33 @@ Topics = {
"ROBOT_DATA_PICTURE": "ROBOT/DATA/PICTURE",

"BACKEND_ACTION_DRIVE": "BACKEND/ACTION/DRIVE",
"BACKEND_ACTION_DRIVEPALL": "BACKEND/ACTION/DRIVEALL",
"BACKEND_ACTION_GETPOSITION": "BACKEND/ACTION/GETPOSITION",
"BACKEND_ACTION_GETBATTERY": "BACKEND/ACTION/GETBATTERY",
"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_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_PICTURE": "BACKEND/DATA/PICTURE",
"BACKEND_DATA_PLANTCOUNT": "BACKEND/DATA/PLANTCOUNT",

}

}

# MQTT Messages:

# region Robot -> Backend
SENSORDATA = {
"AirTemperature": 0.0,
"AirHumidity" : 0.0,
"SoilMoisture" : 0.0,
"Brightness" : 0,
"AirHumidity": 0.0,
"SoilMoisture": 0.0,
"Brightness": 0,
"PlantID": 0,
"ActionID": 0
}
@@ -74,12 +80,13 @@ DRIVE = {

PLANTDATA = {
"AirTemperature": 0.0,
"AirHumidity" : 0.0,
"SoilMoisture" : 0.0,
"Brightness" : 0,
"AirHumidity": 0.0,
"SoilMoisture": 0.0,
"Brightness": 0,
"PlantID": 0,
"Timestamp": "",
"MeasurementID": 0
"MeasurementID": 0,
"PlantName": ""
}

ALLPLANTDATA = [
@@ -102,18 +109,33 @@ BATTERY = {
"Timestamp": ""
}

PLANTCOUNT = {
"CurrenCount": 0,
"maxCount": 0
}

# endregion

# region Frontend -> Backend

DRIVE = {
"PlantID": 0
"PlantName": ""
}

NEWPLANT = PLANTDATA

CONFIGUREPLANT = PLANTDATA

DELETEPLANT = {
"PlantID": ""
}

# DRIVEALL -> no message needed

# GETPOSITION -> no message needed

# GETBATTERY -> no message needed

# GETALLDATA -> no message needed

# endregion
# endregion

+ 12
- 15
software/roboter/raspy/functions.py View File

@@ -7,7 +7,7 @@ from defines import Topics, SENSORDATA

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:
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
"""
# 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/drive_plant.py {plantID}')
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}')

# TODO Error Message
# if errorCode != 0:
# print(f"Robot Error {errorCode} occurred")
# print("Drive Plant aborted, Robot at starting position")
# return
if errorCode != 0:
print(f"Robot Error {errorCode} occurred")
print("Drive Plant aborted, Robot at starting position")
return
print("Measuring Sensors")

#FIXME Sensor not working
measure_send_data(plantID, actionID, client)


print("Robot driving home")
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):
"""
Function to drive to plant according to request
Starting Drive in Thread
Starting Drive in Thread to not block main programm

Args:
clients (mqtt.Client): current mqtt client
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")))
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):
"""
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:
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):
"""
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%
5V -> 0%

@@ -132,7 +129,7 @@ def get_BatteryStatus(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage)

batteryLevel = round(batteryLevel / 1000000, 2) # Voltage
batteryLevel = batteryLevel - 5
batteryLevel = round(batteryLevel / 3.5, 3) *100 # Percentage
batteryLevel = round(batteryLevel / 3.5, 3) *100 # Percentage

battery = {
"Battery": batteryLevel

+ 1
- 6
software/roboter/raspy/mainProg.py View File

@@ -10,7 +10,6 @@ Interaction with the EV3 via SSH

import paho.mqtt.client as mqtt
import functions

from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL


@@ -26,7 +25,7 @@ def on_connect(client: mqtt.Client, userdata, flags, rc):
rc (_type_): _description_
"""
if rc == 0:
#Add callbacks
#Add callbacks
client.message_callback_add(Topics["ROBOT_ACTION_DRIVE"], functions.drive_plant)
client.message_callback_add(Topics["ROBOT_ACTION_GETPOSITION"], functions.get_position)
client.message_callback_add(Topics["ROBOT_ACTION_GETBATTERY"], functions.get_BatteryStatus)
@@ -54,12 +53,8 @@ def main():

print("Starting Loop")
while True:
# print("Looping")
# time.sleep(1)
pass




if __name__ == "__main__":
main()

+ 3
- 14
software/roboter/raspy/raspy_sensors.py View File

@@ -14,8 +14,8 @@ def readDHT22():
Exception: If DHT22 not connected properly

Returns:
float: air temperature in °C
float: air humidity %
float: temperature [°C]
float: humidity [%]
"""
try:
dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
@@ -40,7 +40,7 @@ def readTSL2561():
Exception: If TSL2561 not connected properly

Returns:
int: brightness in Lux
int: brightness [Lux]
"""
try:
tsl2561 = adafruit_tsl2561.TSL2561(board.I2C())
@@ -118,14 +118,3 @@ def readPosition():
"""
position = ""
return position


# for Testing only
def main():
sensors = RaspySensors()
test = sensors.readSensors()
print("Data:" + json.dumps(test))


if __name__ == "__main__":
main()

Loading…
Cancel
Save