# Local python packages LOCALSITEPACKAGES='/home/tc/python3.8/site-packages' # font dir/file FONTFILE='/home/tc/PixelOperator.ttf' # display size WIDTH=128 HEIGHT=64 # Display Refresh LOOPTIME = 1.0 import os, sys import subprocess import time sys.path.append(LOCALSITEPACKAGES) from luma.core.interface.serial import i2c from luma.core.render import canvas from luma.oled.device import sh1106 from PIL import Image, ImageDraw, ImageFont serial = i2c(port=1, address=0x3C) device = sh1106(serial, width=WIDTH, height=HEIGHT) device.clear() # font font = ImageFont.truetype(FONTFILE, 16) # loop while True: cmd = "ifconfig | grep Bcast | awk -F: '{print $2}' | cut -d\' \' -F1 | tr -d \'\\n\'" IP = subprocess.check_output(cmd, shell = True ) cmd = "top -bn1 | grep CPU: | grep '%' | awk 'NR==1{print \"CPU: \",$2}' | tr -d \'\\n\'" CPU = subprocess.check_output(cmd, shell = True ) cmd = "free -m | awk 'NR==2{printf \"Mem: %sMB %.1f%%\", $3,$3*100/$2 }'" MemUsage = subprocess.check_output(cmd, shell = True ) cmd = "df -m | awk '$NF==\"/\"{printf \"Disk: %d/%dMB %s\", $3,$2,$5}'" Disk = subprocess.check_output(cmd, shell = True ) cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"%.1f\", $1/1000}'" Temp = subprocess.check_output(cmd, shell = True ) with canvas(device) as draw: draw.text((0, 0), "IP: " + str(IP,'utf-8'), font=font, fill="white") draw.text((0,16), str(CPU,'utf-8'), font=font, fill="white") draw.text((80,16), str(Temp,'utf-8') + '\'C', font=font, fill="white") draw.text((0,32), str(MemUsage,'utf-8'), font=font, fill="white") draw.text((0,48), str(Disk,'utf-8'), font=font, fill="white") time.sleep(LOOPTIME)