RSSI of connected WLAN

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
Stevo52
Posts: 14
Joined: Sun Feb 03, 2019 10:28 pm

RSSI of connected WLAN

Post by Stevo52 » Sat Dec 28, 2019 3:29 am

I am having some fun with the PYBD, transferring a build from a GPY to the newer STM32F722 device.. It all seems to work very well and is quicker and the code cleaner with the PYBD. To deliver the sensor information I am easily and repeatably able to connect over WiFi to a local access point and carry out most things, as well as write to a local SD or EMMC. That's all good, and I will work up the BT side later.

My client does however want me to report the live, current RSSI for the network being used every time data is sent (not sure exactly why they want that for their metrics). But I am having trouble getting this signal strength information - WLAN.status('rssi') doesn't work for me and I can't use WLAN.scan() once connected.. I can get that information before I connect but with some 12 or more wifi networks in the vicinity of the devices, there is a bit of code required to get the RSSI for the target network. And of course it is determined 'before' the connection is actually made, so depending on how long it has been connected, might not be current. I am looking at a workaround by dropping the connection every 60 seconds and measuring that way but it seems drastic.

Has anyone found a way to get the current RSSI for the WIFI connection? Any code examples? Am I missing something simple?

Hope you all had a great XMAS and are looking forward to a Merry New Year..

User avatar
devnull
Posts: 447
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: RSSI of connected WLAN

Post by devnull » Sat Dec 28, 2019 3:50 am

Hi;

This has been discussed before, unless something has changed recently, you have to scan for all devices, and then iterate through them to match your connected SSID and then read the RSSI value from that scan result.

I get the rssi (dbm) from my info() function and also calculate a sig strength %:

Code: Select all

def dcode(data):
  try: return data.decode('utf8')
  except: return data  
  
def scandic(row=('','',-1,100,-1,-1)):
  return ({
    'ssid'    : dcode(row[0]),
    'chan'    : row[2],
    'dbm'     : row[3],
    'sigpct'  : int(min((row[3]+100)*2,100)),
    'auth'    : row[4],
    'ip'      : wlan.ifconfig()[0]
  })

def info(ssid=None):
  ssid = ssid or wlan.config('essid')
  for row in wlan.scan():
    if dcode(row[0]) == ssid:
      return scandic(row)
  return scandic()

Stevo52
Posts: 14
Joined: Sun Feb 03, 2019 10:28 pm

Re: RSSI of connected WLAN

Post by Stevo52 » Sat Dec 28, 2019 4:49 am

Thanks devnull

I will give this a try a bit later, it is similar to the route I was going anyway.

Does this routine run AFTER Wi-Fi is connected as a Station?

Stevo52
Posts: 14
Joined: Sun Feb 03, 2019 10:28 pm

Re: RSSI of connected WLAN

Post by Stevo52 » Sat Dec 28, 2019 11:19 pm

Thanks devnull, with a few minor modifications (to suit my coding style and calls direct to the WLAN) this has given me the information I need. Your help is appreciated.

Post Reply