WpaCli to control wpa_supplicant
Install:
npm install wpa-wifi --save
Note:
This only works on linux, tested on ubuntu 14.4 and debian jesse. you need to have wpa_supplicant installed , run using sudo and running with wpa_spplicant having config : ctrl_interface=/var/run/wpa_supplicant
For More example see test directory for p2p and wifi connection samples. This is a very basic library, it is nessary to write another wrapper over this.
Reference: http://w1.fi/wpa_supplicant/devel/ctrl_iface_page.html
Example: Wifi Connection
'use strict';
const WpaCli = require('wpa-wifi');
var wpa = new WpaCli('wlan0');
wpa.on('ready', function() {
console.log('ready');
wpa.listNetworks();
wpa.addNetwork();
wpa.setSSID(0, 'ssid');
wpa.setPassword(0, 'password');
wpa.enableNetwork(0);
wpa.selectNetwork(0);
});
wpa.connect();
wpa.on('status', function(status) {
console.log(status);
});
wpa.on('scan_results', function(scanResults) {
console.log(scanResults);
});
wpa.on('list_network', function(networks) {
console.log(networks);
});
wpa.on('raw_msg', function(msg) {
console.log(msg);
});
WpaCli to control wpa_supplicant
Kind: global class
- WpaCli
- new WpaCli(ifName)
- .connect()
- .sendCmd(msg)
- .scan()
- .scanResults()
- .addNetwork()
- .listNetworks()
- .status()
- .setSSID(networkId, add)
- .setPassword(networkId, password)
- .enableNetwork(networkId)
- .selectNetwork(networkId)
- .startDhclient()
- .stopDhclient()
- .disconnectAP()
- .peerFind()
- .peerList()
- .peerStopFind()
- .peerInfo(peerAddress)
- .peerConnectPBC(peerAddress, isOwner)
- .peerConnectPIN(peerAddress, pin, isOwner)
- .listInterfaces(callback)
constructs WpaCli
Param | Type | Description |
---|---|---|
ifName | String |
interface name eg. wlan0 |
connect to wpa control interface
Kind: instance method of WpaCli
connect event handler
Kind: instance method of WpaCli
message event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | Buffer |
message recieved from wpa_ctrl |
control event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
control event messages |
error event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
err | String |
error message |
congestion event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
err | String |
congestion error message |
listening event handler
Kind: instance method of WpaCli
send request to wpa_cli
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
wpa_cli commands |
scan for wifi AP
Kind: instance method of WpaCli
request for wifi scan results
Kind: instance method of WpaCli
scan results handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
scan results message |
raw message handler from wpa_cli, captures all messages by default for debuging purposes
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
wpa messages |
list network handler, list all configured networks or devices
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
network or devices list |
add new network
Kind: instance method of WpaCli
request to list networks
Kind: instance method of WpaCli
request for status
Kind: instance method of WpaCli
status handler, parses status messages and emits status event
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
status message |
set network ssid
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
networkId | String |
network id recieved from list networks |
add | String |
ssid to network |
set network password
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
networkId | String |
networkId network id recieved from list networks |
password | String |
add ssid to network |
enable configured network
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
networkId | string |
networkId network id recieved from list networks |
select network to connect
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
networkId | String |
networkId network id recieved from list networks |
AP connected event handler
Kind: instance method of WpaCli
AP disconnect event handler
Kind: instance method of WpaCli
start dhclient for interface
Kind: instance method of WpaCli
stop dhclient for interface
Kind: instance method of WpaCli
disconnect from AP
Kind: instance method of WpaCli
search for peers
Kind: instance method of WpaCli
list avaliable peers
Kind: instance method of WpaCli
stop peer search
Kind: instance method of WpaCli
fetch Peer Information
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
peerAddress | String |
peer device address |
connect to peer with PBC(Push Button Control) authentication mechanism
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
peerAddress | String |
Mac Address of peer |
isOwner | Boolean |
Your role, are you group owner? if yes then true else false |
connect to peer with PIN(password) authentication mechanism
Kind: instance method of WpaCli
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 |
new peer event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
event message |
peer disconnection event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
event message |
peer info event handler
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
msg | String |
event message |
list network interfaces on system
Kind: instance method of WpaCli
Param | Type | Description |
---|---|---|
callback | function |
callback with list of interface |
peer connected handler
Kind: instance method of WpaCli