forked from clehner/wpa_state
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwpa_cli.js
38 lines (30 loc) · 1.02 KB
/
wpa_cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var wpa = require('./');
var handle = new wpa('wlan1');
handle.connect();
handle.on('event-3', function (evt) { // Log all the level 3 messages
console.log(evt);
});
function addNetwork() {
handle.addNetwork({ssid: 'MySuperNetwork', psk: 'password123'}, function (err, newId) {
if (err) {
console.error(err);
return false;
}
console.log('New network id:', newId);
handle.enableNetwork(newId, function (status) {
console.log('Enable status:', status);
handle.removeNetwork(newId, function (status) {
if (status === 'OK')
console.log('Network removed');
else
console.log('Could not remove the network ', newId);
})
});
});
}
handle.scan(function () {
handle.getScanResults(function (err, data) {
console.log(err, data);
addNetwork(); // I made a separate function just not to add all of the code above in this callback.
});
});