hammerspoon2-docs
    Preparing search index...

    Function create

    • Creates an MQTT client. The client doesn't connect until you call its connect() method.

      The server is either a host name, or a URL whose scheme chooses the transport: mqtt:// (TCP, port 1883), mqtts:// (TLS, port 8883), ws:// (WebSocket, port 80) or wss:// (WebSocket over TLS, port 443). A URL may include a port, a username and password (mqtt://user:pass@host), and for WebSockets a path (defaults to /mqtt).

      Parameters

      • server: string

        The broker's host name or URL

      • Optionaloptions:
            | {
                allowUntrustedCertificates?: boolean;
                caCertificate?: string;
                cleanSession?: boolean;
                clientCertificate?: string;
                clientCertificatePassword?: string;
                clientID?: string;
                connectTimeout?: number;
                keepAlive?: number;
                password?: string;
                port?: number;
                reconnectInterval?: number;
                timeout?: number;
                tls?: boolean;
                username?: string;
                version?: "5"
                | "3.1.1";
                websocket?: boolean;
                websocketPath?: string;
                will?: {
                    payload?: string;
                    qos?: 0 | 2 | 1;
                    retain?: boolean;
                    topic: string;
                };
            }
            | null

        Connection options, which override anything given in the URL

        • {
              allowUntrustedCertificates?: boolean;
              caCertificate?: string;
              cleanSession?: boolean;
              clientCertificate?: string;
              clientCertificatePassword?: string;
              clientID?: string;
              connectTimeout?: number;
              keepAlive?: number;
              password?: string;
              port?: number;
              reconnectInterval?: number;
              timeout?: number;
              tls?: boolean;
              username?: string;
              version?: "5" | "3.1.1";
              websocket?: boolean;
              websocketPath?: string;
              will?: {
                  payload?: string;
                  qos?: 0 | 2 | 1;
                  retain?: boolean;
                  topic: string;
              };
          }
          • OptionalallowUntrustedCertificates?: boolean

            true to accept any certificate from the broker. This makes the connection insecure, so use caCertificate instead if you can

          • OptionalcaCertificate?: string

            The CA certificate to trust for the broker instead of the system's, e.g. for a self-signed certificate: the path of a DER or PEM file, or "keychain:<name>" for the certificates stored with hs.keychain.importCertificate() under that name (or else those with that name in your login keychain). Without it, the broker's certificate must be trusted by macOS, which includes CA certificates you've added to your keychain and marked as trusted

          • OptionalcleanSession?: boolean

            false to ask the broker to keep the client's subscriptions and queued messages while it's disconnected. Defaults to true

          • OptionalclientCertificate?: string

            A certificate and private key to identify the client: the path of a PKCS#12 (.p12) file, or "keychain:<name>" for the identity stored with hs.keychain.importIdentity() under that name (or else the one in your login keychain whose certificate has that name)

          • OptionalclientCertificatePassword?: string

            The password for a clientCertificate file

          • OptionalclientID?: string

            The MQTT client identifier. Defaults to "hammerspoon-" followed by eight random characters. Brokers disconnect an existing client when another connects with the same identifier

          • OptionalconnectTimeout?: number

            Seconds to wait for the broker to accept the connection. Defaults to 10

          • OptionalkeepAlive?: number

            Seconds between keep-alive pings. Defaults to 60

          • Optionalpassword?: string

            The password for the broker

          • Optionalport?: number

            The broker's port

          • OptionalreconnectInterval?: number

            Seconds to wait before trying to reconnect when the connection is lost, retrying until disconnect() is called. While the network is unavailable, the client waits for it to return instead. Defaults to 0, which doesn't reconnect

          • Optionaltimeout?: number

            Seconds to wait for the broker to acknowledge a subscribe(), an unsubscribe(), or a publish() with QoS 1 or 2, before its Promise rejects. Defaults to 5

          • Optionaltls?: boolean

            true to connect with TLS

          • Optionalusername?: string

            The username for the broker

          • Optionalversion?: "5" | "3.1.1"

            The MQTT version. Defaults to "3.1.1"

          • Optionalwebsocket?: boolean

            true to connect over a WebSocket

          • OptionalwebsocketPath?: string

            The WebSocket's path. Defaults to /mqtt

          • Optionalwill?: { payload?: string; qos?: 0 | 2 | 1; retain?: boolean; topic: string }

            A message the broker publishes if the client disconnects without calling disconnect()

            • Optionalpayload?: string

              The message. Defaults to an empty one

            • Optionalqos?: 0 | 2 | 1

              Its quality of service. Defaults to 0

            • Optionalretain?: boolean

              true for the broker to retain it. Defaults to false

            • topic: string

              The topic to publish it to

        • null

      Returns HSMQTTClient | null

      A new HSMQTTClient, or null if the server or options are invalid (the reason is logged to the Console)