Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Scanning for networks and running appear event (only once though)

  • Loading branch information...
commit 132b03187422f607958c72036da8e62f259e6ab1 1 parent 7297480
@tlhunter authored
Showing with 22 additions and 13 deletions.
  1. +4 −10 app.js
  2. +18 −3 node_modules/wireless/index.js
View
14 app.js
@@ -4,10 +4,11 @@ var _ = require('underscore');
wireless.configure({
commands: {
- scan: 'cat examples/iwlist-wlan0-scan.txt',
- stat: 'cat examples/iwconfig-wlan0.txt',
+ scan: 'sudo iwlist :INTERFACE scan',
+ stat: 'sudo ifconfig :INTERFACE',
},
- iface: 'wlan0'
+ iface: 'wlan0',
+ updateFrequency: 10,
});
wireless.on('appear', function(error, network) {
@@ -36,10 +37,3 @@ wireless.start(function() {
console.log("I've connected to the fifth network!");
});
});
-
-fs.readFile('examples/downtown.txt', function(err, data) {
- if (err) throw err;
- var content = data.toString();
- var networks = wireless.parse(content);
- console.log(networks);
-});
View
21 node_modules/wireless/index.js
@@ -1,6 +1,7 @@
var util = require('util');
var events = require('events');
var _ = require('underscore');
+var exec = require('child_process').exec;
// gonna require some sys or child_process stuff for executing nix commands
var Wireless = function() {
@@ -17,9 +18,13 @@ var Wireless = function() {
updateFrequency: 10,
// What commands to execute
commands: {
+ scan: 'iwlist :INTERFACE',
+ stat: 'iwconfig :INTERFACE',
+ },
+ realCommands: {
scan: 'iwlist wlan0',
stat: 'iwconfig wlan0',
- },
+ }
};
// Bind us some event listeners!
@@ -31,12 +36,22 @@ var Wireless = function() {
self.configure = function(config) {
// should actually be a merge
self.configuration = config;
+
+ self.configuration.realCommands = {
+ scan: self.configuration.commands.scan.replace(':INTERFACE', self.configuration.iface),
+ stat: self.configuration.commands.stat.replace(':INTERFACE', self.configuration.iface),
+ };
};
// Start listening
self.start = function(callback) {
- self.emit('appear', false, {ssid: 'test'});
-
+ exec(self.configuration.realCommands.scan, function(err, stdout, stderr) {
+ var content = stdout.toString();
+ var networks = self.parse(content);
+ _.each(networks, function(network) {
+ self.emit('appear', false, network);
+ });
+ });
};
// Stop listening
Please sign in to comment.
Something went wrong with that request. Please try again.