ProjZ
Posts: 3
Joined: Sat Apr 28, 2018 7:02 am

iwlist scan maximal refresh rate

Sat Apr 28, 2018 7:37 am

Hello all,

I am currently interested in getting the Received Signal Strength Indicator (RSSI) of a specific Wifi network with a Python script.
My script is inspired from viewtopic.php?t=85601#p604902 where iwlist scan is used.

I have noticed that it takes around 1 second to parse the RSSI value and I was wondering if there is no way to do it faster? Actually I'm doing this for a university project and I wanted to know what are the limitations so that I can provide a more in depth explanation.

Thank you very much for your help

PS: I measured the execution time of the two lines of code below using time.time().

Code: Select all

proc = subprocess.Popen(["sudo", "iwlist", "wlan0", "scan", "essid", "dd-wrt"],stdout=subprocess.PIPE, universal_newlines=True)
out, err = proc.communicate()

Paul Hutch
Posts: 282
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA

Re: iwlist scan maximal refresh rate

Sun Apr 29, 2018 2:28 pm

I just tried it from outside of Python and found that,

Code: Select all

sudo iwlist wlan0 scan essid XXXXXX
and

Code: Select all

sudo iwlist wlan0 scan
take about a second to return but,

Code: Select all

iwlist wlan0 scan
returns instantly.

It looks to me that the sudo is causing the slowdown and since it happens from a command prompt there is nothing you can do in Python to speed it up.

FYI there is Python library for getting WiFi status data. https://pypi.org/project/python-wifi/

ProjZ
Posts: 3
Joined: Sat Apr 28, 2018 7:02 am

Re: iwlist scan maximal refresh rate

Fri May 18, 2018 8:23 am

Ok I guess there is nothing I can do in Python to speed it up. I'm still wondering what is the underlying reason of this slowdown.
Anyway thank you very much for your answer Paul Hutch! (Sorry for the long delay by the way)

MrEngman
Posts: 3718
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: iwlist scan maximal refresh rate

Fri May 18, 2018 8:46 am

ProjZ wrote:
Fri May 18, 2018 8:23 am
Ok I guess there is nothing I can do in Python to speed it up. I'm still wondering what is the underlying reason of this slowdown.
Anyway thank you very much for your answer Paul Hutch! (Sorry for the long delay by the way)
I believe the scan results are saved somewhere when the Pi boots and connects to the wifi, but not sure where, and when you do

Code: Select all

iwlist wlan0 scan
without sudo it uses the stored results. However, if you do

Code: Select all

sudo iwlist wlan0 scan
it does a new scan and saves those new results wherever, which is why it takes longer as it is doing a new, updated scan.
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ProjZ
Posts: 3
Joined: Sat Apr 28, 2018 7:02 am

Re: iwlist scan maximal refresh rate

Tue May 22, 2018 8:29 am

MrEngman wrote:
Fri May 18, 2018 8:46 am
ProjZ wrote:
Fri May 18, 2018 8:23 am
Ok I guess there is nothing I can do in Python to speed it up. I'm still wondering what is the underlying reason of this slowdown.
Anyway thank you very much for your answer Paul Hutch! (Sorry for the long delay by the way)
I believe the scan results are saved somewhere when the Pi boots and connects to the wifi, but not sure where, and when you do

Code: Select all

iwlist wlan0 scan
without sudo it uses the stored results. However, if you do

Code: Select all

sudo iwlist wlan0 scan
it does a new scan and saves those new results wherever, which is why it takes longer as it is doing a new, updated scan.
Yes I purposely forces the Pi to do a new scan each time I want to retrieve the RSSI and this operation takes around 1 second. I just wonder if it is the minimal required time for the electronics to execute this refresh. If not, it would be great to know how to go around this command and scan the value faster :)

MrEngman
Posts: 3718
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: iwlist scan maximal refresh rate

Tue May 22, 2018 9:26 am

Hi ProjZ,

I think you will find 1 second is about the fastest the scan will run at.

The time taken also appears to be dependent on how many APs the scan finds, or what wifi module you do the scan with.

I have a Pi 3B+ which has an extra wifi module, an 8188eu module, connected to it. Scanning with the extra wifi module takes around 1-2 seconds but using the built in Broadcom wifi it takes about 3-4 seconds. I think the time is dependent to some extent on the amount of data returned by the scan.

Scanning with the built in Broadcom wifi returns a much larger amount of data for each AP it finds which I expect accounts for the longer time it takes.
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

Paul Hutch
Posts: 282
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA

Re: iwlist scan maximal refresh rate

Wed May 23, 2018 2:32 pm

MrEngman wrote:
Fri May 18, 2018 8:46 am
ProjZ wrote:
Fri May 18, 2018 8:23 am
Ok I guess there is nothing I can do in Python to speed it up. I'm still wondering what is the underlying reason of this slowdown.
Anyway thank you very much for your answer Paul Hutch! (Sorry for the long delay by the way)
I believe the scan results are saved somewhere when the Pi boots and connects to the wifi, but not sure where, and when you do

Code: Select all

iwlist wlan0 scan
without sudo it uses the stored results. However, if you do

Code: Select all

sudo iwlist wlan0 scan
it does a new scan and saves those new results wherever, which is why it takes longer as it is doing a new, updated scan.
I just tried running the non-sudo version before and after firing up a test AP in my office. The test AP showed up in the second scan and disappeared from a third scan after I turned the test AP back off.

Without sudo it still updates the scan results so other than slowing down the return speed, I'm not sure what good the sudo does for iwlist.

Return to “Python”

Who is online

Users browsing this forum: kko123 and 8 guests