-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayIPAddress.py
60 lines (51 loc) · 1.84 KB
/
displayIPAddress.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
#!/usr/bin/python
# -*- coding:utf-8 -*-
import epd2in13
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
import socket
import datetime
def tryGetIPAddress():
try:
return socket.gethostbyname(socket.gethostname() + ".local")
except:
return 0
try:
epd = epd2in13.EPD()
epd.init(epd.lut_full_update)
# Define fonts
font18 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 18)
font24 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMono.ttf', 24)
fontbold24 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24)
# Waiting for IP-Address
if not tryGetIPAddress():
# Drawing warning
image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame
draw = ImageDraw.Draw(image)
draw.text((10, 20), "No IP-Address :(", font = font24, fill = 0)
draw.text((10, 50), "Plugin Ethernet", font = fontbold24, fill = 0)
draw.text((10, 80), "Cable...!", font = fontbold24, fill = 0)
epd.display(epd.getbuffer(image.rotate(180)))
epd.sleep()
while not tryGetIPAddress():
time.sleep(10)
# Collect informations
host_name = socket.gethostname()
host_ip = tryGetIPAddress()
date_time = str(datetime.datetime.now())[:19]
# Drawing informations on diplay
try:
image = Image.open('/home/pi/.config/autostart/train.bmp')
except:
image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame
draw = ImageDraw.Draw(image)
draw.text((10, 10), "Hostname/IP:", font = font24, fill = 0)
draw.text((10, 35), host_name, font = fontbold24, fill = 0)
draw.text((10, 65), host_ip, font = fontbold24, fill = 0)
draw.text((10, 95), date_time, font = font18, fill = 0)
epd.display(epd.getbuffer(image.rotate(180)))
epd.sleep()
except:
print( 'traceback.format_exc():\n%s',traceback.format_exc())
exit()