copy and paste the following into a new file called boot.py

```python

To use networking features, we need to import the Network library

import network

Next we set in stone a couple of variables of the WiFi network we

want to connect to, you will need to set these yourself.

YOUR_WIFI_AP_NAME = "insert it here" YOUR_WIFI_AP_PASSCODE = "insert it here"

the ap_is_disabled() function takes in no arguments/parameters and

will return a true/false boolean to indicate if the ESP8266 thinks

that Access Point (AP) station behaviour is enabled (true) or

disabled (false).

We use this to check that AP behaviour is disabled before trying

to connect connect as a client to an existing WiFi networks AP

def ap_is_disabled(): ap_if = network.WLAN(network.AP_IF) ap_if.active(False) if ap_if.active() is not True: print('access point functionality disabled') return True else: print('access point is still running...') return False

this do_connect() function also takes in no arguments/parameters

and will similarly return a boolean on whether it was successful

on connecting to the specified WiFi AP using the credentials we

set above

def do_connect(): sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): print('connecting to network...') sta_if.active(True) sta_if.connect(YOUR_WIFI_AP_NAME, YOUR_WIFI_AP_PASSCODE) while not sta_if.isconnected(): pass print('network config:', sta_if.ifconfig())

if sta_if.isconnected():
    return True
else:
    return False

The above functions are now put into action, first we test that

the ESP8266 doesn't think it should be a WiFi network AP in it's

own right...

if ap_is_disabled(): # and if it not set to be a AP we then try to connect to the # WiFi network! :) do_connect()

```