-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (74 loc) · 1.92 KB
/
Copy pathmain.py
File metadata and controls
83 lines (74 loc) · 1.92 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import time
import urequests
import network
from neopixel import NeoPixel
from machine import Pin
import micropython,sys,gc
ssid = 'Wokwi-GUEST'
password = ''
urls = (
"https://www.google.com/",
"https://www.google.com/",
"https://www.google.com/",
"https://www.google.com/",
"https://www.google.com/",
"https://www.google.com/",
"https://www.google.com/",
"https://www.google.com/alyaiscool")
serviceStatus = [200,200,200,200,200,200,200,200]
totalLeds = const(16)
waitTime = const(60)
rainbow = [(255,0,0),(255,125,0),(255,255,0),(125,255,0),(0,255,0),(0,255,125),(0,255,255),(0,125,255)]
errorColor = (255,255,0)
connectingColor = (0,255,255)
def connectToWifi():
print("Connecting to WiFi",end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect(ssid,'')
while not sta_if.isconnected():
floodPixels(connectingColor)
print(".",end="")
time.sleep(0.1)
print(" Connected!")
def checkUrls():
for index,url in enumerate(urls):
try:
print("Checking ",url)
resp = urequests.head(url)
print(index,"----",resp.status_code)
serviceStatus[index] = resp.status_code
del(resp)
gc.collect()
except:
serviceStatus[index] = 500
gc.collect()
def ledToRainbow(ledNumber):
rainbowBand = 0
if ledNumber < 8:
rainbowBand = ledNumber
else: # 8 9 10 11 12 13 14 15
rainbowBand = abs(15-ledNumber)
return rainbowBand
def updatePixels():
for i in range(16):
if serviceStatus[ledToRainbow(i)] == 200:
pixels[i] = rainbow[ledToRainbow(i)]
else:
pixels[i] = (0,0,0)
pixels.write()
def floodPixels(color):
for i in range(totalLeds):
pixels[i] = color
pixels.write()
pixels = NeoPixel(Pin(4),totalLeds)
connectToWifi()
updatePixels()
while True:
if network.WLAN(network.STA_IF).isconnected():
checkUrls()
updatePixels()
time.sleep(waitTime)
else:
floodPixels(errorColor)
connectToWifi()