Not in the dark any more – Scan Wifis with micropython on an ESP8266

A small script to scan the neighbouring Wifis with your microcontroller. You get the following information about them:

  • SSID – Wifi name
  • MAC – hardware address of the Wifi interface
  • RSSI – signal strength
  • channel – could indicate problems if multiple Wifis are on the same
  • security – which encryption protocol is used
  • hidden

Kept the code as simple and small as possible. Available functions in network package could vary depending on used microcontroller type and micropython version / implementation.

import network
import binascii

wifiSecurityType = { 0: 'open', 1: 'WEP', 2: 'WPA-PSK', 3: 'WPA2-PSK', 4: 'WPA/WPA2-PSK'}

for wifi in network.WLAN(network.WLAN.IF_STA).scan():
    ssid = wifi[0].decode()
    mac = ':'.join([f"{b:02X}" for b in wifi[1]])
    channel = wifi[2]
    rssi =  wifi[3]
    sec =  wifiSecurityType[wifi[4]]
    hidden = wifi[5] is 1
    print(f"SSID: {ssid}, MAC: {mac}, channel: {channel}, rssi: {rssi}, sec: {sec}, hidden: {hidden}")

Resource links:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.