EV3 battery status added
This commit is contained in:
parent
830d662e08
commit
20bad535eb
@ -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))
|
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
|
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
|
||||||
|
8,5V -> 100%
|
||||||
|
5V -> 0%
|
||||||
|
|
||||||
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 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 = {
|
||||||
"Battery": 0.0
|
"Battery": batteryLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO read Battery
|
|
||||||
clients.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4))
|
clients.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4))
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
@ -16,7 +16,7 @@ class RaspySensors:
|
|||||||
"""
|
"""
|
||||||
Init all Sensors
|
Init all Sensors
|
||||||
"""
|
"""
|
||||||
#[ ]TODO Message if Error
|
#TODO Message if Error
|
||||||
|
|
||||||
|
|
||||||
#Air Temperature & Humidity
|
#Air Temperature & Humidity
|
||||||
@ -83,17 +83,6 @@ class RaspySensors:
|
|||||||
"""
|
"""
|
||||||
return self.position
|
return self.position
|
||||||
|
|
||||||
#TODO - read battery from EV3
|
|
||||||
def readBattery(self):
|
|
||||||
"""
|
|
||||||
Read and return battery of ev3
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
_type_: _description_
|
|
||||||
"""
|
|
||||||
return self.battery
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#for Testing only
|
#for Testing only
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user