API Docs

Control and query Wi-Fi interfaces, scan for networks, and watch for Wi-Fi events.

Built on CoreWLAN. Fields that reveal network identity — ssid, bssid, countryCode, and BSSIDs inside scan results — are only populated once Location Services is enabled and the user has authorized this app; call hs.permissions.requestLocation() first (the same gate hs.location uses). Without authorization these fields are null/omitted, not errors.

Types

This module provides the following types:

Properties

hs.wifi.watcherEventTypes

string[]
The Wi-Fi event types that can be passed to `HSWifiWatcher.events`.

Methods

hs.wifi.interfaces() -> string[]

Returns the names of all Wi-Fi interfaces attached to the system (e.g. `["en0"]`).
hs.wifi.interfaces() -> string[]
string[]
an array of interface name strings
console.log(hs.wifi.interfaces())

hs.wifi.interfaceDetails(interface) -> [String: Any]

Returns detailed information about a Wi-Fi interface.
hs.wifi.interfaceDetails(interface) -> [String: Any]
Name Type Description
interface string the interface name as returned by `interfaces()`; omit for the system's default Wi-Fi interface
[String: Any]
a table with keys `interface, active, power, ssid, bssid, security, interfaceMode, activePHYMode, rssi, noise, transmitRate, transmitPower, countryCode, hardwareAddress, wlanChannel, supportedChannels, cachedScanResults, configuration`; or null if the interface doesn't exist. `ssid`/`bssid`/`countryCode`/`wlanChannel` may be absent without Location Services authorization.
const info = hs.wifi.interfaceDetails()
if (info) console.log(info.ssid + " on channel " + info.wlanChannel.number)

hs.wifi.currentNetwork(interface) -> string

Returns the SSID of the network currently joined on an interface.
hs.wifi.currentNetwork(interface) -> string
Name Type Description
interface string the interface name as returned by `interfaces()`; omit for the system's default Wi-Fi interface
string
the SSID string, or null if not joined to a network (or Location Services is not authorized)
console.log(hs.wifi.currentNetwork())

hs.wifi.setPower(state, interface) -> boolean

Turns a Wi-Fi interface on or off.
hs.wifi.setPower(state, interface) -> boolean
Name Type Description
state boolean true to power the interface on, false to power it off
interface string the interface name as returned by `interfaces()`; omit for the system's default Wi-Fi interface
boolean
true if the power state was changed successfully, false if the interface doesn't exist or the change failed (see the Console for the reason)
hs.wifi.setPower(false) // turn Wi-Fi off

hs.wifi.disassociate(interface) -> None

Disconnects an interface from its current network.
hs.wifi.disassociate(interface) -> None
Name Type Description
interface string the interface name as returned by `interfaces()`; omit for the system's default Wi-Fi interface
None
hs.wifi.disassociate()

hs.wifi.associate(ssid, passphrase, interface) -> Promise<boolean>

Scans for a network by SSID and joins it. Enterprise networks are not supported. This can take several seconds; it runs off the main thread so it does not block the app.
hs.wifi.associate(ssid, passphrase, interface) -> Promise<boolean>
Name Type Description
ssid string the SSID of the network to join
passphrase string the network passphrase; required for WEP/WPA/WPA2/WPA3 Personal networks
interface string the interface name as returned by `interfaces()`; omit for the system's default Wi-Fi interface
Promise<boolean>
A Promise that resolves `true` if joined successfully, `false` if no network with that SSID was found, or rejects if the interface doesn't exist or the association attempt fails
hs.wifi.associate("MyNetwork", "hunter2")
    .then(joined => console.log(joined ? "Joined" : "Network not found"))
    .catch(err => console.log("Error: " + err))

hs.wifi.scanNetworks(interface) -> Promise<object[]>

Scans for visible Wi-Fi networks. This can take a few seconds; it runs off the main thread so it does not block the app.
hs.wifi.scanNetworks(interface) -> Promise<object[]>
Name Type Description
interface string the interface name as returned by `interfaces()`; omit for the system's default Wi-Fi interface
Promise<object[]>
A Promise that resolves to an array of network tables, each with keys `ssid, bssid, rssi, noise, ibss, countryCode, beaconInterval, security, phyModes, wlanChannel, informationElementData`; or rejects if the interface doesn't exist or the scan fails. `bssid`/`countryCode` may be absent without Location Services authorization. `informationElementData` is raw beacon/probe-response data returned as an array of byte values (0-255) rather than a string, since it can contain sequences that are unsafe to render as text.
hs.wifi.scanNetworks().then(networks => {
    networks.forEach(n => console.log(n.ssid + " (" + n.rssi + " dBm)"))
})

hs.wifi.addWatcher() -> HSWifiWatcher

Creates a new Wi-Fi event watcher. Call `.setCallback()` and `.start()` to activate it. The watcher is stopped automatically when the module shuts down.
hs.wifi.addWatcher() -> HSWifiWatcher
HSWifiWatcher
an HSWifiWatcher
const w = hs.wifi.addWatcher()
w.setCallback((event, info) => console.log(event, info)).start()