pythonraspberry-pidbuswpa-supplicant

wpa_supplicant has no interfaces (pydbus)


This is a simple code I have that I wrote using the documentation of wpa_supplicant's D-Bus API.

from pydbus import SystemBus

bus = SystemBus()
proxy = bus.get('fi.w1.wpa_supplicant1','/fi/w1/wpa_supplicant1')

print(proxy.Interfaces)

As per the documentation, it should return the following:

An array with paths to D-Bus objects representing controlled interfaces each.

However, it returns an empty array, while I would expect to see a path to my wlan0 interface.

I feel like I am missing a previous step but I am completely lost on what it is.

A few more things that might be useful:

  1. Running wpa_cli interface_list returns nothing.
  2. Running ls /var/run/wpa_supplicant/ returns p2p-dev-wlan0 wlan0
  3. I am not sure how relevant this is, but I am running this on a Raspberry Pi Zero W.

EDIT: It seems like wpa_supplicant has no clue about what a wlan0 is.

I switched to the dbus-python package to see if it was any different and received the following error when trying to get the wlan0 interface.

import dbus

bus = dbus.SystemBus()
wpas_obj = bus.get_object('fi.w1.wpa_supplicant1','/fi/w1/wpa_supplicant1')

wpas = dbus.Interface(wpas_obj, 'fi.w1.wpa_supplicant1')
path = wpas.GetInterface('wlan0')

Error: wpa_supplicant knows nothing about this interface


Solution

  • After weeks of pain, I am answering myself for the sake of completion and with the hope that someday this is useful to somebody else.

    The error was in the way that the wpa_supplicant service was creating the interfaces. All it was missing was the -u flag.

    Taken from the wpa_supplicant manual:

    -u     Enable DBus control interface. If enabled, interface definitions may be omitted. (This is only available if wpa_supplicant was built with the CONFIG_DBUS option.)
    

    Once I figured out the error it was a rather easy fix. However, here is further explanation on how to fix this, just in case you are still a bit lost.

    Simply edit your service file, it should be something like wpa_supplicant@wlan0.service, not wpa_supplicant.service, that part is important. Then append the -u flag on the line that says ExecStart.

    To edit a service file you can use something similar to

    sudo systemctl edit nameofyour.service --full

    and follow up with

    sudo systemctl restart nameofyour.service

    You may need to reboot your device after that.