-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (39 loc) · 1.08 KB
/
main.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
import network
import json
import requests
import machine, neopixel
import time
import json
import os
wlan = network.WLAN(network.STA_IF)
def connect():
with open('wlan.json') as f:
credentials = json.load(f)
wlan.connect(credentials['ssid'], credentials['password'])
def set_wifi(ssid, password):
with open('wlan.json', 'w') as f:
f.write(json.dumps({
"ssid": ssid,
"password": password
}))
def do():
while True:
response = requests.get("https://yourURLHere")
response_content = json.loads(response.content)
np = neopixel.NeoPixel(machine.Pin(0), 10)
for light in response_content:
np[int(light)] = tuple(response_content[light])
np.write()
time.sleep(60)
def init():
# Connect to network
wlan.active(True)
if not "wlan.json" in os.listdir():
print("Use set_wifi(ssid, password) to set a wifi password")
print("Afterwards reboot")
return
connect()
while not wlan.isconnected():
pass
do()
init()