Skip to content
Stand with Ukraine flag

Getting Started

The ThingsBoard IoT Gateway is an open-source solution, designed to serve as a bridge between IoT devices connected to legacy and third-party systems with ThingsBoard.

This guide covers initial IoT Gateway installation and configuration, we will do the following things:

  • Create a new gateway device;
  • Launch the gateway using Docker command;
  • Configure different connector types (MQTT, OPC-UA, Modbus) in order to connect to a local demo servers and read data from them;
  • Check received device data on ThingsBoard.
  • Before initiating the Gateway setup, ensure that the ThingsBoard server is up and running. The simplest approach is to use ThingsBoard Cloud. Alternatively, you can install ThingsBoard manually by following the steps outlined in the Installation Guide.
  • Before moving forward, ensure Docker is installed and properly configured on your machine. If you haven’t installed Docker yet, you can download it from the official Docker website and follow their installation guide for your specific operating system.

Step 1. Create a new gateway device on ThingsBoard

Section titled “Step 1. Create a new gateway device on ThingsBoard”

First, add a gateway device to your ThingsBoard instance by following these steps:

  1. Go to Entities > Gateways tab.

  2. Click the + button, enter the gateway device name (e.g., “My Gateway”), and select the device profile. Click on Create button.

To launch the gateway, use the following steps:

  1. Select and click on newly created gateway, click on Launch command button in the top right corner.

  2. Click to download docker-compose.yml file to your PC, copy command and execute it in your terminal.

After running gateway docker image, you can see the following logs in your terminal:

To view gateway and connector logs on the platform side, you need to enable remote logging. For this purpose, use the following steps:

  1. On selected gateway page, click on General configuration button on the right panel.

  2. Navigate to the Logs tab. Enable the Remote logging toggle. Select DEBUG in the Log level drop-down menu. Click on the Save button to apply changes.

By choosing the type of connector, you determine the specific method of connection you will use to ensure the interaction of your gateway with other systems or devices.

To see how the connector works, you can choose one of the following connectors:

Let’s add an MQTT connector, which will subscribe to some data topics using the demo broker with a built-in data generator and send data to the gateway.

As a demo MQTT broker, we will use docker image, that can be installed and run using the following command:

Terminal window
docker run -it -p 1884:1884 thingsboard/tb-gw-mqtt-broker:latest

After running docker image, you can see the following logs in your terminal:

MQTT connector will establish a connection to a broker named “Demo Broker” at “host.docker.internal” on port 1884, using an anonymous security type. It will include a data mapping for the “data/” topic, specifying a JSON converter and defining attribute and time series mappings for device data. Additionally, it will handle connect and disconnect requests for sensors with expressions to extract device names from topic filters.

To create a connector, follow these steps:

  1. Click on Connectors configuration button on the right panel.

  2. Click the + Add connector button.

  3. Choose MQTT connector type from the dropdown, fill in Name field, choose Logging level to INFO, disable Fill configuration with default values field and click on Add button.

  4. Connector created.

First, we need to configure the connection to the demo broker. Let’s start from the Connection to broker section. This section offers detailed connection configuration options and contains several important fields, including host, port, MQTT version, client ID, and security settings. The host field specifies the address of the broker, while the port field indicates the communication port. The MQTT version field ensures compatibility with the protocol version being used. The client ID uniquely identifies the client, and the security settings provides configuration for client authorization at MQTT Broker.

Fill in the following fields with values:

Field nameValue
Hosthost.docker.internal
Port1884
MQTT version5
Client IDrandomly generated
SecurityAnonymous

Now, we are ready to move to the Data mapping section. This configuration section contains an array of topics that the gateway will subscribe to after connecting to the broker, along with settings about processing incoming messages (converter).

Let’s configure data map using the following steps:

Following the steps outlined, your gateway will receive and apply the new configuration. It will then synchronize its state with the remote server. You can view the synchronization status of the connector configuration in the Configuration column, which will indicate whether the gateway is successfully aligned with the remote settings.

Also, you can see the connector logs to make sure that the connector works, for this purpose, follow these steps:

  1. In the General connector tab enable remove logging by turning on the Enable remote logging toggle. Choose DEBUG in the Log level drop-down menu. Click on the Save button to apply changes.

  2. Click on logs icon to open connector logs page.

  3. You can see the Logs table that consists of Created time, Status and Message columns.

For now, the gateway is ready to process data through the newly created and configured MQTT connector.

Let’s publish data to the MQTT Broker defined in the configuration above, you can follow these steps using a tool like mosquitto_pub or an MQTT client library in your preferred programming language. In this example, we’ll use the mosquitto_pub command-line tool.

  1. Ensure that the Mosquitto MQTT clients are installed on your system. Typically, you can install them using the package manager of your operating system:
  • For Ubuntu:

    Terminal window
    sudo apt-get install mosquitto-clients
  • For Windows:

    Download the Mosquitto client tools from the official website.

    Install the tools, ensuring that the installation directory is added to the system’s PATH.

  • For MacOS:

    Terminal window
    brew install mosquitto
  1. Use the mosquitto_pub command to publish data to a specific MQTT topic. In this case, we’ll use the “data/” topic as defined in the configuration:
Terminal window
mosquitto_pub -h localhost -p 1884 -t data/ -m '{"frequency": 50, "power": 100, "temperature": 25, "humidity": 60}'

Where:

  • -h - specifies the MQTT broker’s host address;
  • -p - specifies the MQTT broker’s port;
  • -t - specifies the MQTT topic to publish to (“data/” in our case);
  • -m - specifies the payload or message to publish. It should be in JSON format, following the structure defined in the mapping section of your configuration.

Adjust the payload values as needed.

To review the data uploaded from your gateway, use the following steps:

  1. Navigate to the Entities > Devices page and click on the created device. This will open the device details page. From there, switch to the Attributes tab to view the attributes that were configured in the connector.

  2. To view real-time telemetry data from the device, navigate to the Latest Telemetry tab. Here, you will find the telemetry data being sent by the device, including metrics like “humidity” and “temperature”. This tab provides real-time device telemetry updates.

After the successful installation and configuration of your first connector, you can configure other connectors to connect to different devices. You can find more information about connectors in the following articles:

More about ThingsBoard IoT Gateways Dashboard, you can read here.