Webinar
Unifying Data from Vehicle to Cloud | Register Now →

Boosting Development Efficiency: MQTTX 1.9.3 Introduces Powerful IoT Scenario Data Simulation

MQTTX Team
May 29, 2023
Boosting Development Efficiency: MQTTX 1.9.3 Introduces Powerful IoT Scenario Data Simulation

MQTTX is a powerful cross-platform MQTT 5.0 desktop and CLI client that makes learning, exploring and developing MQTT easy and fast. It is a comprehensive MQTT toolbox, offering a user-friendly interface and a range of features for developers and users working with MQTT-based applications and services.

Website:https://mqttx.app/

GitHub: https://github.com/emqx/MQTTX

Introduction

In mid-May, the MQTTX team released a brand new version 1.9.3. This version officially renamed MQTT X as MQTTX to further unify the brand identity. Meanwhile, the latest release of MQTTX introduced a valuable enhancement to its command-line client. This new feature empowers developers to simulate IoT scenario data, catering to their specific testing needs. Furthermore, MQTTX has made substantial progress in optimizing Docker images, resulting in a notable reduction in file size.

Download the latest MQTTX version right now! →

MQTTX CLI Enhancements: Scenario-based Data Simulation

The MQTTX command-line client, MQTTX CLI, introduces a new command called "simulate" specifically designed for simulating MQTT publish messages in specific scenarios. This feature is particularly crucial for developers conducting system testing as it allows them to simulate data according to their testing scenario requirements. For instance, developers can simulate data sent by various devices, significantly enhancing development and testing efficiency.

The main parameters of this feature include:

  • -sc, --scenario: The name of the built-in scenario to simulate
  • -f, --file: The file path of a local custom scenario script
  • -t, --topic: The message topic, optional, supports variables such as %u (Username),%c (Clientid), %i (Index),%sc (Scenario). The default topic format is mqttx/simulate/%sc/%c

You must specify either the --scenario or --fileparameter. If both are set, the --file parameter takes priority.

Build-in Scenarios

MQTTX CLI has several built-in scenarios that can be specified using the --scenario parameter. For example, running mqttx simulate --scenario tesla simulates data for a Tesla car. You can also use the mqttx ls --scenarios command to list all the built-in scenarios. This command will output a table displaying the name and description of each scenario. If you want to use one of these scenarios in the simulate command, specify the scenario name in the --scenario option:

mqttx simulate --scenario <SCENARIO_NAME>

The built-in scenarios include:

  • tesla: Simulates data for a Tesla car.
  • IEM: Simulates industrial energy monitoring data.
  • smart_home: Simulates smart home data.
  • weather: Simulates weather station data.

Customized Scenarios

Developers can write custom IoT data scripts to simulate specific scenarios. For example, the following script generates random temperature and humidity data:

function generator (faker, options) {
  return {
    message: JSON.stringify({
      temp: faker.datatype.number({ min: 20, max: 80 }),  // Generate a random temperature between 20 and 80.
      hum: faker.datatype.number({ min: 40, max: 90 }),   // Generate a random humidity between 40 and 90.
    })
  }
}
module.exports = {
  name: 'myScenario',  // Name of the scenario
  generator,          // Generator function
}

Refer to the scripts-example folder in the MQTTX GitHub repository for more examples and detailed editing guidelines. You can also explore using faker.js to generate various types of random data.

For more information, users can also run the "help" command:

mqttx simulate --help

Example: Smart Home Scenario

Suppose you want to simulate a scenario where 10 smart home devices publish data on a specified topic; you can run the following command:

mqttx simulate -sc smart_home -c 10 -h broker.emqx.io -t testtopic/smart_home

This command will start 10 simulators (specified by the -c 10 parameter) that will publish data to the testtopic/smart_home topic (specified by the -t testtopic/smart_home parameter), simulating the behavior of smart home devices. The data will be generated by the built-in smart_home scenario (specified by the -sc smart_home parameter). Additionally, these simulators will connect to the server broker.emqx.io (specified by the -h broker.emqx.io parameter). After subscribing to this topic, you will see data similar to the following:

{
    "home_id": "e5ee7759-464f-4df8-9b68-2afc906da39a",
    "owner_name": "Dustin Hessel",
    "address": "8850 Ona Circle",
    "rooms": [{
        "room_type": "living room",
        "temperature": 19,
        "humidity": 45,
        "lights_on": true,
        "window_open": false
    }, {
        "room_type": "bedroom",
        "temperature": 23,
        "humidity": 33,
        "lights_on": true,
        "window_open": false,
        "bed_occupancy": false
    }, {
        "room_type": "kitchen",
        "temperature": 23,
        "humidity": 50,
        "lights_on": false,
        "window_open": false,
        "fridge_temperature": 5,
        "oven_on": true
    }, {
        "room_type": "bathroom",
        "temperature": 23,
        "humidity": 46,
        "lights_on": true,
        "window_open": true,
        "water_tap_running": false,
        "bath_water_level": 68
    }],
    "timestamp": 1684810770255
}

This data showcases the status of an innovative home environment, including temperature, humidity, lighting, and other information for each room.

Deployment Enhancement: Optimized Docker Image

In MQTTX 1.9.3, we significantly optimized the Docker images of MQTTX CLI and MQTTX Web Client. We adopted the multi-stage builds technique and switched to a Node.js environment based on Alpine Linux (node:16-alpine). These changes have significantly reduced the Docker image size by approximately 81.3%. Specifically, the MQTTX CLI Docker image size has been reduced from the original 1.07GB to 200.52MB, and the MQTTX Web Client Docker image size has shrunk from the original 886.75MB to 146.4MB.

These optimizations drastically reduce user storage usage and speed up the image download time, lowering the usage cost. The optimized images maintain full functionality while also improving their running efficiency. Moreover, these improvements alleviate network transmission pressure, making the private deployment of the MQTTX Web Client in a Docker environment more convenient and efficient.

MQTTX CLI Docker

MQTTX Web Client Docker

Desktop Client Enhancement

Auto Reconnect Feature

The connection has auto-reconnect enabled by default. If the MQTTX desktop client loses connection to the MQTT Broker due to network issues or other reasons, the client will attempt to reconnect automatically.

Editing Disabled in Connection State

In the connection state, editing is disabled to prevent accidental modifications and ensure data consistency.

Fixed Startup Issue on Ubuntu

We have resolved the problem of MQTTX not starting on Ubuntu systems. Now, Ubuntu users can use our desktop client without any issues.

Logo Update

We have optimized the application's logo, changing MQTT X to MQTTX, making it more concise and recognizable.

MQTTX

Future Plans

  1. Synchronize the IoT scenario data simulation feature to the desktop client.
  2. Enhance the highlighting of particular data formats, such as JSON, within the message display box.
  3. Support Protobuf message format.
  4. Support Sparkplug B.
  5. Enable configuration to ignore storing messages with QoS 0 to reduce storage space consumption.
  6. MQTT Debug feature.
  7. Automatic chart plotting for received messages.
  8. Plugin functionality for protocol extensions such as CoAP, MQTT-SN, etc.
  9. Automation of script testing (Flow).

MQTTX has always been committed to providing the best user experience and serving as the ultimate client tool for MQTT services and application developers worldwide.

Try MQTTX for Free
Get Started →

Related Posts

Mar 1, 2021Shifan Yu
MQTTX Script Function Tutorial

MQTT X has added a script function since v1.4.2. This article will introduce the use of the script function with two simple instances.

Aug 11, 2022MQTTX Team
MQTTX CLI: A Powerful and Easy-to-Use MQTT CLI

In order to provide more choices and convenience for users to implement MQTT connection tests, MQTT X v1.8.0 adds the command line as a form of interaction - the MQTT X CLI.