123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import time
- import subprocess
- from board import SCL, SDA
- import busio
- from PIL import Image, ImageDraw, ImageFont
- import adafruit_ssd1306
- i2c = busio.I2C(SCL, SDA)
- disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
- disp.fill(0)
- disp.show()
- width = disp.width
- height = disp.height
- image = Image.new("1", (width, height))
- draw = ImageDraw.Draw(image)
- draw.rectangle((0, 0, width, height), outline=0, fill=0)
- padding = -2
- top = padding
- bottom = height - padding
- x = 0
- font = ImageFont.load_default()
- while True:
-
- draw.rectangle((0, 0, width, height), outline=0, fill=0)
-
-
- cmd = "hostname -I | cut -f 1 -d ' '"
- IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
- cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
- CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
- cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'"
- MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
- cmd = 'df -h | awk \'$NF=="/"{printf "Disk: %d/%d GB %s", $3,$2,$5}\''
- Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")
-
- cmd ="vcgencmd measure_temp |cut -f 2 -d '='"
- Temp = subprocess.check_output(cmd, shell = True )
-
- draw.text((x, top + 0), "IP: " + IP, font=font, fill=255)
- draw.text((x, top + 8), CPU, font=font, fill=255)
- draw.text((x, top + 16), MemUsage, font=font, fill=255)
- draw.text((x, top + 25), Disk, font=font, fill=255)
- draw.text((x, top + 34),"Temp: ", font=font, fill=255)
- draw.text((30, top + 34), Temp, font=font, fill=255)
- draw.text((20, top + 48),"Passerelle TOR", font=font, fill=255)
-
- disp.image(image)
- disp.show()
- time.sleep(0.1)
|