wpa-wifi
v0.4.4
Published
wpa wifi controller
Downloads
7
Readme
Wpa-wifi
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);
});
API Documention:
WpaCli
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)
new WpaCli(ifName)
constructs WpaCli
| Param | Type | Description | | --- | --- | --- | | ifName | String | interface name eg. wlan0 |
wpaCli.connect()
connect to wpa control interface
Kind: instance method of WpaCli
wpaCli._onConnect()
connect event handler
Kind: instance method of WpaCli
wpaCli._onMessage(msg)
message event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | Buffer | message recieved from wpa_ctrl |
wpaCli._onCtrlEvent(msg)
control event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | control event messages |
wpaCli._onError(err)
error event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | err | String | error message |
wpaCli._onCongestion(err)
congestion event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | err | String | congestion error message |
wpaCli._onListening()
listening event handler
Kind: instance method of WpaCli
wpaCli.sendCmd(msg)
send request to wpa_cli
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | wpa_cli commands |
wpaCli.scan()
scan for wifi AP
Kind: instance method of WpaCli
wpaCli.scanResults()
request for wifi scan results
Kind: instance method of WpaCli
wpaCli._onScanResult(msg)
scan results handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | scan results message |
wpaCli._onRawMsg(msg)
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 |
wpaCli._onListNetwork(msg)
list network handler, list all configured networks or devices
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | network or devices list |
wpaCli.addNetwork()
add new network
Kind: instance method of WpaCli
wpaCli.listNetworks()
request to list networks
Kind: instance method of WpaCli
wpaCli.status()
request for status
Kind: instance method of WpaCli
wpaCli._onStatus(msg)
status handler, parses status messages and emits status event
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | status message |
wpaCli.setSSID(networkId, add)
set network ssid
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | networkId | String | network id recieved from list networks | | add | String | ssid to network |
wpaCli.setPassword(networkId, password)
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 |
wpaCli.enableNetwork(networkId)
enable configured network
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | networkId | string | networkId network id recieved from list networks |
wpaCli.selectNetwork(networkId)
select network to connect
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | networkId | String | networkId network id recieved from list networks |
wpaCli._onApConnected()
AP connected event handler
Kind: instance method of WpaCli
wpaCli._onApDisconnected()
AP disconnect event handler
Kind: instance method of WpaCli
wpaCli.startDhclient()
start dhclient for interface
Kind: instance method of WpaCli
wpaCli.stopDhclient()
stop dhclient for interface
Kind: instance method of WpaCli
wpaCli.disconnectAP()
disconnect from AP
Kind: instance method of WpaCli
wpaCli.peerFind()
search for peers
Kind: instance method of WpaCli
wpaCli.peerList()
list avaliable peers
Kind: instance method of WpaCli
wpaCli.peerStopFind()
stop peer search
Kind: instance method of WpaCli
wpaCli.peerInfo(peerAddress)
fetch Peer Information
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | peerAddress | String | peer device address |
wpaCli.peerConnectPBC(peerAddress, isOwner)
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 |
wpaCli.peerConnectPIN(peerAddress, pin, isOwner)
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 |
wpaCli._onNewPeerFound(msg)
new peer event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | event message |
wpaCli._onPeerDisconnect(msg)
peer disconnection event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | event message |
wpaCli._onPeerInfo(msg)
peer info event handler
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | msg | String | event message |
wpaCli.listInterfaces(callback)
list network interfaces on system
Kind: instance method of WpaCli
| Param | Type | Description | | --- | --- | --- | | callback | function | callback with list of interface |
wpaCli._onPeerConnected()
peer connected handler
Kind: instance method of WpaCli