EMQX Broker writing

    The following preparations are required for EMQX to add TDengine data sources correctly.

    • The TDengine cluster is deployed and working properly
    • taosAdapter is installed and running properly. Please refer to the for details.
    • If you use the emulated writers described later, you need to install the appropriate version of Node.js. V12 is recommended.

    Install and start EMQX

    Depending on the current operating system, users can download the installation package from the and execute the installation. After installation, use or sudo systemctl start emqx to start the EMQX service.

    Note: this chapter is based on EMQX v4.4.5. Other version of EMQX probably change its user interface, configuration methods or functions.

    In this step we create the appropriate database and table schema in TDengine for receiving MQTT data. Open TDengine CLI and execute SQL bellow:

    Configuring EMQX Rules

    Since the configuration interface of EMQX differs from version to version, here is v4.4.5 as an example. For other versions, please refer to the corresponding official documentation.

    Use your browser to open the URL http://IP:18083 and log in to EMQX Dashboard. The initial installation username is admin and the password is: public.

    Creating Rule

    Select “Rule” in the “Rule Engine” on the left and click the “Create” button: !

    TDengine Database EMQX rule engine

    1. SELECT
    2. payload
    3. FROM

    Add “action handler”

    TDengine Database EMQX add action handler

    Select “Data to Web Service” and click the “New Resource” button.

    Edit “Resource”

    Select “WebHook” and fill in the request URL as the address and port of the server running taosAdapter (default is 6041). Leave the other properties at their default values.

    TDengine Database EMQX edit resource

    Edit the resource configuration to add the key/value pairing for Authorization. If you use the default TDengine username and password then the value of key Authorization is:

    Please refer to the for the authorization in details.

    Enter the rule engine replacement template in the message body:

    1. INSERT INTO test.sensor_data VALUES(
    2. now,
    3. ${payload.temperature},
    4. ${payload.volume},
    5. ${payload.PM10},
    6. ${payload.pm25},
    7. ${payload.NO2},
    8. ${payload.CO},
    9. '${payload.id}',
    10. ${payload.area},
    11. ${payload.ts}
    12. )

    Finally, click the “Create” button at bottom left corner saving the rule.

    Note: CLIENT_NUM in the code can be set to a smaller value at the beginning of the test to avoid hardware performance be not capable to handle a more significant number of concurrent clients.

    Execute tests to simulate sending MQTT data

    1. node mock.js

    TDengine Database EMQX run mock

    Refresh the EMQX Dashboard rules engine interface to see how many records were received correctly:

    Verify that data writing to TDengine

    Use the TDengine CLI program to log in and query the appropriate databases and tables to verify that the data is being written to TDengine correctly:

    TDengine Database EMQX result in taos