How to use the node-wifi.scan function in node-wifi

To help you get started, we’ve selected a few node-wifi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alvinwan / riot / test / index.js View on Github external
// Absolutely necessary even to set interface to null
wifi.init({
    iface : null // network interface, choose a random wifi interface if set to null
});

data = {samples: []}

if (process.argv.length <= 2) {
  n = 1
} else {
  n = process.argv[2]
}

for (var i=0; i < n; i++){
// Scan networks
wifi.scan(function(err, networks) {
    if (err) {
        console.log(err);
    } else {
        sample = []
        networks.forEach(function(network) {
            sample.push({mac: network['mac'], signal_level: network['signal_level'], ssid: network['ssid']})
        })
        data['samples'].push(sample)
    }
});
await sleep(5000);
}

var json = JSON.stringify(data)
var fs = require('fs');
fs.writeFile('samples.json', json, 'utf8', function() {});
github alvinwan / riot / scripts / observe.js View on Github external
function startScan(i) {
    var date1 = new Date();
    wifi.scan(function(err, networks) {
        if (err || networks.length == 0) {
          console.log(" * [ERR] Failed to collect " + i + ". Waiting for a second before retrying... (" + err + ")")
          utils.sleep(1000)
          startScan(i);
          return
        }
        console.log(" * [INFO] Collected sample " + i + " with " + networks.length + " networks in " + ( (new Date() - date1) / 1000 ) + "s")
        samples.push(networks)
        hook(i, networks);
        if (i <= 1) return completion({samples: samples});
        startScan(i-1);
    });
  }
github ruslang02 / atomos / apps / official / settings / sections / network-wlan.js View on Github external
async function listNetworks() {
		networkList.innerHTML = "";
		let networks = await wifi.scan().catch(err => {
			console.error(err);
			new Snackbar("We couldn't list available networks, check console.");
		}) || [];
		for (const hs of networks) {
			if (connectedSSIDs.includes(hs.ssid)) continue;
			let elem = document.createElement("button");
			let strength = Math.ceil(hs.quality / 25);
			let again = false;
			elem.onclick = async function () {
				if (!!hs.security.trim()) {
					let message = document.createElement("div");
					message.lead = document.createElement("p");
					message.lead.className = "mb-2";
					message.lead.innerHTML = `Network "${hs.ssid}" is secured. Enter hotspot's password.` +
						(again ? "<br><div class="text-danger">Check the password you entered.</div>" : "");
					message.pass = document.createElement("input");
github alvinwan / riot / tutorial / observe-step2.js View on Github external
function startScan(i) {
    wifi.scan(function(err, networks) {
        if (err || networks.length == 0) {
          startScan(i);
          return
        }
        if (i &lt;= 0) {
          return completion({samples: samples});
        }
        hook(i, networks)
        samples.push(networks)
        startScan(i-1);
    });
  }