
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@loofkid/pi-wifi
Advanced tools
The purpose of this module is to provide tools to connect to a Wifi
On your project root execute:
$ npm install --save pi-wifi
The following is the list of functions available:
The check function is used to return the state of the network with the specified ssid
var piWifi = require('pi-wifi');
piWifi.check('myTestNetwork', function(err, result) {
if (err) {
return console.error(err.message);
}
console.log(result);
});
// => If everything is working
// { selected: true, connected: true, ip: '192.168.0.12' }
// => Alternatively
// { selected: false, connected: false }
The connectTo function is used to connect to a network with the parameters specified (This can connect to open and secure networks including 802.1x)
The details object can contain the following:
var piWifi = require('pi-wifi');
var networkDetails = {
ssid: 'MyNetwork',
username: 'demo',
password: 'swordfish'
};
//A simple connection
piWifi.connectTo(networkDetails, function(err) {
if(!err) {
console.log('Network created successfully!');
} else {
console.log(err.message); //Failed to connect
}
});
//After creating a succesful connection, you could use the function check to verify
var ssid = 'MyOpenNetwork';
piWifi.connectTo({ssid: ssid}}, function(err) {
if (!err) { //Network created correctly
setTimeout(function () {
piwifi.check(ssid, function (err, status) {
if (!err && status.connected) {
console.log('Connected to the network ' + ssid + '!');
} else {
console.log('Unable to connect to the network ' + ssid + '!');
}
});
}, 2000);
} else {
console.log('Unable to create the network ' + ssid + '.');
}
});
The connectToId function is used enables the network, saves the configuration and then select the network with the id provided
var piWifi = require('pi-wifi');
piWifi.connectToId(2, function(err) {
if (err) {
return console.error(err.message);
}
console.log('Successful connection!');
});
The connect function is used to connect to a network with the ssid specified using the password provided (Avoid using this as it is only for backwards compatibility and may be deprecated in the future)
var piWifi = require('pi-wifi');
piWifi.connect('myTestNetwork', 'MyTestPassword', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Successful connection!');
});
The connectOpen function is used to connect to an open network with the ssid specified (Avoid using this as it is only for backwards compatibility and may be deprecated in the future)
var piWifi = require('pi-wifi');
piWifi.connectOpen('myTestNetwork', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Successful connection!');
});
The connectEAP function is used to connect to a network with the ssid specified using the password provided (Avoid using this as it is only here for consistency and may be deprecated in the future)
var piWifi = require('pi-wifi');
piWifi.connectEAP('myTestNetwork', 'MyTestUsername', 'MyTestPassword', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Successful connection!');
});
The disconnect function is used to disconnect from the network on the current interface
var piWifi = require('pi-wifi');
piWifi.disconnect(function(err) {
if (err) {
return console.error(err.message);
}
console.log('Disconnected from network!');
});
The detectSupplicant function is used to look for a running wpa_supplicant process and if found returns the config file and interface used
var piWifi = require('pi-wifi');
piWifi.detectSupplicant(function(err, iface, configFile) {
if (err) {
return console.error(err.message);
}
console.log('Supplicant running in interface', iface, 'using the configuration file', configFile);
});
The interfaceDown function is used to drop the interface provided
var piWifi = require('pi-wifi');
piWifi.interfaceDown('wlan0', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Interface dropped succesfully!');
});
The interfaceUp function is used to raise the interface provided
var piWifi = require('pi-wifi');
piWifi.interfaceUp('wlan0', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Interface raised succesfully!');
});
The killSupplicant function is used to kill the supplicant process for the specified interface
var piWifi = require('pi-wifi');
piWifi.killSupplicant('wlan0', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Supplicant process terminated!');
});
The listInterfaces function is used to list the available network interfaces' names
var piWifi = require('pi-wifi');
piWifi.listInterfaces(function(err, interfacesArray) {
if (err) {
return console.error(err.message);
}
console.log(interfacesArray);
});
// =>
// ['wlan0', 'wlan1']
The listNetworks function is used to list the networks in an array, each network has Network ID, SSID, BSSID and FLAGS
var piWifi = require('pi-wifi');
piWifi.listNetworks(function(err, networksArray) {
if (err) {
return console.error(err.message);
}
console.log(networksArray);
});
// =>
// [{ network_id: 0, ssid: 'MyNetwork', bssid: 'any', flags: '[DISABLED]' },
// { network_id: 1, ssid: 'Skynet', bssid: 'any', flags: '[CURRENT]' }]
The restartInterface function is used to restart the interface provided
var piWifi = require('pi-wifi');
piWifi.restartInterface('wlan0', function(err) {
if (err) {
return console.error(err.message);
}
console.log('Interface restarted succesfully!');
});
The scan function is used to scan available wifi networks
var piWifi = require('pi-wifi');
piWifi.scan(function(err, networks) {
if (err) {
return console.error(err.message);
}
console.log(networks);
});
// =>
//[
// { bssid: 'aa:bb:cc:dd:ee:ff',
// frequency: 2462,
// signalLevel: -40,
// flags: '[WPA2-PSK-CCMP][WPS][ESS]',
// ssid: 'MyNetwork' },
// { bssid: '11:22:33:44:55:66',
// frequency: 2462,
// signalLevel: -28,
// flags: '[WPA2-PSK-CCMP][ESS]',
// ssid: 'AnotherNetwork' },
// { bssid: 'aa:11:bb:22:cc:33',
// frequency: 2462,
// signalLevel: -33,
// flags: '[WPA2-EAP-CCMP-preauth][WPS][ESS]',
// ssid: 'MyEnterpriseNetwork' },
// { bssid: 'c0:56:27:44:3b:9c',
// frequency: 2412,
// signalLevel: -59,
// flags: '[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]',
// ssid: 'MyGuestsNetwork'
// }
//]
The setCurrentInterface function is used to specify the interface to use as default
var piWifi = require('pi-wifi');
piWifi.setCurrentInterface('wlan1');
piWifi.status('wlan0', function(err, status) {
if (err) {
return console.error(err.message);
}
console.log(status);
});
The startSupplicant function is used to start a wpa_supplicant instance
var piWifi = require('pi-wifi');
piWifi.startSupplicant({iface: 'wlan0', config: '/etc/wpa_supplicant/wpa_supplicant.conf', dns: '/etc/resolv.conf'}, function(err, networks) {
if (err) {
return console.error(err.message);
}
console.log('Supplicant instance successfully started!');
});
The status function is used to show status parameters of the interface specified, if no interface is provided the selected one is used
var piWifi = require('pi-wifi');
piWifi.status('wlan0', function(err, status) {
if (err) {
return console.error(err.message);
}
console.log(status);
});
// =>
//{
// bssid: '2c:f5:d3:02:ea:d9',
// frequency: 2412,
// mode: 'station',
// key_mgmt: 'wpa2-psk',
// ssid: 'MyNetwork',
// pairwise_cipher: 'CCMP',
// group_cipher: 'CCMP',
// p2p_device_address: 'aa:bb:cc:dd:ee:ff',
// wpa_state: 'COMPLETED',
// ip: '10.20.30.40',
// mac: 'a1:b2:c3:d4:e5:f6',
// uuid: 'e1cda789-8c88-53e8-ffff-31c304580c22',
// id: 0
//}
Tested on Raspberry Pi 3
FAQs
Module for accessing wpa_cli on Raspberry Pi 3.
The npm package @loofkid/pi-wifi receives a total of 2 weekly downloads. As such, @loofkid/pi-wifi popularity was classified as not popular.
We found that @loofkid/pi-wifi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.