wpa-ctrl v1.1.2
WpaCtrl
WpaCtrl to control wpa_supplicant
npm install wpa-ctrl --save
This only works on linux, tested on Debian stretch. You need to have wpa_supplicant
installed and run as a user in the
netdev
group.
For more examples, see the test directory for p2p and wifi connection samples. This is a very basic library, it is nessary to write another wrapper over this.
Kind: global class
Emits: WpaCtrl#event:raw_msg, WpaCtrl#event:response, WpaCtrl#event:CTRL-REQ, WpaCtrl#event:P2P-DEVICE-FOUND, WpaCtrl#event:P2P-DEVICE-LOST, WpaCtrl#event:P2P-GROUP-STARTED, WpaCtrl#event:P2P-INVITATION-RECEIVED, WpaCtrl#event:CTRL-EVENT-CONNECTED, WpaCtrl#event:CTRL-EVENT-DISCONNECTED
See: http://w1.fi/wpa_supplicant/devel/ctrl_iface_page.html for full documentation of the commands that can be sent
and events that can be emitted.
- WpaCtrl
- new WpaCtrl(ifName, [ctrlPath])
- .connect() ⇒ Promise
- .close()
- .sendCmd(msg) ⇒ Promise
- .scan() ⇒ Promise
- .scanResults() ⇒ Promise
- .addNetwork() ⇒ Promise
- .listNetworks() ⇒ Promise
- .status() ⇒ Promise
- .setNetworkVariable(networkId, variable, value) ⇒ Promise
- .setNetworkSSID(networkId, ssid) ⇒ Promise
- .setNetworkPreSharedKey(networkId, preSharedKey, ssid) ⇒ Promise
- .setNetworkIdentity(networkId, identity) ⇒ Promise
- .setNetworkPassword(networkId, password) ⇒ Promise
- .enableNetwork(networkId) ⇒ Promise
- .selectNetwork(networkId) ⇒ Promise
- .saveConfig() ⇒ Promise
- .reconfigure() ⇒ Promise
- .reassociate() ⇒ Promise
- .disconnectAP() ⇒ Promise
- .peerFind() ⇒ Promise
- .peerStopFind() ⇒ Promise
- .peerInfo(peerAddress) ⇒ Promise
- .peerConnectPBC(peerAddress, isOwner) ⇒ Promise
- .peerConnectPIN(peerAddress, pin, isOwner) ⇒ Promise
- .listInterfaces() ⇒ Promise
- .removeVitualInterface(iFaceName, callback) ⇒ Promise
- .flushPeers() ⇒ Promise
new WpaCtrl(ifName, ctrlPath)
constructs WpaCtrl
Param | Type | Default | Description |
---|---|---|---|
ifName | string | interface name eg. wlan0 | |
ctrlPath | string | "'/run/wpa_supplicant'" | The location of the wpa_supplicant control interface. |
Example (Scan for SSIDs and connect to an wireless network.)
'use strict';
const WpaCtrl = require('wap-ctrl');
let wpa = new WpaCtrl('wlan0');
wpa.on('raw_msg', function(msg) {
console.log(msg);
});
wpa.connect().then(function () {
console.log('ready');
return wpa.listNetworks();
}).then(function (networks) {
console.log(networks);
return wpa.scan();
}).then(function (accessPoints) {
console.log(accessPoints);
wpa.addNetwork();
wpa.setNetworkSSID(0, 'ssid');
wpa.setNetworkPreSharedKey(0, 'password');
wpa.enableNetwork(0);
return wpa.selectNetwork(0);
}).then(function () {
wpa.close();
}).catch(function (err) {
console.log(err);
});
wpaCtrl.connect() ⇒ Promise
connect to wpa control interface
Kind: instance method of WpaCtrl
wpaCtrl.close()
close the wpa control interface
Kind: instance method of WpaCtrl
wpaCtrl.sendCmd(msg) ⇒ Promise
send request to wpa_supplicant control interface
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
msg | string | wpa_supplicant commands |
wpaCtrl.scan() ⇒ Promise
scan for wifi AP
Kind: instance method of WpaCtrl
wpaCtrl.scanResults() ⇒ Promise
request for wifi scan results
Kind: instance method of WpaCtrl
wpaCtrl.addNetwork() ⇒ Promise
add new network
Kind: instance method of WpaCtrl
wpaCtrl.listNetworks() ⇒ Promise
request to list networks
Kind: instance method of WpaCtrl
wpaCtrl.status() ⇒ Promise
request for status
Kind: instance method of WpaCtrl
wpaCtrl.setNetworkVariable(networkId, variable, value) ⇒ Promise
set network variable
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | network id recieved from list networks |
variable | string | variable to set |
value | string | value for the variable |
wpaCtrl.setNetworkSSID(networkId, ssid) ⇒ Promise
set network ssid
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | network id recieved from list networks |
ssid | string | ssid of the network |
wpaCtrl.setNetworkPreSharedKey(networkId, preSharedKey, ssid) ⇒ Promise
set network pre-shared key
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | networkId network id recieved from list networks |
preSharedKey | string | pre-shared key |
ssid | string | ssid of the network |
wpaCtrl.setNetworkIdentity(networkId, identity) ⇒ Promise
set network identity
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | network id recieved from list networks |
identity | string | identity string for EAP |
wpaCtrl.setNetworkPassword(networkId, password) ⇒ Promise
set network password
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | network id recieved from list networks |
password | string | password string for EAP |
wpaCtrl.enableNetwork(networkId) ⇒ Promise
enable configured network
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | networkId network id recieved from list networks |
wpaCtrl.selectNetwork(networkId) ⇒ Promise
select network to connect
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
networkId | number | networkId network id recieved from list networks |
wpaCtrl.saveConfig() ⇒ Promise
save the current configuration
Kind: instance method of WpaCtrl
wpaCtrl.reconfigure() ⇒ Promise
reload the configuration from disk
Kind: instance method of WpaCtrl
wpaCtrl.reassociate() ⇒ Promise
Force reassociation
Kind: instance method of WpaCtrl
wpaCtrl.disconnectAP() ⇒ Promise
disconnect from AP
Kind: instance method of WpaCtrl
wpaCtrl.peerFind() ⇒ Promise
search for peers
Kind: instance method of WpaCtrl
wpaCtrl.peerStopFind() ⇒ Promise
stop peer search
Kind: instance method of WpaCtrl
wpaCtrl.peerInfo(peerAddress) ⇒ Promise
fetch Peer Information
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
peerAddress | string | peer device address |
wpaCtrl.peerConnectPBC(peerAddress, isOwner) ⇒ Promise
connect to peer with PBC(Push Button Control) authentication mechanism
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
peerAddress | string | Mac Address of peer |
isOwner | Boolean | Your role, are you group owner? if yes then true else false |
wpaCtrl.peerConnectPIN(peerAddress, pin, isOwner) ⇒ Promise
connect to peer with PIN(password) authentication mechanism
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
peerAddress | string | Mac Address of peer |
pin | string | password for authentication |
isOwner | Boolean | Your role, are you group owner? if yes then true else false |
wpaCtrl.listInterfaces() ⇒ Promise
list network interfaces on system
Kind: instance method of WpaCtrl
wpaCtrl.removeVitualInterface(iFaceName, callback) ⇒ Promise
Remove virtual interface eg: p2p-p2p0-1
Kind: instance method of WpaCtrl
Param | Type | Description |
---|---|---|
iFaceName | string | interface name |
callback | function | callback function |
wpaCtrl.flushPeers() ⇒ Promise
Flush peer data
Kind: instance method of WpaCtrl