Merge pull request from benallard/ups_shutdown

ups_lite: Add auto-shutdown
This commit is contained in:
Simone Margaritelli
2020-01-13 11:39:27 +01:00
committed by GitHub
2 changed files with 11 additions and 1 deletions
pwnagotchi

@ -116,6 +116,9 @@ main:
enabled: false enabled: false
session-stats: session-stats:
enabled: true enabled: true
ups_lite:
enabled: false
shutdown: 2 # Auto-shutdown when <= 2%
# monitor interface to use # monitor interface to use
iface: mon0 iface: mon0
# command to run to bring the mon interface up in case it's not up already # command to run to bring the mon interface up in case it's not up already

@ -7,12 +7,14 @@
# For Raspberry Pi Zero Ups Power Expansion Board with Integrated Serial Port S3U4 # For Raspberry Pi Zero Ups Power Expansion Board with Integrated Serial Port S3U4
# https://www.ebay.de/itm/For-Raspberry-Pi-Zero-Ups-Power-Expansion-Board-with-Integrated-Serial-Port-S3U4/323873804310 # https://www.ebay.de/itm/For-Raspberry-Pi-Zero-Ups-Power-Expansion-Board-with-Integrated-Serial-Port-S3U4/323873804310
# https://www.aliexpress.com/item/32888533624.html # https://www.aliexpress.com/item/32888533624.html
import logging
import struct import struct
from pwnagotchi.ui.components import LabeledValue from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins import pwnagotchi.plugins as plugins
import pwnagotchi
# TODO: add enable switch in config.yml an cleanup all to the best place # TODO: add enable switch in config.yml an cleanup all to the best place
@ -63,4 +65,9 @@ class UPSLite(plugins.Plugin):
ui.remove_element('ups') ui.remove_element('ups')
def on_ui_update(self, ui): def on_ui_update(self, ui):
ui.set('ups', "%2i%%" % self.ups.capacity()) capacity = self.ups.capacity()
ui.set('ups', "%2i%%" % capacity)
if capacity <= self.options['shutdown']:
logging.info('[ups_lite] Empty battery (<= %s%%): shuting down' % self.options['shutdown'])
ui.update(force=True, new_data={'status': 'Battery exhausted, bye ...'})
pwnagotchi.shutdown()