init
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import time
|
||||
import network
|
||||
import urequests
|
||||
|
||||
def sendDoorStatus(status):
|
||||
requestURL = "http://10.69.70.1/status"
|
||||
r = urequests.post(requestURL, data={"status", status})
|
||||
|
||||
def connectToNet():
|
||||
ssid = "ITRnet"
|
||||
password = "pink4bubble"
|
||||
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
wlan.connect(ssid, password)
|
||||
|
||||
MAX_WIFI_CONNECT_WAIT = 30
|
||||
while MAX_WIFI_CONNECT_WAIT > 0:
|
||||
if wlan.status() < 0 or wlan.status() >= 3:
|
||||
break
|
||||
MAX_WIFI_CONNECT_WAIT -= 1
|
||||
print('waiting to connect...')
|
||||
time.sleep(1)
|
||||
|
||||
if wlan.status() != 3:
|
||||
raise RuntimeError('network connection failed')
|
||||
else:
|
||||
print('connected!')
|
||||
status = wlan.ifconfig()
|
||||
print('ip = ' + status[0])
|
||||
|
||||
# program
|
||||
|
||||
connectToNet()
|
||||
sendDoorStatus(False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user