forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatusDisplay.py
executable file
·58 lines (47 loc) · 2.08 KB
/
statusDisplay.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
import paho.mqtt.client as mqtt
from PIL import Image, ImageDraw, ImageFont
from subprocess import call
# fbi requires three images to work with in order to force no-cache of the files.
# Let's initialise three images...
call(["cp", "/home/pi/splash.jpg", "/mnt/ramdisk/status1.jpg"])
call(["cp", "/home/pi/splash.jpg", "/mnt/ramdisk/status2.jpg"])
call(["cp", "/home/pi/splash.jpg", "/mnt/ramdisk/status3.jpg"])
call(["/bin/bash", "/home/pi/displayImg.sh"])
lrtemp = 0
lrhumid = 0
gatemp = 0
gahumid = 0;
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
client.subscribe("ESP8266/#")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
global lrtemp, lrhumid, gatemp, gahumid
if(msg.topic == "ESP8266/lounge/temperature"):
lrtemp = msg.payload
if(msg.topic == "ESP8266/lounge/humidity"):
lrhumid = msg.payload
if(msg.topic == "ESP8266/garage/temperature"):
gatemp = msg.payload
if(msg.topic == "ESP8266/garage/humidity"):
gahumid = msg.payload
image = Image.new('RGB',(800,480))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("SegoeWP.ttf",48)
draw.text((20,50), 'Lounge Temp', font=font, fill=(0,0,255))
draw.text((20,100), str(lrtemp), font=font, fill=(255,0,0))
draw.text((20,150), 'Lounge Humidity', font=font, fill=(0,0,255))
draw.text((20,200), str(lrhumid), font=font, fill=(255,0,0))
draw.text((20,250), 'Garage Temp', font=font, fill=(0,0,255))
draw.text((20,300), str(gatemp), font=font, fill=(255,0,0))
draw.text((20,350), 'Garage Humidity', font=font, fill=(0,0,255))
draw.text((20,400), str(gahumid), font=font, fill=(255,0,0))
# and then save the image out to the three files.
image.save("/mnt/ramdisk/status1.jpg")
image.save("/mnt/ramdisk/status2.jpg")
image.save("/mnt/ramdisk/status3.jpg")
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("mqtt.fqdn", 1883, 60)
client.loop_forever()