forked from jadolg/IoTInternetMonitior
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (30 loc) · 738 Bytes
/
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
import gc
import time
import network
import urequests
from machine import Pin
pin = machine.Pin(2, machine.Pin.OUT)
pin.on()
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
while True:
try:
wlan.connect("user", "password")
response = urequests.get("http://clients3.google.com/generate_204")
print(response.status_code)
if response.status_code == 204:
print("online")
pin.off()
elif response.status_code == 200:
print("portal")
pin.off()
time.sleep(1)
pin.on()
else:
print("offline")
pin.on()
except:
print("error")
pin.on()
gc.collect()
time.sleep(10)