-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py.dist
46 lines (38 loc) · 980 Bytes
/
main.py.dist
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
# This is executed after boot.py
import time
import ubinascii
import machine
import config
from umqtt.simple import MQTTClient
# Apparently NodeMCUs have a weird PIN wiring
# https://github.com/esp8266/Arduino/blob/esp8266/hardware/esp8266com/esp8266/variants/nodemcu/pins_arduino.h#L49
D0 = const(16)
D1 = const(5)
D2 = const(4)
D3 = const(0)
D4 = const(2)
D5 = const(14)
D6 = const(12)
D7 = const(13)
D8 = const(15)
D9 = const(3)
D10 = const(1)
MQTT_CID = b'esp-' + ubinascii.hexlify(machine.unique_id())
mqtt = MQTTClient(MQTT_CID, config.MQTT_HOST)
def mqtt_callback(topic, message):
# called when a new MQTT message arrives
pass
def cycle():
# read inputs of the chip etc
pass
if __name__ == '__main__':
print('Running main loop.')
mqtt.set_callback(mqtt_callback)
mqtt.connect()
try:
while 1:
cycle()
mqtt.check_msg()
time.sleep_ms(100) # sleep 100ms
finally:
mqtt.disconnect()