【问题标题】:wpa_supplicant has no interfaces (pydbus)wpa_supplicant 没有接口(pydbus)
【发布时间】:2021-09-15 21:03:15
【问题描述】:

这是我使用 wpa_supplicant 的 D-Bus API 文档编写的一个简单代码。

from pydbus import SystemBus

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

print(proxy.Interfaces)

根据文档,它应该返回以下内容:

一个数组,其中包含指向 D-Bus 对象的路径,每个对象代表受控接口。

但是,它返回一个空数组,而我希望看到我的 wlan0 接口的路径。

我觉得我错过了上一步,但我完全不知道它是什么。

还有一些可能有用的东西:

  1. 运行 wpa_cli interface_list 不会返回任何结果。
  2. 运行ls /var/run/wpa_supplicant/ 返回p2p-dev-wlan0 wlan0
  3. 我不确定这有多相关,但我在 Raspberry Pi Zero W 上运行它。

编辑: 似乎 wpa_supplicant 不知道 wlan0 是什么。

我切换到dbus-python包看看有什么不同,在尝试获取wlan0接口时收到以下错误。

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')

错误:wpa_supplicant knows nothing about this interface

【问题讨论】:

    标签: python raspberry-pi dbus wpa-supplicant


    【解决方案1】:

    经过数周的痛苦,我为了完成而回答自己,并希望有一天这对其他人有用。

    错误在于wpa_supplicant 服务创建接口的方式。它所缺少的只是-u 标志。

    取自 wpa_supplicant 手册:

    -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.)
    

    一旦我发现了错误,它就很容易解决。但是,这里有关于如何解决这个问题的进一步说明,以防你仍然有点迷失。

    只需编辑您的服务文件,它应该类似于wpa_supplicant@wlan0.service不是 wpa_supplicant.service,这部分很重要。然后在写有ExecStart 的行上附加-u 标志。

    要编辑服务文件,您可以使用类似于

    sudo systemctl edit nameofyour.service --full

    并跟进

    sudo systemctl restart nameofyour.service

    之后您可能需要重新启动设备。

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2016-04-13
      • 2021-10-20
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 2016-07-09
      • 2023-04-09
      相关资源
      最近更新 更多