How to use node-wifi - 10 common examples

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 / test / index.js View on Github external
async function demo() {

// Initialize wifi module
// 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);
github alvinwan / riot / scripts / observe.js View on Github external
async function record(n=1, completion=function(data) {}, hook=function(i, sample) {}) {
  console.log(" * [INFO] Starting to listen")
  wifi.init({
      iface : null // network interface, choose a random wifi interface if set to null
  });

  samples = []
  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);
github alvinwan / riot / tutorial / observe-step2.js View on Github external
function record(n, completion, hook) {
  wifi.init({
      iface : null // network interface, choose a random wifi interface if set to null
  });

  samples = []
  function startScan(i) {
    wifi.scan(function(err, networks) {
        if (err || networks.length == 0) {
          startScan(i);
          return
        }
        if (i <= 0) {
          return completion({samples: samples});
        }
        hook(i, networks)
        samples.push(networks)
        startScan(i-1);
github blahsd / snwe / app / js / require / modules / wifi.js View on Github external
constructor(filePath, document) {
    super(filePath, document);
    this.container = 'right';

    this.isOn = false;
    this.isConnected = false;
    this.isConnecting = true;
    this.network = false;

    wifi.init({
      iface: null // network interface, choose a random wifi interface if set to null
    });

  }
github jeeliz / jetsonjs / server / wrappers / WifiNetworkManager.js View on Github external
const connect=(networkDetails, callback)=>{
	// Connect to a network
	wifi.connect(networkDetails, (err) => {
	    if (err) {
	        console.log('WARNING in Wifi.js - connect(): connection fails', err.message)
	  		callback(err, false)
	  		return
	    }
	    console.log('INFO in Wifi.js - connect() : connected successfully')
	    get_status((err, status)=>{
	    	if (err) {
	    		callback(err, false)
	    	} else {
	    		save_config(networkDetails, callback.bind(null,false, status))
	    	}
	    })
	})
}
github blahsd / snwe / app / js / require / modules / wifi.js View on Github external
updateStatus() {
    wifi.getCurrentConnections((err, currentConnections) => {
      try {
        if (currentConnections[0].ssid.length <= 1) {
          // Is connecting
          this.isOn = false;
          this.isConnected = false;
          this.isConnecting = true;
          this.network = "Connecting...";
        } else {
          this.isOn = true;
          this.isConnected = true;
          this.isConnecting = false;
          this.network = currentConnections[0].ssid;
        }
      } catch (e) {
        // If no currentConnections are returned, it must mean we're disconnected and not in the process of connecting to anything
        this.isOn = false;
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 ruslang02 / atomos / apps / official / settings / sections / network-wlan.js View on Github external
async function listConnectedNetworks() {
		connectedList.innerHTML = "";
		connectedSSIDs = [];
		let networks = await wifi.getCurrentConnections().catch(err => {
			console.error(err);
			new Snackbar("We couldn't list connected networks, check console.");
		}) || [];
		for (const hs of networks) {
			connectedSSIDs.push(hs.ssid);
			let elem = document.createElement("div");
			let strength = Math.ceil(hs.quality / 25);
			elem.className = "rounded-0 flex-shrink-0 d-flex align-items-center text-left pb-2 pt-1 mb-0 px-3 " + (Shell.ui.darkMode ? " text-white border-secondary" : "");
			elem.icon = document.createElement("button");
			elem.icon.className = "mdi mdi-24px border-0 rounded-max text-white d-flex p-2 lh-24 my-1 mr-2 btn btn-primary mdi-wifi-strength-" + strength;
			elem.icon.onmouseup = () => {
				new Menu([{
					icon: "information-outline",
					label: "Properties",
					click() {
						Shell.showMessageBox({