Skip to content

Instantly share code, notes, and snippets.

@unforgiven512
Created July 18, 2019 21:55
Show Gist options
  • Select an option

  • Save unforgiven512/ed97306cc408632d04287f6d771eb997 to your computer and use it in GitHub Desktop.

Select an option

Save unforgiven512/ed97306cc408632d04287f6d771eb997 to your computer and use it in GitHub Desktop.
new boot.py file on MicroPython ESP8266 board #7
# This file is executed on every boot (including wake-boot from deepsleep)
# Import any necessary modules for early in the system boot process
import esp
import gc
import webrepl
import machine
import network
# import socket
import uos
print('\n\n\n\n')
print('\t+-----------------------------------------+')
print('\t| MicroPython on ESP8266 starting up... |')
print('\t+-----------------------------------------+')
print('\n\n\n')
# Disable the ESP low-level hardware debugging (if so desired)
print('> ESP low-level hardware debug prints have been disabled.\n')
esp.osdebug(None)
# Set frequency to 160 MHz
print('> Setting the ESP8266 core frequency from 80MHz to 160MHz...')
machine.freq(160000000)
# Create objects for network interfaces (WLAN station, WLAN AP)
print('> Creating objects to facilitate access to the WLAN station and access point interfaces...')
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)
# Ensure the STA interface is active, and the AP interface is NOT active.
print('> Ensuring the WLAN station (ie: client) interface is active...')
sta_if.active(True)
print('> Ensuring the WLAN access point (ie: AP) interface is NOT active...')
ap_if.active(False)
if not sta_if.isconnected():
print('====================================')
print(' NO CONNECTION TO WLAN: PirateNet ')
print('====================================')
print('\n\n')
print('> Attempting to connect to WLAN: PirateNet')
sta_if.active(True)
sta_if.connect('PirateNet', 'wlanaxx00x')
while not sta_if.isconnected():
pass
print('================================')
print(' CONNECTED TO WLAN: PirateNet ')
print('================================')
print('\n\n')
print('ifconfig')
print('--------')
print(sta_if.ifconfig())
#uos.dupterm(None, 1) # disable REPL on UART(0)
# Start the WebREPL
print('> Starting the WebREPL services...')
webrepl.start()
# Determine reset cause very early on, and let the program know what happened
print('--------------------------------------------------------------------------------')
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
print('> [RESET] System woke up from deep sleep')
else:
print('> [RESET] System woke up from a hard reset (ie: power-on-reset)')
print('--------------------------------------------------------------------------------')
# Collect garbage before handing execution over to main.py
print('> Performing any necessary garbage collection before handing execution to main.py\n\n\n\n\n')
gc.collect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment