I would like to control wpa_supplicant using a node.js module. Most importantly I want to be able to detect connection failures so I can write a program that can act upon them.
So far setting up a wireless connection using wpa_supplicant with terminal commands has succeeded. I have tried to access the wlan0 interface using the dbus-native module but have been unable to access the interface.
I am also open to using other existing node modules or write my own if I can be pointed in the right direction.
Would anyone be able to help me advance here?
Code I have tried so far:
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);
});
// wpa_supplicant denies knowledge of the interface
iface.GetInterface('wlan0', function (err, iface2) {
console.log( arguments );
console.log(err, iface2);
});
//error couldn't grab interface
iface.CreateInterface([
['Ifname',
['s', 'wlan0']
]
], function (err, iface3){
console.log(err, iface3);
});
//error couldn't grab interface
iface.CreateInterface([
['Ifname',
['s', 'wlan0']
],
['Driver',
['s', 'nl80211']
],
['ConfigFile',
['s', '~/etc/wpa_supplicant/wpa_supplicant.conf']
]
], function (err, iface3){
console.log(err, iface3);
});
});
Update 1:
I used the DBus properties api to investigate the Interfaces properties and discovered that the the property itself was null.
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;
}
My only conclusion is that the wpa_supplicant never registers any new interfaces with the dbus.
(I have ensured that I set up my wlan0 using wpa_supplicant using terminal commands)
Update 2:
I have continuously tried to figure out why the following part of my code keeps giving me the error:
[ 'wpa_supplicant couldn\'t grab this interface.' ]
iface.CreateInterface([
['Ifname',
['s', 'wlan0']
]
], function (err, iface3){
console.log(err, iface3);
});
dbus-monitor
tool a and see what happens when the connection is going up and down