Scanning the WiFi network with the Raspberry Pi Pico W

{,}
July 22nd, 2022

Let’s try the Wifi features of the new Raspberry Pi Pico W.

The Pico W has two Wifi interfaces:

  • network.STA_IF, the station interface
  • network.AP_IF, the access-point interface

network.STA_IF

The station (or standard) interface, can be used to connect the Pico W to another 2.4GHz WiFi access point. This seems to be the default.

network.AP_IF

The access-point interface can be used to turn your Pico W into a WiFi access-point that can connect up to 4 devices at the moment.

Use the Pico W to scan access points

Let’s try out the station interface, network.STA_IF.

Using micropython it’s really a breeze:


import network
import binascii
wlan = network.WLAN() #  network.WLAN(network.STA_IF)
wlan.active(True)
networks = wlan.scan() # list with tupples with 6 fields ssid, bssid, channel, RSSI, security, hidden
i=0
networks.sort(key=lambda x:x[3],reverse=True) # sorted on RSSI (3)
for w in networks:
      i+=1
      print(i,w[0].decode(),binascii.hexlify(w[1]).decode(),w[2],w[3],w[4],w[5])

In most example code you need to specify the interface, but apparently it defaults to the standard station network.STA_INF interface.

The output is a list with tupples that according to the docs should contain six fields ssid, bssid, channel, RSSI, security, hidden.

The bssid is the same as the hardware unique MAC-address.

There are five values for security:

  1. open (0)
  2. WEP (1)
  3. WPA-PSK (2)
  4. WPA2-PSK(3)
  5. WPA/WPA2-PSK (4)

and two for hidden:

  1. visible (0)
  2. hidden (1)

The docs states that for hidden 0 = visible and  1 = hidden, but actually the output I get, some twenty networks(!?) gives no 0, but several undocumented values for hidden: 1,2,3,4,5,7.

Twenty WiFi-networks? Yes, I do work in a city. And that’s only the 2.4GHz band. 🙁

So what does those values mean, what is there more than visible or hidden?

Also the security results differ with outputs from 0 (=open), most 5, but some report 7.

What do those values for security mean?

Is it a bug or a (undocumented) feature?

Tags: ,

3 Responses to “Scanning the WiFi network with the Raspberry Pi Pico W”

  1. 007 Says:

    Hello,
    Thank you very much for your example.

    I ran it on MicroPython v1.19.1 on Raspberry Pi Pico W.

    Apparently it returns up to 8 different codes for the security (w[4]) and up tp 7 different codes for Hidden/Visible(w[5]). Interestingly, none of the Hidden/Visible(w[5]) return 0, even though I have 25 or so visible networks in the range (yes, it is in the city center too)

    Thanks again.

  2. Taylor Says:

    I’ve had a look into this,

    For security mode, I can only get it to return one of 3 values (I haven’t tried on any WEP networks, so that might return a different value (1 I assume?))

    0 – Open
    3 – WPA
    7 – Mixed WPA/WPA2
    5 – WPA2/WPA3/OWE

    Seems to be a bit field where
    Bit 0 – encrypted
    Bit 1 – WPA
    Bit 2 – WPA2/3/OWE

    I’m unsure how the hidden field works, but I assume its a counter on how many times that AP advertised during the scan.

    Further Reading:
    https://github.com/micropython/micropython/blob/a00c9d56db775ee5fc14c2db60eb07bab8e872dd/extmod/network_cyw43.c#L143
    https://www.raspberrypi.com/documentation/pico-sdk/struct__cyw43__ev__scan__result__t.html

  3. webonomic Says:

    @Taylor thank you for responding, that is interesting research you have done.

Leave a Reply