|
|
@@ -96,23 +96,34 @@ def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
clients.publish(Topics["ROBOT_DATA_POSITION"], json.dumps(position, indent=4)) |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
Function to read battery status from ev3 and send via MQTT |
|
|
|
8,5V -> 100% |
|
|
|
5V -> 0% |
|
|
|
|
|
|
|
Args: |
|
|
|
clients (mqtt.Client): current mqtt client |
|
|
|
userdata (_type_): _description_ |
|
|
|
message (mqtt.MQTTMessage): received message |
|
|
|
""" |
|
|
|
print("Received battery status request") |
|
|
|
|
|
|
|
try: |
|
|
|
batteryLevel = int(os.popen('sshpass -p maker ssh robot@ev3dev.local cat /sys/devices/platform/battery/power_supply/lego-ev3-battery/voltage_now').read()) |
|
|
|
except: |
|
|
|
print("Robot not connected") |
|
|
|
#TODO Error Message |
|
|
|
return |
|
|
|
|
|
|
|
batteryLevel = round(batteryLevel / 1000000, 2) # Voltage |
|
|
|
batteryLevel = batteryLevel - 5 |
|
|
|
batteryLevel = round(batteryLevel / 3.5, 3) *100 # Percentage |
|
|
|
|
|
|
|
battery = { |
|
|
|
"Battery": 0.0 |
|
|
|
"Battery": batteryLevel |
|
|
|
} |
|
|
|
|
|
|
|
#TODO read Battery |
|
|
|
clients.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4)) |
|
|
|
|
|
|
|
|
|
|
|
#endregion |