0

I am trying to connect an STM32 Nucleo WIFI expansion board (SPWF04SA) to our wireless network using the built-in MicroPython interpreter. According to the datasheet it is supposed to be supported.

I can list the available networks using

import network
wlan = WLAN()
nets = wlan.scan()
for net in nets:
    print(net)

And I get

(ssid='PE0000', bssid='00:13:60:FF:8F:2D', auth='WPA2 ', channel=4, rssi=-65)
(ssid='PE9000', bssid='02:13:60:FF:8F:2D', auth='WPA2 ', channel=4, rssi=-67)
(ssid='PE0200', bssid='B8:C7:5D:07:CF:D3', auth='WPA2 ', channel=6, rssi=-85)

I then try to connect to network PE9000 (or any of them for that matter) using:

wlan.connect('PE9000',(WLAN.WPA2,'xxxx'))

And I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'WLAN' has no attribute 'WPA2'

If I try to use WLAN.WPA for the security type I don't get the error but, obviously, it won't connect to the network.

Any help would be appreciated.

dda
  • 6,030
  • 2
  • 25
  • 34
Mark Wagoner
  • 1,729
  • 1
  • 13
  • 20

2 Answers2

0

I was having this same problem with my ESP8266 module. I have included some code below that helped me fix the issue. I am using micropython 1.9.2.

    configuration_filename = 'configuration.json'

    station_config = network.WLAN(network.STA_IF)

    if not station_config.isconnected():
        with open(configuration_filename, 'r') as configuration_file:
            json_configuration = configuration_file.read()
            json_config = json.loads(json_configuration)

            ssid = json_config['ssid']
            password = json_config['password']
            station_config.connect(ssid, password)
            while not station_config.isconnected():
                machine.idle() # save power while waiting
            print('WLAN connection succeeded!')        
  • Thanks but since I don't have your JSON file this doesn't help much. I also get an error that there is no STA_IF attribute. – Mark Wagoner Sep 28 '17 at 20:40
  • The configuration_file has nothing to do with it -- it just holds the ssid and the password for the wifi network. You can actually test the code out by hard coding the ssid and password to see if it works. I'm not sure why the STA_IF is not working, I guess it is the different chipsets. – Lester Privott Sep 29 '17 at 12:07
0

I finally got it working. In case anyone else ever runs into this it appears the syntax is slightly non-standard for these boards. Instead of calling wlan.connect() I had to use the following:

w.init(mode=WLAN.STA, ssid='PE9000', auth=(WLAN.WPA, 'xxxx'))

Even though I specify WPA instead of WPA2 it must figure it out and connect anyway.

Mark Wagoner
  • 1,729
  • 1
  • 13
  • 20