ReadonlyclientThe MQTT client identifier sent to the broker. Unless you chose one with the clientID option, it is "hammerspoon-" followed by eight random characters.
ReadonlyhostThe host name of the broker.
ReadonlyidentifierThe unique identifier of this client object.
ReadonlyisWhether the client is connected to the broker.
ReadonlyportThe port of the broker.
ReadonlystateThe client's connection state: "disconnected", "connecting", "connected", "reconnecting" (the connection was lost and the client is trying to restore it, see the reconnectInterval option) or "disconnecting".
ReadonlysubscriptionsThe topic filters this client has subscribed to, and the QoS level requested for each. These are restored automatically when the client reconnects.
Connects to the broker.
A Promise resolving once the broker has accepted the connection, to true if the broker resumed a previous session for this client (see the cleanSession option), or false if it started a new one
Disconnects from the broker, removes all listeners and releases the client. It can't be used again afterwards. Called automatically when Hammerspoon reloads its configuration.
Disconnects from the broker. This also stops a client that is reconnecting from trying again.
A Promise resolving once the client has disconnected
Remove a previously registered listener for this client's events.
The event the listener was registered for
The function originally passed to on
Register a listener for this client's events.
Listeners receive:
"connected": (), each time the client connects, including when it reconnects by itself"disconnected": (reason), null when you called disconnect(), otherwise a description of why the connection was lost"message": (message), an object with the message's topic, its payload decoded as UTF-8, its raw bytes (a Uint8Array), its qos, and whether it is retained and a duplicateA client with listeners stays alive until you remove them or call destroy().
The event to listen for
Called when the event occurs
Register a listener that fires at most once for one of this client's events.
The event to listen for
Called once, then automatically removed
Publishes a message.
The topic to publish to
The message, sent as UTF-8. Use JSON.stringify() to send an object
Optionaloptions: { qos?: 0 | 2 | 1; retain?: boolean }
The QoS level to send the message with (default 0), and whether the broker should keep it as the topic's retained message (default false)
A Promise resolving once the message has been sent (QoS 0) or the broker has acknowledged it (QoS 1 and 2)
Subscribes to a topic filter, so messages published to matching topics arrive as "message" events.
The topic, which may contain the wildcards + (one level) and # (all remaining levels)
Optionalqos: 0 | 2 | 1
The highest QoS level to receive messages with. Defaults to 0
A Promise resolving to the QoS level the broker granted, which may be lower than requested. It rejects if the broker refuses the subscription
Unsubscribes from a topic filter.
The topic filter originally passed to subscribe()
A Promise resolving once the broker has acknowledged the request
A connection to an MQTT broker, created by
hs.mqtt.create().The client does nothing until you call
connect(). Messages for the topics yousubscribe()to arrive as"message"events (seeon()).A connected client keeps working after you drop your reference to it, until you call
disconnect()ordestroy(), or Hammerspoon reloads its configuration. So does a client with listeners registered byon().