Skip to content
Stand with Ukraine flag

General Configuration

The gateway is configured through tb_gateway.json and per-connector JSON files located in the config directory. Connection parameters can also be overridden with environment variables.

Default layout for a daemon installation:

/etc/thingsboard-gateway/config/
tb_gateway.json Main gateway configuration file
logs.json Logging configuration
mqtt.json MQTT connector configuration
modbus.json Modbus connector configuration
opcua.json OPC-UA connector configuration
request.json Request connector configuration
ble.json BLE connector configuration
can.json CAN connector configuration
...
/var/lib/thingsboard_gateway/extensions/ Folder for custom connectors/converters
mqtt/ Folder for MQTT custom connectors/converters
__init__.py Default Python package file, needed for correct imports
custom_uplink_mqtt_converter.py Custom MQTT converter example
modbus/ Folder for Modbus custom connectors/converters
opcua/ Folder for OPC-UA custom connectors/converters
ble/ Folder for BLE custom connectors/converters
request/ Folder for Request custom connectors/converters
can/ Folder for CAN custom connectors/converters
...
/var/log/thingsboard-gateway/
service.log Main gateway service logs
connector.log Connector logs
storage.log Storage logs
tb_connection.log ThingsBoard connection logs

Environment variables are useful for Docker deployments — set them in docker-compose.yml to avoid hard-coding credentials in the config file:

services:
tb-gateway:
image: thingsboard/tb-gateway
container_name: tb-gateway
environment:
- TB_GW_HOST=host.docker.internal
- TB_GW_PORT=1883
- TB_GW_ACCESS_TOKEN=YOUR_ACCESS_TOKEN

Full list of supported variables:

VariableDefaultDescription
TB_GW_HOSThost.docker.internalHostname or IP address of ThingsBoard server
TB_GW_PORT1883MQTT service port on ThingsBoard server
TB_GW_ACCESS_TOKENAccess token for the gateway
TB_GW_CA_CERTPath to CA certificate file
TB_GW_PRIVATE_KEYPath to private key file
TB_GW_CERTPath to certificate file
TB_GW_CLIENT_IDMQTT client ID
TB_GW_USERNAMEMQTT username
TB_GW_PASSWORDMQTT password
TB_GW_RATE_LIMITS15:1,300:60,Message rate limit in COUNT:SECONDS, format
TB_GW_DP_RATE_LIMITS15:1,300:60,Data point rate limit in COUNT:SECONDS, format
TB_GW_LOGS_PATH/thingsboard_gateway/logsPath to the logs folder

The main tb_gateway.json file controls the platform connection, security, storage backend, and the list of active connectors. Below is a full example connecting to thingsboard.cloud with memory storage and four connectors:

{
"thingsboard": {
"host": "thingsboard.cloud",
"port": 1883,
"remoteShell": false,
"remoteConfiguration": true,
"statistics": {
"enable": true,
"statsSendPeriodInSeconds": 60
},
"deviceFiltering": {
"enable": false,
"filterFile": "list.json"
},
"maxPayloadSizeBytes": 1024,
"minPackSendDelayMS": 60,
"minPackSizeToSend": 500,
"checkConnectorsConfigurationInSeconds": 10,
"handleDeviceRenaming": true,
"security": {
"type": "accessToken",
"accessToken": "YOUR_ACCESS_TOKEN"
},
"qos": 1,
"checkingDeviceActivity": {
"checkDeviceInactivity": false,
"inactivityTimeoutSeconds": 200,
"inactivityCheckPeriodSeconds": 500
}
},
"storage": {
"type": "memory",
"read_records_count": 100,
"max_records_count": 10000
},
"grpc": {
"enabled": false,
"serverPort": 9595,
"keepaliveTimeMs": 10000,
"keepaliveTimeoutMs": 5000,
"keepalivePermitWithoutCalls": true,
"maxPingsWithoutData": 0,
"minTimeBetweenPingsMs": 10000,
"minPingIntervalWithoutDataMs": 5000
},
"connectors": [
{
"type": "mqtt",
"name": "MQTT Broker Connector",
"configuration": "mqtt.json"
},
{
"type": "modbus",
"name": "Modbus Connector",
"configuration": "modbus.json"
},
{
"type": "modbus",
"name": "Modbus Serial Connector",
"configuration": "modbus_serial.json"
},
{
"type": "opcua",
"name": "OPC-UA Connector",
"configuration": "opcua.json"
}
]
}

The file has three top-level sections:

SectionDescription
thingsboardPlatform connection, security, and gateway behaviour
storageLocal buffer for incoming data before sending to the platform
connectorsArray of active connectors and their config files

Parameters inside the thingsboard object:

ParameterDefaultDescription
hostthingsboard.cloudHostname or IP address of the ThingsBoard server
port1883MQTT service port
qos1MQTT QoS: 0 (at most once) or 1 (at least once)
minPackSendDelayMS200Delay between outgoing packets (lower value → higher CPU usage)
minPackSizeToSend500Minimum packet size before sending
maxPayloadSizeBytes1024Maximum message payload size in bytes
checkConnectorsConfigurationInSeconds10How often connector configs are checked for changes
handleDeviceRenamingtrueEnable device rename/delete notifications from the platform

Configures collection and reporting of gateway statistics as device attributes.

ParameterDefaultDescription
enabletrueEnable statistics collection
statsSendPeriodInSeconds3600How often statistics are sent to ThingsBoard
configurationstatistics.jsonOptional: path to a custom statistics commands file

The optional statistics.json file lets you collect arbitrary system metrics via shell commands:

[
{
"timeout": 100,
"command": ["/bin/sh", "-c", "ps -A -o cpu,%mem | awk '{cpu += $1}END{print cpu}'"],
"attributeOnGateway": "CPU"
},
{
"timeout": 100,
"command": ["/bin/sh", "-c", "ps -A -o %cpu,%mem | awk '{mem += $2}END{print mem}'"],
"attributeOnGateway": "Memory"
},
{
"timeout": 100,
"command": ["/bin/sh", "-c", "ipconfig getifaddr en0"],
"attributeOnGateway": "IP address"
}
]

Example files for Linux, macOS, and Windows are included in the config/statistics/ folder.

Optional. Restricts which devices are allowed to send data to ThingsBoard based on connector and device name rules.

ParameterDefaultDescription
enablefalseEnable device filtering
filterFilelist.jsonName of the filter rules file in the config folder

The filter file supports deny and allow rules per connector. Device names may be exact strings or regular expressions:

{
"deny": {
"MQTT Broker Connector": [
"Temperature Device",
"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$)"
],
"Modbus Connector": [
"My Modbus Device"
]
},
"allow": {
"MQTT Broker Connector": [
"My Temperature Sensor"
]
}
}
  • deny — devices matching these names (or patterns) are blocked from reporting through the specified connector.
  • allow — devices explicitly permitted regardless of deny rules.

In the above example, the following rules are defined:

  • The device named “Temperature Device” and any device with an email address format are denied access to the “MQTT Broker Connector”.
  • The device named “My Modbus Device” is denied access to the “Modbus Connector”.
  • The device named “My Temperature Sensor” is allowed access to the “MQTT Broker Connector”.

Optional. Disconnects devices that have been inactive for longer than the configured timeout.

ParameterDefaultDescription
checkDeviceInactivityfalseEnable inactivity monitoring
inactivityTimeoutSeconds120Seconds of inactivity before the device is disconnected
inactivityCheckPeriodSeconds10How often device activity is checked

Choose one of four security modes:

Simple token-based authentication. Create a gateway device in ThingsBoard and copy its access token.

ParameterDescription
accessTokenAccess token from the ThingsBoard device credentials
"security": {
"type": "accessToken",
"accessToken": "YOUR_ACCESS_TOKEN"
}

Optional. When set, the gateway auto-registers on the platform using the specified strategy instead of using pre-configured credentials. See Device Provisioning for the full workflow.

The platform generates and assigns an access token automatically.

ParameterDescription
typeAUTO
provisionDeviceKeyProvisioning key from the device profile
provisionDeviceSecretProvisioning secret from the device profile
"provisioning": {
"type": "AUTO",
"provisionDeviceKey": "YOUR_PROVISION_KEY",
"provisionDeviceSecret": "YOUR_PROVISION_SECRET"
}

The storage section configures how the gateway buffers incoming device data before forwarding it to ThingsBoard. Choose one of three backends:

Persists data to .db files on disk. Recommended for most production setups.

ParameterDefaultDescription
typesqliteStorage type
data_file_path./data/Directory for database files (trailing separator required)
max_read_records_count1000Max messages read from storage per batch and sent to ThingsBoard
size_limit1024Max size (MB) of each SQLite file before rotation to a new file
max_db_amount10Max number of rotated DB files to keep; writes are dropped when exceeded
oversize_check_period1Frequency (minutes) to check whether the current DB exceeds size_limit
writing_batch_size1000Max messages batched before a single write to the DB
messages_ttl_check_in_hours1How often to check for expired messages
messages_ttl_in_days7Days to retain messages before automatic deletion
"storage": {
"type": "sqlite",
"data_file_path": "./data/",
"max_read_records_count": 1000,
"size_limit": 1024,
"max_db_amount": 10,
"oversize_check_period": 1,
"writing_batch_size": 1000,
"messages_ttl_check_in_hours": 1,
"messages_ttl_in_days": 7
}

The connectors array lists all active connectors. Each entry requires:

ParameterExampleDescription
typemqttConnector type — must match the folder name containing the connector implementation
nameMQTT Broker ConnectorDisplay name for the connector
configurationmqtt.jsonFilename of the connector config file in the config directory
useGRPCtrueOptional. Enable/disable gRPC transport for the connector
"connectors": [
{
"type": "mqtt",
"name": "MQTT Broker Connector",
"configuration": "mqtt.json"
},
{
"type": "modbus",
"name": "Modbus Connector",
"configuration": "modbus.json"
},
{
"type": "modbus",
"name": "Modbus Serial Connector",
"configuration": "modbus_serial.json"
},
{
"type": "opcua",
"name": "OPC-UA Connector",
"configuration": "opcua.json"
}
]

Multiple connectors of the same type are supported — give each a unique name and configuration file. For custom connector types, see the Customization guide.