【问题标题】:getting list of wpa_supplicant interfaces in node.js在 node.js 中获取 wpa_supplicant 接口列表
【发布时间】:2016-09-09 16:05:32
【问题描述】:

我的最终目标是创建一个可以告诉我为什么无线连接设置失败的模块。

目前我正在尝试使用node-dbus 模块访问 wlan0 接口。就目前而言,wpa_supplicant 告诉我它不知道 wlan0

'wpa_supplicant 对此接口一无所知。'

非常感谢任何帮助或建议。

代码:

var dbus = require('dbus-native');
var util = require('util');

var bus = dbus.systemBus();
var wpas = bus.getService('fi.w1.wpa_supplicant1');

var wpai = wpas.getInterface('/fi/w1/wpa_supplicant1'
    , 'fi.w1.wpa_supplicant1', function (err, iface) {
        //console.log(err, iface);

        iface.on('PropertiesChanged', function(dict) {
            console.log('interface properties have changed!');
            console.log(dict);
        });

        iface.on('InterfaceAdded', function(path, dict) {
            console.log('interface has been added!');
            console.log(path, dict);
        });

        iface.on('InterfaceRemoved', function(path) {
            console.log('interface has been removed!');
            console.log(path);
        });

        iface.GetInterface('wlan0', function (err, iface2) {
            console.log(err, iface2);
        });

        console.log(util.inspect(iface, true, 3));

    });

更新 1:

我使用 DBus 属性 api 调查了 Interfaces 属性,发现该属性本身为空。

wpas.getInterface('/fi/w1/wpa_supplicant1', 'org.freedesktop.DBus.Properties', function(err, device) {
                device.GetAll('fi.w1.wpa_supplicant1', function(err, prop) {
                    var props = arrToMap(prop);
                    console.log(err,props);
                });
            });

function arrToMap(arr) {
    var output = {};
    for (var i = 0; i < arr.length; i++) {
        output[arr[i][0]] = arr[i][1][1][0];
    }
    return output;
}

我唯一的结论是 wpa_supplicant 从不向 dbus 注册任何新接口。

(我已确保通过终端命令使用 wpa_supplicant 设置了我的 wlan0)

【问题讨论】:

    标签: node.js wpa wpa-supplicant


    【解决方案1】:

    我设法通过使用 Promise 重写上面的代码来解决我的问题。 还需要注意的是,上面的 GetInterface 只返回 wpa_supplicant 适配器。

    需要使用 GetInterface 对该对象进行额外调用才能获得实际的 wlan0 接口。

    如果有人遇到错误“wpa_supplicant 无法获取此接口”,请尝试删除 wlan0 文件:/run/wpa_supplicant/wlan0(如果有)

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 2017-10-22
      • 2017-08-19
      • 2011-12-08
      • 2017-05-12
      • 2016-07-14
      • 2016-04-01
      • 2017-09-18
      • 2013-10-16
      相关资源
      最近更新 更多