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()
What's in your boot.py?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: What's in your boot.py?
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.
Index to my micropython libraries.