-
Notifications
You must be signed in to change notification settings - Fork 5
/
mqtt.py
65 lines (53 loc) · 1.56 KB
/
mqtt.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
61
62
63
64
65
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
from m5mqtt import M5mqtt
setScreenColor(0x111111)
m5mqtt = M5mqtt('m5stick', 'io.adafruit.com', 1883, 'USER_NAME', 'YOUR_ACCESS_KEY', 300)
image0 = M5Img(0, 0, "res/humi3.jpg", True)
temperature = None
humidity = None
ticks = None
def fun_PATH_TO_TEMPERATURE_FEED_(topic_data):
global temperature, humidity, ticks
temperature = topic_data
pass
m5mqtt.subscribe(str('PATH_TO_TEMPERATURE_FEED'), fun_PATH_TO_TEMPERATURE_FEED_)
def fun_PATH_TO_HUMIDITY_FEED_(topic_data):
global temperature, humidity, ticks
humidity = topic_data
pass
m5mqtt.subscribe(str('PATH_TO_HUMIDITY_FEED'), fun_PATH_TO_HUMIDITY_FEED_)
def buttonA_wasPressed():
global temperature, humidity, ticks
axp.powerOff()
pass
btnA.wasPressed(buttonA_wasPressed)
@timerSch.event('timer1')
def ttimer1():
global temperature, humidity, ticks
ticks = (ticks if isinstance(ticks, int) else 0) + 1
pass
wifiCfg.doConnect('YOUR_WIFI_SSID', 'YOUR_WIFI_PASS')
m5mqtt.start()
temperature = '---'
humidity = '---'
ticks = 0
axp.setLDO2Volt(2.8)
setScreenColor(0x000000)
lcd.font(lcd.FONT_DejaVu24)
timerSch.run('timer1', 3500, 0x00)
while True:
if ticks % 2 == 0:
lcd.fill(0x000000)
image0.changeImg("res/temp3.jpg")
image0.setPosition(8, 8)
lcd.print(temperature, 8, 80, 0xff6666)
else:
lcd.fill(0x000000)
image0.changeImg("res/humi3.jpg")
image0.setPosition(8, 8)
lcd.print(humidity, 8, 80, 0x33ccff)
wait_ms(3500)
wait_ms(2)