Yesterday, the 11th, was the day I tied all my little WiFi scripts together into the wrapper.

In the file, the script runs immediately after sends the P4wnP1_cli command to Connect to WiFi.


P4wnP1 OLED Connect-to-WiFi List of Scripts (JoyFi?)

Here is the current list of scripts included in the OLED P4wnP1 Connect-to-WiFi script package (in order of where they're placed in the wrapper .py file):


How does work? runs the classic linux command iwconfig to fetch internet wireless configuration data from the Raspberry Pi (or any Linux computer).

Why use iwconfig to check WiFi status instead of a more Python-native code block such as the one at shown at this page?

I wanted to use a "raw" Linux command.  I also wanted Signal Strength and the other info that comes with the output of iwconfig.

Note:  There's also this way to check active connections in Python.

Step 1:  Run the iwconfig Command

First, wifi-chek runs "iwconfig" Linux command in a Python3 subprocess.

I use the Python "try" command to attempt running iwconfig and simultaneously handling errors how I want it to.

Step 2:  Get the Data

Then it parses the output of iwconfig using the Python3 ".strip" method.

Step 3:  Do the WiFi Network Check

After that, it looks for "SSID:" in the parsed output.

TIP:  To look for text in a string using Python, check out this simple method on Stackexchange.


Why?  If the device is connected to a WiFi network, then the text "SSID:" will appear in the output of iwconfig.


Therefore, if the string "SSID:" is found, then determines that the WiFi is connected to a network.

If "SSID" is not found, then _____________.

Step 4:  Run the Ping Check Command

After the SSID is checked, pings

Wifi-chek runs a Python3 subprocess to "ping -c3".

If returns data to us, then determines that P4wnP1 is now connected to the Internet (DNS is good!).

If does NOT return data to us, then ______________.

Step 5:  Offer Options

To Do:

Untested alternative to iwlist:

iw dev wlan0 scan


Switch to WiFi "Managed" mode:

Another name for this is Client mode.

Make a script that runs these commands:

sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode Managed
sudo ifconfig wlan0 up
sudo iwlist wlan0 scan