mqtt#

class platypush.plugins.mqtt.MqttPlugin(host=None, port=1883, tls_cafile=None, tls_certfile=None, tls_keyfile=None, tls_version=None, tls_ciphers=None, tls_insecure=False, username=None, password=None, client_id=None, timeout=None, **kwargs)[source]#

Bases: Plugin

This plugin allows you to send custom message to a message queue compatible with the MQTT protocol, see https://mqtt.org/

Requires:

  • paho-mqtt (pip install paho-mqtt)

__init__(host=None, port=1883, tls_cafile=None, tls_certfile=None, tls_keyfile=None, tls_version=None, tls_ciphers=None, tls_insecure=False, username=None, password=None, client_id=None, timeout=None, **kwargs)[source]#
Parameters:
  • host (str) – If set, MQTT messages will by default routed to this host unless overridden in send_message (default: None)

  • port (int) – If a default host is set, specify the listen port (default: 1883)

  • tls_cafile (str) – If a default host is set and requires TLS/SSL, specify the certificate authority file (default: None)

  • tls_certfile (str) – If a default host is set and requires TLS/SSL, specify the certificate file (default: None)

  • tls_keyfile (str) – If a default host is set and requires TLS/SSL, specify the key file (default: None)

  • tls_version (str) – If TLS/SSL is enabled on the MQTT server and it requires a certain TLS version, specify it here (default: None). Supported versions: tls (automatic), tlsv1, tlsv1.1, tlsv1.2.

  • tls_ciphers (str) – If a default host is set and requires TLS/SSL, specify the supported ciphers (default: None)

  • tls_insecure (bool) – Set to True to ignore TLS insecure warnings (default: False).

  • username (str) – If a default host is set and requires user authentication, specify the username ciphers (default: None)

  • password (str) – If a default host is set and requires user authentication, specify the password ciphers (default: None)

  • client_id (str) – ID used to identify the client on the MQTT server (default: None). If None is specified then Config.get('device_id') will be used.

  • timeout (int) – Client timeout in seconds (default: None).

publish(topic: str, msg: Any, host: str | None = None, port: int | None = None, reply_topic: str | None = None, timeout: int = 60, tls_cafile: str | None = None, tls_certfile: str | None = None, tls_keyfile: str | None = None, tls_version: str | None = None, tls_ciphers: str | None = None, tls_insecure: bool | None = None, username: str | None = None, password: str | None = None, qos: int = 0)[source]#

Sends a message to a topic.

Parameters:
  • topic – Topic/channel where the message will be delivered

  • msg – Message to be sent. It can be a list, a dict, or a Message object.

  • host – MQTT broker hostname/IP (default: default host configured on the plugin).

  • port – MQTT broker port (default: default port configured on the plugin).

  • reply_topic – If a reply_topic is specified, then the action will wait for a response on this topic.

  • timeout – If reply_topic is set, use this parameter to specify the maximum amount of time to wait for a response (default: 60 seconds).

  • tls_cafile – If TLS/SSL is enabled on the MQTT server and the certificate requires a certificate authority to authenticate it, ssl_cafile will point to the provided ca.crt file (default: None).

  • tls_certfile – If TLS/SSL is enabled on the MQTT server and a client certificate it required, specify it here (default: None).

  • tls_keyfile – If TLS/SSL is enabled on the MQTT server and a client certificate key it required, specify it here (default: None).

  • tls_version – If TLS/SSL is enabled on the MQTT server and it requires a certain TLS version, specify it here (default: None). Supported versions: tls (automatic), tlsv1, tlsv1.1, tlsv1.2.

  • tls_insecure – Set to True to ignore TLS insecure warnings (default: False).

  • tls_ciphers – If TLS/SSL is enabled on the MQTT server and an explicit list of supported ciphers is required, specify it here (default: None).

  • username – Specify it if the MQTT server requires authentication (default: None).

  • password – Specify it if the MQTT server requires authentication (default: None).

  • qos – Quality of Service (_QoS_) for the message - see MQTT QoS (default: 0).

send_message(*args, **kwargs)[source]#

Alias for platypush.plugins.mqtt.MqttPlugin.publish().