WLAN access point not working micropython 1.19.1

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
MicroRichard
Posts: 15
Joined: Tue Aug 09, 2022 11:32 am

WLAN access point not working micropython 1.19.1

Post by MicroRichard » Wed Sep 07, 2022 3:53 pm

With micropython 1.15 the following code worked to create an accesspoint.

Code: Select all

def enable_wifi(ssid, password):
        """ Enable device as WiFi access point

        Parameters
        ----------
        ssid : String
            Broadcast WiFi SSID
        password: String
            WiFi password
        """    
        
        if not NetworkHandler.ap:
            NetworkHandler.ap = network.WLAN(network.AP_IF)
            
        NetworkHandler.ap.active(0)
        NetworkHandler.ap.config(essid=ssid)
        NetworkHandler.ap.config(password=password)
        NetworkHandler.ap.config(channel=1)
        NetworkHandler.ap.config(authmode=4)
        NetworkHandler.ap.active(1)
Recently upgraded to micropython 1.19.1 and the network accesspoint does not appear anymore.
I discovered that the following code works, but then how to set the security and password of the accesspoint?

Code: Select all

if not NetworkHandler.ap:
        NetworkHandler.ap = network.WLAN(network.AP_IF)
            
        NetworkHandler.ap.active(0)
        NetworkHandler.ap.config(essid=ssid, channel=1)
The accesspoint is shown but has no security enabled...
Help would be appreciated.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: WLAN access point not working micropython 1.19.1

Post by jimmo » Thu Sep 08, 2022 2:48 am

Which board are you using? You're posting in Pyboard-D but "authmode" has never been a supported config argument for the Pyboard-D as far as I can tell, only on ESP32 and ESP8266.

On Pyboard-D the config argument is "security".

I can confirm the following code works for me on ESP32 & ESP8266 on 1.19.1 to create a secured access point. (Except on ESP8266 you need to active(1) the interface before calling config).

Code: Select all

import network
ap = network.WLAN(network.AP_IF)
ap.active(0)
ap.config(essid="esp32-jim", password="helloworld", channel=1, authmode=network.AUTH_WPA_WPA2_PSK)
ap.active(1)
And equivalently to create an open access point

Code: Select all

import network
ap = network.WLAN(network.AP_IF)
ap.active(0)
ap.config(essid="esp32-jim", channel=1, authmode=network.AUTH_OPEN)
ap.active(1)
For the pyboard-d, the following works for me on 1.19.1 to create a secured AP:

Code: Select all

import network

ap = network.WLAN(network.AP_IF)
ap.active(0)
ap.config(essid="pybd-jim", password="helloworld", channel=1, security=4)
ap.active(1)
Did you find a resolution to viewtopic.php?f=20&t=12958 by the way?

MicroRichard
Posts: 15
Joined: Tue Aug 09, 2022 11:32 am

Re: WLAN access point not working micropython 1.19.1

Post by MicroRichard » Thu Sep 08, 2022 6:18 am

The pyboard is the pyboard D type and the firmware is MicroPython v1.19.1-1-g093d292. When i use the code you mentioned an exception is raised saying 'unknown config param'. It has something to do with the security parameter.

Code: Select all

import network

ap = network.WLAN(network.AP_IF)
ap.active(0)
ap.config(essid="pybd-jim", password="helloworld", channel=1, security=4)
ap.active(1)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: WLAN access point not working micropython 1.19.1

Post by jimmo » Thu Sep 08, 2022 3:12 pm

MicroRichard wrote:
Thu Sep 08, 2022 6:18 am
MicroPython v1.19.1-1-g093d292
I can't find this commit in the history... Where did you download this from? What's the full .dfu filename?
MicroRichard wrote:
Thu Sep 08, 2022 6:18 am
When i use the code you mentioned an exception is raised saying 'unknown config param'. It has something to do with the security parameter.
Maybe it was added after 1.19.1 ... try one of the recent nightly builds.

The part that is confusing me is that config(authmode=) has never (as far as I can tell from the git history) been supported on pyboard-d, so I'm confused how this was working previously.

Post Reply