diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml index 986d2fc2..952dcfba 100644 --- a/pwnagotchi/defaults.yml +++ b/pwnagotchi/defaults.yml @@ -70,8 +70,9 @@ main: netmask: 24 interval: 1 # check every x minutes for device share_internet: false - memtemp: # Display memory usage and cpu temperature on screen - enabled: false + memtemp: # Display memory usage, cpu load and cpu temperature on screen + enabled: false + orientation: horizontal # horizontal/vertical # 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/memtemp.py b/pwnagotchi/plugins/default/memtemp.py index b17225a3..8262791b 100644 --- a/pwnagotchi/plugins/default/memtemp.py +++ b/pwnagotchi/plugins/default/memtemp.py @@ -1,6 +1,6 @@ -# tempmem shows memory infos and cpu temperature +# memtemp shows memory infos and cpu temperature # -# totalmem usedmem freemem cputemp +# mem usage, cpu load, cpu temp # ############################################################### # @@ -10,71 +10,54 @@ # - removed the label so we wont waste screen space # - Updated version to 1.0.1 # +# 20-10-2019 by spees +# - Refactored to use the already existing functions +# - Now only shows memory usage in percentage +# - Added CPU load +# - Added horizontal and vertical orientation +# ############################################################### - __author__ = 'https://github.com/xenDE' __version__ = '1.0.1' __name__ = 'memtemp' __license__ = 'GPL3' -__description__ = 'A plugin that will add a memory and temperature indicator' +__description__ = 'A plugin that will display memory/cpu usage and temperature' -import struct from pwnagotchi.ui.components import LabeledValue from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts +import pwnagotchi +import subprocess +import logging -import time - - -class MEMTEMP: - - # set the minimum seconds before refresh the values - refresh_wait = 30 - - refresh_ts_last = time.time() - refresh_wait - - def __init__(self): - # only import when the module is loaded and enabled - import os - - def get_temp(self): - try: - temp = os.popen('/opt/vc/bin/vcgencmd measure_temp').readlines()[0].split('=')[1].replace("\n", '').replace("'","") - return 't:' + temp - except: - return 't:-' - # cpu:37.4C - - def get_mem_info(self): - try: - # includes RAM + Swap Memory: -# total, used, free = map(int, os.popen('free -t -m').readlines()[-1].split()[1:]) - # without Swap, only real memory: - total, used, free = map(int, os.popen('free -t -m').readlines()[-3].split()[1:4]) - return "\nT:"+str(total)+"M U:"+str(used)+"M\nF:"+str(free)+"M" - except: - return "\nT:- U:-\nF:- " - # tm:532 um:82 fm:353 - - -memtemp = None +OPTIONS = dict() def on_loaded(): - global memtemp - memtemp = MEMTEMP() + logging.info("memtemp plugin loaded.") + + +def mem_usage(): + return int(pwnagotchi.mem_usage() * 100) + +def cpu_load(): + return int(pwnagotchi.cpu_load() * 100) + def on_ui_setup(ui): - ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value='\nT:- U:-\nF:- -', position=(ui.width() / 2 + 17, ui.height() / 2), - label_font=fonts.Bold, text_font=fonts.Medium)) - + if OPTIONS['orientation'] == "horizontal": + ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value='mem cpu temp\n - - -', position=(ui.width() / 2 + 30, ui.height() /2 + 15), + label_font=fonts.Small, text_font=fonts.Small)) + elif OPTIONS['orientation'] == "vertical": + ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value=' mem:-\n cpu:-\ntemp:-', position=(ui.width() / 2 + 55, ui.height() /2), + label_font=fonts.Small, text_font=fonts.Small)) def on_ui_update(ui): - if time.time() > memtemp.refresh_ts_last + memtemp.refresh_wait: - ui.set('memtemp', "%s %s" % (memtemp.get_mem_info(), memtemp.get_temp())) - memtemp.refresh_ts_last = time.time() - - + if OPTIONS['orientation'] == "horizontal": + ui.set('memtemp', " mem cpu temp\n %s%% %s%% %sc" % (mem_usage(), cpu_load(), pwnagotchi.temperature())) + + elif OPTIONS['orientation'] == "vertical": + ui.set('memtemp', " mem:%s%%\n cpu:%s%%\ntemp:%sc" % (mem_usage(), cpu_load(), pwnagotchi.temperature()))