GoPiGo O/S: Read WiFi connection status and type?

Greetings!

Is it possible to determine, programmatically, what state the WiFi is in?

Seeing as it can be in one of several possible states:

  1. Access Point mode, disconnected.
  2. Access Point mode, connected.
  3. Networked mode, disconnected.
  4. Networked mode, connected.
  5. Completely disabled.

it would be nice to know what state it’s in, and - just as important - when or if it changes state.

Thanks!

Obviously, since the software driving the WiFi LED can tell four of those, the answer lies in finding the source code for the wifi service. I figured it out on Raspbian For Robots, but since I keep my GoPiGo OS card in “unaltered” state, it is a royal pain to get connected every time.

In R4R the antena_wifi.service runs this file every 10 seconds to set the LED based on the bot autodetect code and

iwgetid --scheme

returning the SSID of a network connection:

more ../Dexter/GoPiGo3/Install/antenna_wifi.sh
# 1 Detect if we are on a GoPiGo3
# 2 Detect if we have Wifi connection
# 3 Throw a yellow-orangey LED or turn it off


# If detected_robot exists and it contains GoPiGo3, or 
# if it doesn't exist at all on standalone Raspbian
if [ -f "/home/pi/Dexter/detected_robot.txt" ] && grep -q GoPiGo3 /home/pi/Dexter/detected_robot.txt  || [  ! -f "/home/pi/Dexter/detected_robot.txt" ]
then
    if iwgetid --scheme
    then
        python -c "import gopigo3;GPG=gopigo3.GoPiGo3();GPG.set_led(GPG.LED_WIFI,3,1,3)"
    else
        python -c "import gopigo3;GPG=gopigo3.GoPiGo3();GPG.set_led(GPG.LED_WIFI,0,0,0)"
    fi
fi

On R4R, autodetect source is here (I’m pretty sure it is also in the gopigo3 python site packages):
$ find …/Dexter auto_detect_robot.py | grep auto_detect

…/Dexter/lib/Dexter/RFR_Tools/miscellaneous/auto_detect_robot.py

auto_detect_rpi (version 3 or 4) is also there.

2 Likes