-
Notifications
You must be signed in to change notification settings - Fork 0
/
displayWifiStatus.py
executable file
·60 lines (44 loc) · 2.04 KB
/
displayWifiStatus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
# -*- coding:utf-8 -*-
import epd2in13b
import time
import os
from PIL import Image,ImageDraw,ImageFont
import traceback
try:
epd = epd2in13b.EPD()
epd.init()
print("Clear...")
epd.Clear()
print("Drawing")
# Drawing on the Vertical image
HBlackimage = Image.new('1', (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH), 255) # 298*126
HYellowimage = Image.new('1', (epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH), 255) # 298*126
drawblack = ImageDraw.Draw(HBlackimage)
drawyellow = ImageDraw.Draw(HYellowimage)
font1 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSansBold.ttf', 18)
font2 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSerif.ttf', 18)
font3 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBoldOblique.ttf', 25)
# Left line
drawyellow.rectangle((0, 0, 2, epd2in13b.EPD_WIDTH), fill = 0)
# Top Line
drawyellow.rectangle((0, 0, epd2in13b.EPD_HEIGHT, 2), fill = 0)
host = os.popen('hostname').read()
drawblack.text((2, 2), 'SBC:', font = font1, fill = 0)
drawblack.text((80, 2), host, font = font2, fill = 0)
drawyellow.rectangle((0, 20, epd2in13b.EPD_HEIGHT, 22), fill = 0)
wifi = os.popen("nmcli -t -f active,ssid dev wifi | grep '^yes' | cut -d: -f2").read()
drawblack.text((2, 22), 'Wifi:', font = font1, fill = 0)
drawblack.text((80, 22), wifi, font = font2, fill = 0)
drawyellow.rectangle((0, 40, epd2in13b.EPD_HEIGHT, 42), fill = 0)
ipAddress = os.popen("hostname -I").read()
drawblack.text((2, 42), 'IP:', font = font1, fill = 0)
drawblack.text((80, 42), ipAddress, font = font2, fill = 0)
drawyellow.rectangle((0, 60, epd2in13b.EPD_HEIGHT, epd2in13b.EPD_WIDTH), fill = 0)
drawyellow.text((30, 68), 'Lancaster', font = font3, fill = 1)
epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HYellowimage))
time.sleep(2)
epd.sleep()
except:
print('traceback.format_exc():\n%s',traceback.format_exc())
exit()