ReadonlyadvertisementThe peripheral's last advertisement, if a scan has seen one, otherwise null.
The object has localName (string or null), isConnectable (boolean or null), txPower (number or null), serviceUUIDs (string[]), manufacturerData (Uint8Array or null) and serviceData (an object mapping service UUIDs to Uint8Array).
ReadonlybatteryThe battery level last read by readBatteryLevel(), as a percentage, or null if it hasn't been read.
ReadonlyidentifierThe peripheral's identifier, a UUID that macOS assigns in place of its Bluetooth address, which it doesn't reveal. It is stable on this Mac, but differs between Macs.
ReadonlyisWhether Hammerspoon is connected to the peripheral.
ReadonlylastWhen the peripheral was last seen, in Unix seconds: in a scan, or while connected. null if unknown.
ReadonlynameThe peripheral's name, or null if it hasn't reported one.
ReadonlyrssiThe last known signal strength in dBm, or null if there is none. It is updated by hs.bluetooth.scan() and readRSSI().
ReadonlytypeThe type name for JavaScript introspection. Always "HSBluetoothPeripheral".
Connects Hammerspoon to the peripheral, so its GATT services can be used. It stays connected until disconnect() is called, even if you drop your reference to it.
A Promise resolving to this peripheral once it's connected, or rejecting if the connection fails or takes longer than 20 seconds
Disconnects Hammerspoon from the peripheral. If macOS has its own connection to it (e.g. a paired keyboard), that connection stays.
A Promise resolving to this peripheral once it's disconnected
Discovers the characteristics of one of a connected peripheral's GATT services.
The service UUID: 16-bit ("180F"), 32-bit, or 128-bit
A Promise resolving to the service's characteristics. properties lists what each supports: "read", "write", "writeWithoutResponse", "notify", "indicate", "broadcast", "authenticatedSignedWrites" and "extendedProperties"
Discovers the GATT services of a connected peripheral.
A Promise resolving to the UUIDs of the peripheral's services, e.g. ["180A", "180F"]
Remove a previously registered listener for this peripheral's events.
The event the listener was registered for
The function originally passed to on
Register a listener for this peripheral's events. A peripheral with listeners keeps working after you drop your reference to it.
The event to listen for
Called when the event occurs
Register a listener that fires at most once for one of this peripheral's events.
The event to listen for
Called once, then automatically removed
Reads the peripheral's battery level from its standard GATT Battery service. The peripheral must be connected.
A Promise resolving to the battery percentage, or null if the peripheral has no Battery service
Reads the current signal strength of a connected peripheral.
A Promise resolving to the signal strength in dBm, or rejecting if the peripheral isn't connected
Reads the value of a GATT characteristic of a connected peripheral. The service and characteristic are discovered first if needed.
The service UUID, e.g. "180F"
The characteristic UUID, e.g. "2A19"
A Promise resolving to the characteristic's value
Subscribes to a GATT characteristic of a connected peripheral, so each new value is delivered as a "value" event (see on()).
The service UUID
The characteristic UUID, which must support "notify" or "indicate"
A Promise resolving once the peripheral has started sending values
Returns a plain object describing this peripheral, for JSON serialisation
JSON.stringify() calls this automatically, so you rarely need to call it yourself.
An object with the peripheral's identifier, name, isConnected, rssi, lastSeen and batteryLevel
Stops a subscription started by subscribe().
The service UUID
The characteristic UUID
A Promise resolving once the peripheral has stopped sending values
Writes the value of a GATT characteristic of a connected peripheral. Writes to one characteristic are sent in the order they're made.
The service UUID
The characteristic UUID
The bytes to write. A string is written as UTF-8
Optionaloptions: { withoutResponse?: boolean }With withoutResponse: true, write without asking the peripheral to confirm it, which is faster but can't tell whether it arrived. Defaults to false
A Promise resolving once the peripheral has accepted the write (or, without a response, once it has been sent)
A Bluetooth Low Energy (BLE) peripheral, found by
hs.bluetooth.scan()or through a paired device'slowEnergyPeripheral(). Obtain peripherals from thehs.bluetoothmodule; do not instantiate them directly. A peripheral is identified by itsidentifier, and the same peripheral is returned as the same object for as long as you hold on to it. Callconnect()before using its GATT services. A connected peripheral stays connected, and keeps delivering its events, until you calldisconnect(), even if you drop your reference to it.