Use GoPiGo3 To Map WiFi Signal

When I built the occupancy grid sensor collection code, I didn’t think to add WiFi signal strength. This would allow the bot to build an indoor WiFi signal strength map.

In testing out gathering signal strength, I discovered some interesting aspects of WiFi on my bot:

  • The onboard WiFi signal strength varies from best (-25dBm) to worst (-42dBm) with orientation of the bot to the router
  • The USB WiFi adapter does not return signal strength in dBm - (always returns 100/100)
  • The OS seems to apply a “scan program” for the built-in WiFi adapter which perform a scan about once a minute

Here is my program if anyone has interest:



#           sudo pip3 install wifi

#         ./ for 1/minute scans
#         sudo ./ for continuous scans

#        - The USB WiFi Adapter does not return actual signal strength (program shows it as constnt -50)

import wifi
import time
from datetime import datetime
import os
import subprocess

def main():

    if os.geteuid() == 0:
        print("Priviledged Run")
        print("NonPriviledged Run")

    ip0 = subprocess.getoutput("ifconfig wlan0 | grep 'inet '")
    ip1 = subprocess.getoutput("ifconfig wlan1 | grep 'inet '")
    print("wlan0 address:",ip0)
    print("wlan1 address:",ip1)

    sig0 = 0
    sig1 = 0

    last_sig0 = 0
    last_sig1 = 0

    while True:
            # if priviledged scan, otherwise return once per minute cached value
            cell0 = list(wifi.Cell.all('wlan0'))[0]
            cell1 = list(wifi.Cell.all('wlan1'))[0]
            sig0 = cell0.signal
            sig1 = cell1.signal

            if (sig0 != last_sig0) or (sig1 != last_sig1):
                print("%d/%m/%Y %H:%M:%S"))
                print("wlan0:",sig0, cell0.quality)
                print("wlan1:",sig1, cell1.quality, "\n")
                last_sig0 = sig0
                last_sig1 = sig1
        except KeyboardInterrupt:
            print("\ncntr-c detected, exiting")
        except Exception as e:
            # once a minute the OS scans wlan0 
            # if running priviledged causes device busy exception

            # print("Exception: {}".format(str(e)))

if __name__ == '__main__':  main()