What's in your boot.py?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
dirtydan
Posts: 1
Joined: Mon Oct 22, 2018 10:56 pm

What's in your boot.py?

Post by dirtydan » Tue Oct 23, 2018 9:48 pm

Hello, I'm looking for interesting boot.py tricks. I've posted mine below. I've just got some functions for connecting to wifi with options to print my ip address and disconnect if I need to for some reason.

def connect():
import network
sta_if = network.WLAN(network.STA_IF)
print('connecting to network...')
sta_if.active(True)
sta_if.connect('MYSSID',MYPASSWORD')
def isconnected():
import network
sta_if = network.WLAN(network.STA_IF)
print(sta_if.isconnected())
def getip():
import network
sta_if = network.WLAN(network.STA_IF)
print("Got ip: ", sta_if.ifconfig()[0])
print("Netmask: ", sta_if.ifconfig()[1])
print("DNS: ", sta_if.ifconfig()[2])
def disconnect():
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.disconnect()

if __name__ == '__main__':
connect()

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: What's in your boot.py?

Post by pythoncoder » Wed Oct 24, 2018 6:01 am

In general it's best to keep boot.py pretty minimal. If you want a set of functions to be available at the REPL create a file (say myfile.py) and edit main.py to read:

Code: Select all

from myfile import connect, disconnect, isconneced, getip
Peter Hinch
Index to my micropython libraries.

Post Reply