Get current battery state (device.battery_state)
Declaration
state = device.battery_state()
Returns
- state
String, battery charging state
"Full" when connected to power and fully charged
"Charging" when connected and charging
"Unplugged" when not connected to power
"Unknown" when state is unknown
Example
local mapping = {
Full = "Connected and full",
Charging = "Connected and charging",
Unplugged = "Not connected",
Unknown = "Unknown",
}
sys.alert("Battery state: " .. mapping[device.battery_state()])
Note: Uses function outside this chapter sys.alert