Created
January 18, 2022 08:56
-
-
Save bazooka07/4eb777a8fa315f0c4d8d45eb899fe7fe to your computer and use it in GitHub Desktop.
_boot.py for Micropython on esp32 board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import uos | |
from flashbdev import bdev | |
from machine import Pin, Timer, Signal | |
from time import sleep_ms | |
# For ESP32-C3 LilyGo-T-OI-PLUS | |
LED_IN = Pin(3, Pin.OUT, 1) | |
LED_IN.off() | |
def flash(t=None): | |
LED_IN.on() | |
sleep_ms(150) | |
LED_IN.off() | |
try: | |
if bdev: | |
uos.mount(bdev, "/") | |
except OSError: | |
import inisetup | |
vfs = inisetup.setup() | |
timer1 = Timer(0) | |
timer1.init(mode=Timer.PERIODIC, period=500, callback=flash) | |
print('\n\n') | |
try: | |
import wifi_config | |
import network | |
sta_if = network.WLAN(network.STA_IF) | |
sta_if.active(True) | |
if not sta_if.isconnected(): | |
for ap in sta_if.scan(): | |
ssid = ap[0].decode('utf-8') | |
# Trying connection with known access points... | |
if ssid in wifi_config.aps: | |
print('SSID for Wifi: %s' %(ssid,)) | |
sta_if.connect(ssid, wifi_config.aps[ssid]) | |
while sta_if.status() == network.STAT_CONNECTING: | |
print('.', end='') | |
sleep_ms(200) | |
print('') | |
if sta_if.isconnected(): | |
ap_if = network.WLAN(network.AP_IF) | |
ap_if.active(False) | |
break | |
if sta_if.isconnected(): | |
try: | |
import uftpd | |
except: | |
sta_if.ifconfig() | |
try: | |
import ntptime | |
ntptime.settime() | |
except: | |
pass | |
except: | |
print('No Wifi setting found') | |
finally: | |
timer1.deinit() | |
try: | |
from upysh import * | |
except: | |
pass | |
gc.collect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this file on your board after flashing, with ampy for example "ampy -p /dev/ttyUSB0 put wifi_config.py" | |
aps = { | |
"GALAVEYSON": "my-secret-passord-1", | |
"Redmi 7A": "my-secret-passord-2", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment