Robot Docu extended and main to mainProg added
This commit is contained in:
parent
bbc895c7dd
commit
f29e567f07
Binary file not shown.
@ -4,6 +4,7 @@ from raspySensors import RaspySensors
|
||||
|
||||
#region global Varaibles
|
||||
sensors = RaspySensors()
|
||||
client = mqtt.Client()
|
||||
|
||||
sensorData = {
|
||||
"Air Temperature [°C]" : 0,
|
||||
@ -27,9 +28,9 @@ batteryStatus = {
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
#region global functions
|
||||
|
||||
def measureSendData(plantID, actionID):
|
||||
def measure_send_data(plantID, actionID):
|
||||
'''Measure data for one plant via sensor class and send via MQTT'''
|
||||
sensorData = sensors.readSensors()
|
||||
sensorData["Plant_ID"] = plantID
|
||||
@ -37,6 +38,26 @@ def measureSendData(plantID, actionID):
|
||||
client.publish("Robot/Data/SensorData", json.dumps(sensorData, indent=4))
|
||||
|
||||
|
||||
def init_mqtt():
|
||||
'''Initialise MQTT client'''
|
||||
mqttBroker = "mqtt.eclipseprojects.io"
|
||||
client = mqtt.Client("Robot")
|
||||
|
||||
#Add callbacks
|
||||
client.message_callback_add("Robot/Data", send_data_json) #Testing
|
||||
client.message_callback_add("Robot/Action/Drive", drive_plant)
|
||||
client.message_callback_add("Robot/Action/GetPosition", get_position)
|
||||
client.message_callback_add("Robot/Action/GetBattery", get_BatteryStatus)
|
||||
|
||||
#Subscribe to topics
|
||||
client.subscribe("Robot/Data") #Testing
|
||||
client.subscribe("Robot/Action/Drive")
|
||||
client.subscribe("Robot/Action/GetPosition")
|
||||
client.subscribe("Robot/Action/GetBattery")
|
||||
|
||||
client.connect(mqttBroker)
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region MQTT callbacks
|
||||
@ -56,12 +77,12 @@ def drive_plant(clients, userdata, message):
|
||||
#[ ]TODO Start drive forward -> Thread
|
||||
|
||||
print(f"Measuring data at Plant {message}")
|
||||
measureSendData() # With threads not here
|
||||
measure_send_data() # With Signal not here
|
||||
|
||||
print("Driving back to start position")
|
||||
#[ ]TODO Start Drive Back Function in Thread
|
||||
|
||||
print("Back at starting Position")
|
||||
print("Back at starting Position") #Signal
|
||||
|
||||
|
||||
def get_position(clients, userdata, message):
|
||||
@ -74,8 +95,8 @@ def get_position(clients, userdata, message):
|
||||
client.publish("Robot/Data/Position", json.dumps(gpsPosition, indent=4))
|
||||
|
||||
|
||||
|
||||
def get_BatteryStatus(clients, userdata, message):
|
||||
|
||||
'''Callback function for battery status request
|
||||
Function to read battery status from ev3 and send via MQTT'''
|
||||
|
||||
@ -91,23 +112,18 @@ def get_BatteryStatus(clients, userdata, message):
|
||||
#endregion
|
||||
|
||||
|
||||
mqttBroker = "mqtt.eclipseprojects.io"
|
||||
client = mqtt.Client("Robot")
|
||||
|
||||
def main():
|
||||
init_mqtt()
|
||||
dataDict = {} #Testing
|
||||
|
||||
#Add callbacks
|
||||
client.message_callback_add("Robot/Data", send_data_json) #Testing
|
||||
client.message_callback_add("Robot/Action/Drive", drive_plant)
|
||||
client.message_callback_add("Robot/Action/GetPosition", get_position)
|
||||
client.message_callback_add("Robot/Action/GetBattery", get_BatteryStatus)
|
||||
client.loop_start()
|
||||
|
||||
client.connect(mqttBroker)
|
||||
while True:
|
||||
pass
|
||||
|
||||
#Subscribe to topics
|
||||
client.subscribe("Robot/Data") #Testing
|
||||
client.subscribe("Robot/Action/Drive")
|
||||
client.subscribe("Robot/Action/GetPosition")
|
||||
client.subscribe("Robot/Action/GetBattery")
|
||||
|
||||
client.loop_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user