-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate for python.txt
110 lines (90 loc) · 2.37 KB
/
template for python.txt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#import the libraries
from sense_hat import SenseHat
import paho.mqtt.client as mqtt
#import time to set how often the temp will be published
import time
#set the broker url
broker="mqtt.eclipse.org"
#set the port number
port=1880
#set the topic
topic="class/topic"
sense = SenseHat()
sense.clear()
b = (0,0,255)
r = (255,0,0)
w = (255,255,255)
client= mqtt.Client("client id")
low =[
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b,
b,b,b,b,b,b,b,b
]
medium=[
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w
]
high=[
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r,
r,r,r,r,r,r,r,r
]
client.connect("localhost",1884,60)
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("class/test1")
def on_message(client, userdata, msg):
if msg.payload.decode() == "Hello":
print("Yes!")
print(msg.payload.decode())
f=open('temp.txt','a')
f.write(msg.payload.decode() + " ")
f.close()
#client.disconnect()
while True:
temp = sense.get_temperature()
t= round(temp)
if t>=45:
sense.set_pixels(high)
l= " "+str(t)
client.publish(topic,l)
client.on_connect = on_connect
client.on_message = on_message
time.sleep(5)
sense.clear()
print(l)
elif t>10:
sense.set_pixels(medium)
l= " "+str(t)
client.publish(topic,l)
client.on_connect = on_connect
client.on_message = on_message
time.sleep(5)
sense.clear()
print(l)
elif t<10:
sense.set_pixels(low)
l= " "+str(t)
client.publish(topic,l)
client.on_connect = on_connect
client.on_message = on_message
time.sleep(5)
sense.clear()
print(l)
client.loop()