There's no reason to run python, since the information is easiest obtained by running wpa_cli
. Php uses shell_exec
to run commands, which is the equivalent of os.system
and to some extent subprocess.check_output
in python.
You have to run two commands in order. If the first fails, the second has no use as the WiFi card is not able to scan.
wpa_cli -i wlan0 scan
This should return "OK" and wlan0
is the name of the wireless interface as shown by ifconfig
. This is typically wlan0 and does not change over time, only when more WiFi cards are added to the pi.
wpa_cli -i wlan0 scan_results
This returns several lines with a header:
bssid / frequency / signal level / flags / ssid
b2:c2:87:77:62:73 2437 -50 [WPA2-EAP-CCMP][ESS] Ziggo
1c:3a:de:c3:f8:cf 2472 -54 [WPA2-PSK-CCMP+TKIP][WPS][ESS] HZN246837438
You can discard the first line and split the rest of the lines at whitespace. Php can do this and make sure you allow at maximum 4 splits (resulting in 5 elements).
I'm doing exactly what you want, on a rpi-3, with Django (python). For a webserver with php the process is the same.