Bladeren bron

Add MCU startup sequence

At boot time, the ESP8266 will connect to the wireless network
defined in the config file, then set the LED_PIN high to indicate
that it's connected and ready.
DarkMorford 6 jaren geleden
bovenliggende
commit
e08a926d4c
1 gewijzigde bestanden met toevoegingen van 27 en 0 verwijderingen
  1. 27 0
      code/main.py

+ 27 - 0
code/main.py

@@ -0,0 +1,27 @@
+from machine import Pin, Signal
+LED_PIN = Signal(13, Pin.OUT, invert=False)
+BUTTON_PIN = Signal(0, Pin.IN, invert=True)
+
+# Turn off "ready" LED
+LED_PIN.off()
+
+# Read configuration from JSON file
+with open('config.json') as fd:
+    import ujson
+    config = ujson.load(fd)
+
+# Configure wireless networking
+import network
+wifi_host = network.WLAN(network.AP_IF)
+wifi_host.active(False)
+
+wifi_guest = network.WLAN(network.STA_IF)
+wifi_guest.active(True)
+if not wifi_guest.isconnected():
+    wifi_guest.connect(config.wifi.ssid, config.wifi.password)
+    while not wifi_guest.isconnected():
+        pass
+print(wifi_guest.ifconfig())
+
+# Turn on "ready" LED
+LED_PIN.on()