forked from Hack42/openlabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenlabs.py
33 lines (30 loc) · 860 Bytes
/
openlabs.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
#KADOOTJE VAN HACK42
import ugfx
import badge
import easywifi
import time
import machine
import gc
import time
from umqtt.simple import MQTTClient
state="CLOSED"
oldstate=state
oldtest=-1
pin=machine.Pin(33,machine.Pin.IN,machine.Pin.PULL_UP)
def test():
return pin.value()
X=MQTTClient("openlabs42","test.mosquitto.org")
while True:
thetest = test()
if oldtest != thetest:
easywifi.enable()
X.connect()
oldtest = thetest
state = "CLOSED" if thetest == 1 else "OPEN"
X.publish("openlabs/state/state",state,1)
ugfx.clear(ugfx.WHITE if state=="OPEN" else ugfx.BLACK)
ugfx.string_box(0,45,296,38, state, "PermanentMarker36", ugfx.BLACK if state=="OPEN" else ugfx.WHITE, ugfx.justifyCenter)
ugfx.flush(ugfx.LUT_FULL)
X.disconnect()
easywifi.disable()
time.sleep(1)