Skip to content

Using mqtt_test.py to check MQTT

Rich Bell edited this page Nov 28, 2023 · 7 revisions

The mqtt_test.py utility

Deprecated in version 3.0, use https://github.com/bellrichm/WeeWX-MQTTSubscribe/wiki/MQTTSubscribe-Simulator-mode.

This can be retrieved via the command, wget https://github.com/bellrichm/WeeWX-MQTTSubscribe/blob/master/mqtt_test.py

This is a small utility that can help debug problems when running MQTTSubscribe. It reads the WeeWX configuration file (typically weewx.conf) for the necessary MQTT options to connect and subscribe to the topics. As the topic data is received it is written to the console.

The configuration file can actually be stripped down to just the MQTTSubscribeDriver or MQTTSubscribeService stanzas. This allows one to get the MQTT configuration correct prior to configuring WeeWX.

Optionally, the MQTT options can be passed in as parameters. These will override the options in the configuration file. This enables one to quickly and easily determine the correct MQTT options needed.

A few key parameters are --type, --records, and --quiet. The --type controls which stanza, [MQTTSubscribeDriver] or [MQTTSubscribeService] is read. The default us to read from the [MQTTSubscribeDriver] section. The --records controls how many MQTT 'records' are processed. The default is to loop forever. The --quiet option turns off MQTT logging.

Invoke the utility with --help to see all the parameters.

Note: when using the plugin as a service, be sure to pass the commandline option --type=service when invoking the test script. This ensures that the configuration options are parsed from the [MQTTSubscribeService] section.

Getting Started

    Prerequisites
    Required MQTT information
    Required WeeWX information
    Installing MQTTSubscribe
    Configuring MQTTSubscribe
    Running MQTTSubscribe with WeeWX
    Debugging

Common Options

    Main section
    The [[topics]] section
    The [[[message]]] section
    The [[[topic-name]]] section
    The [[[[field-name]]]] section

Additional Options

    Main section
    The [[tls]] section
    The [[topics]] section
    The [[[topic-name]]] section
    The [[[[field-name]]]] section

Date/Time Processing Options

Experimental Options

Configurator Mode

    Environment setup
    Invocation
    Options

Simulator Mode

    Environment setup
    Invocation
    driver simulation options
    service simulation options

Parser Mode

    Environment setup
    Invocation
    Options

Example individual Configuration

Example json Configuration

    Simple json message
    'Nested' json message
    json message with array

Example keyword Configuration

Example Configuration with multiple types

Example unit and unit group customization

FAQ

Debugging
Understanding The log

    Initialization
    MQTT Initialization
    MQTTSubscribeDriver secondary thread processing
    MQTTSubscribeDriver primary thread processing
    MQTTSubscribeService secondary thread processing
    MQTTSubscribeService primary thread processing

Supporting Additional message types
Development Environment
Deprecated Documentation

     Configuring pre 1.6.0
     Options Removed In 2.0.0
     Using test_mqtt.py To Check MQTT
     Running As A driver In Standalone Mode
     Running As A service In Standalone Mode

Clone this wiki locally