diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml index bb0672d..029b449 100644 --- a/pwnagotchi/defaults.yml +++ b/pwnagotchi/defaults.yml @@ -116,6 +116,9 @@ main: enabled: false session-stats: enabled: true + ups_lite: + enabled: false + shutdown: 2 # Auto-shutdown when <= 2% # monitor interface to use iface: mon0 # command to run to bring the mon interface up in case it's not up already diff --git a/pwnagotchi/plugins/default/ups_lite.py b/pwnagotchi/plugins/default/ups_lite.py index ba86412..482472f 100644 --- a/pwnagotchi/plugins/default/ups_lite.py +++ b/pwnagotchi/plugins/default/ups_lite.py @@ -7,12 +7,14 @@ # 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.aliexpress.com/item/32888533624.html +import logging import struct from pwnagotchi.ui.components import LabeledValue from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins +import pwnagotchi # 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') 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()