MQTT Historian

Overview

The MQTT Historian agent publishes data to an MQTT broker.

The mqttlistener.py script will connect to the broker and print all messages.

Dependencies

The Paho MQTT library from Eclipse is needed for the agent and can be installed with:

pip install paho-mqtt

The Mosquitto MQTT broker may be useful for testing and can be installed with

apt-get install mosquitto

Configuration

The following is an example configuration file:

{
    "connection: {
        # Optional backup limit in gigabytes. Default is no backup limit.
        # "backup_storage_limit_gb": null,

        # Quality of service level for MQTT publishes. Default is 0.
        # "mqtt_qos": 0,

        # Set messages to be retained. Default is False
        # "mqtt_retain": false,

        # Address of broker to connect to. Default is localhost.
        "mqtt_hostname": "localhost",

        # Port on broker accepting connections. Default is 1883
        "mqtt_port": 1883

        # If a client id is not provided one will be generated by paho-mqtt.
        # Default is an empty string.
        # "mqtt_client_id": "",

        # Keepalive timeout for the client. Default is 60 seconds
        # "mqtt_keepalive": 60,

        # Optional will is published when the client disconnects. Default is None.
        # If used then QOS defaults to 0 and retain defaults to False.
        # "mqtt_will": {
        #     "topic": "<topic>",
        #     "payload":"<payload">,
        #     "qos":<qos>,
        #     "retain":<retain>
        # },

        # MQTT authentication info. Defaults to None.
        # "mqtt_auth": {
        #    "username": "<username>",
        #    "password": "<password>"
        # },

        # MQTT TLS parameters. If used then CA Certs is required. Otherwise the
        # default is None.
        # "mqtt_tls": {
        #     "ca_certs":"<ca_certs>",
        #     "certfile":"<certfile>",
        #     "keyfile":"<keyfile>",
        #     "tls_version":"<tls_version>",
        #     "ciphers":"<ciphers">
        # }

        # Protocol versions MQTTv311 and MQTTv31 are supported. Default is MQTTv311.
        # "mqtt_protocol": "MQTTv311"
    }
}