0.4.4 • Published 8 years ago

wpa-wifi v0.4.4

Weekly downloads
6
License
ISC
Repository
github
Last release
8 years ago

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

new WpaCli(ifName)

constructs WpaCli

ParamTypeDescription
ifNameStringinterface 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

ParamTypeDescription
msgBuffermessage recieved from wpa_ctrl

wpaCli._onCtrlEvent(msg)

control event handler

Kind: instance method of WpaCli

ParamTypeDescription
msgStringcontrol event messages

wpaCli._onError(err)

error event handler

Kind: instance method of WpaCli

ParamTypeDescription
errStringerror message

wpaCli._onCongestion(err)

congestion event handler

Kind: instance method of WpaCli

ParamTypeDescription
errStringcongestion 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

ParamTypeDescription
msgStringwpa_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

ParamTypeDescription
msgStringscan results message

wpaCli._onRawMsg(msg)

raw message handler from wpa_cli, captures all messages by default for debuging purposes

Kind: instance method of WpaCli

ParamTypeDescription
msgStringwpa messages

wpaCli._onListNetwork(msg)

list network handler, list all configured networks or devices

Kind: instance method of WpaCli

ParamTypeDescription
msgStringnetwork 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

ParamTypeDescription
msgStringstatus message

wpaCli.setSSID(networkId, add)

set network ssid

Kind: instance method of WpaCli

ParamTypeDescription
networkIdStringnetwork id recieved from list networks
addStringssid to network

wpaCli.setPassword(networkId, password)

set network password

Kind: instance method of WpaCli

ParamTypeDescription
networkIdStringnetworkId network id recieved from list networks
passwordStringadd ssid to network

wpaCli.enableNetwork(networkId)

enable configured network

Kind: instance method of WpaCli

ParamTypeDescription
networkIdstringnetworkId network id recieved from list networks

wpaCli.selectNetwork(networkId)

select network to connect

Kind: instance method of WpaCli

ParamTypeDescription
networkIdStringnetworkId 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

ParamTypeDescription
peerAddressStringpeer device address

wpaCli.peerConnectPBC(peerAddress, isOwner)

connect to peer with PBC(Push Button Control) authentication mechanism

Kind: instance method of WpaCli

ParamTypeDescription
peerAddressStringMac Address of peer
isOwnerBooleanYour 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

ParamTypeDescription
peerAddressStringMac Address of peer
pinStringpassword for authentication
isOwnerBooleanYour role, are you group owner? if yes then true else false

wpaCli._onNewPeerFound(msg)

new peer event handler

Kind: instance method of WpaCli

ParamTypeDescription
msgStringevent message

wpaCli._onPeerDisconnect(msg)

peer disconnection event handler

Kind: instance method of WpaCli

ParamTypeDescription
msgStringevent message

wpaCli._onPeerInfo(msg)

peer info event handler

Kind: instance method of WpaCli

ParamTypeDescription
msgStringevent message

wpaCli.listInterfaces(callback)

list network interfaces on system

Kind: instance method of WpaCli

ParamTypeDescription
callbackfunctioncallback with list of interface

wpaCli._onPeerConnected()

peer connected handler

Kind: instance method of WpaCli

0.4.4

8 years ago

0.4.3

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.7

8 years ago

0.3.6

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.16

8 years ago

0.1.15

8 years ago

0.1.14

8 years ago

0.1.13

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.1

8 years ago