platypush.plugins.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, username=None, password=None, **kwargs)[source]

This plugin allows you to send custom message to a message queue compatible with the MQTT protocol, see http://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, username=None, password=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 a default host is set and requires TLS/SSL, specify the minimum TLS supported version (default: None)
  • tls_ciphers (str) – If a default host is set and requires TLS/SSL, specify the supported ciphers (default: None)
  • 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)
publish(topic: str, msg: Any, host: Optional[str] = None, port: int = 1883, reply_topic: Optional[str] = None, timeout: int = 60, tls_cafile: Optional[str] = None, tls_certfile: Optional[str] = None, tls_keyfile: Optional[str] = None, tls_version: Optional[str] = None, tls_ciphers: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None)[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.
  • port – MQTT broker port (default: 1883).
  • 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).
  • 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).
send_message(*args, **kwargs)[source]

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