upython-bme680/boot.py

48 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-02-04 21:25:36 +01:00
# This file is executed on every boot (including wake-boot from deepsleep)
import webrepl
import time
import machine
wifi_timelimit = 5.0
try:
from secrets import secrets
yourWifiSSID = secrets["ssid"]
yourWifiPassword = secrets["password"]
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
def connect():
import network
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect(yourWifiSSID, yourWifiPassword)
print("connecting to " + yourWifiSSID + "...")
start = time.time()
while not sta_if.isconnected():
if time.time() - start > wifi_timelimit:
print(" ")
print("**** TIMEOUT: too long a wait for connecting to WiFi - check ssid and password")
print(" ")
break
pass
ipaddress = sta_if.ifconfig()[0]
print("connected to " + yourWifiSSID + ' with IP address:' , ipaddress)
webrepl.start()
def no_debug():
import esp
esp.osdebug(None) # this can be run from the REPL as well
def showip():
import network
sta_if = network.WLAN(network.STA_IF)
print('network config:', sta_if.ifconfig())
connect()
import main