WLAN

The WLAN is a system feature of all Pycom devices, therefore it is enabled by default.

In order to retrieve the current WLAN instance, run:

>>> from network import WLAN
>>> wlan = WLAN() # we call the constructor without params

The current mode (WLAN.AP after power up) may be checked by running:

>>> wlan.mode()

When changing the WLAN mode, if following the instructions below, the WLAN connection to the Pycom device will be broken. This means commands will not run interactively over WiFi.

There are two ways around this:

  1. Put this setup code into the boot.py file of the Pycom device so that it gets executed automatically after reset.

  2. Duplicate the REPL on UART. This way commands can be run via Serial USB.

Connecting to a Router

The WLAN network class always boots in WLAN.AP mode; to connect it to an existing network, the WiFi class must be configured as a station:

from network import WLAN
wlan = WLAN(mode=WLAN.STA)

Now the device may proceed to scan for networks:

nets = wlan.scan()
for net in nets:
    if net.ssid == 'mywifi':
        print('Network found!')
        wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000)
        while not wlan.isconnected():
            machine.idle() # save power while waiting
        print('WLAN connection succeeded!')
        break

Assigning a Static IP Address at Boot Up

If the users wants their device to connect to a home router upon boot up, using with a fixed IP address, use the following script as /flash/boot.py:

Notice how we check for the reset cause and the connection status, this is crucial in order to be able to soft reset the LoPy during a telnet session without breaking the connection.

Multiple Networks using a Static IP Address

The following script holds a list with nets and an optional list of wlan_config to set a fixed IP

Connecting to a WPA2-Enterprise network

Connecting with EAP-TLS:

Before connecting, obtain and copy the public and private keys to the device, e.g. under location /flash/cert. If it is required to validate the server’s public key, an appropriate CA certificate (chain) must also be provided.

Connecting with EAP-PEAP or EAP-TTLS:

In case of EAP-PEAP (or EAP-TTLS), the client key and certificate are not necessary, only a username and password pair. If it is required to validate the server’s public key, an appropriate CA certificate (chain) must also be provided.

Last updated