Socket
The Socket Connector runs a TCP or UDP server on the gateway, accepting connections from devices and forwarding their binary payload data to ThingsBoard.
To enable this connector, add it to the connectors list in tb_gateway.json — see the
General Configuration reference.
Section “General”
Section titled “Section “General””General settings for the connector — name, logging, change filtering, and the report strategy.
- Name — connector name, used in logs and when saving to persistent storage
- Enable remote logging — enables remote logging for the connector
- Logging level —
INFO,DEBUG,WARNING,ERROR,CRITICAL, orNONE - Send data only on change — sends data only when its value has changed; otherwise data is sent on every check
- Report strategy — controls when data is forwarded to ThingsBoard:
- On report period — after every report period
- On value change — when a value changes
- On value change or report period — when a value changes or the report period elapses
- On received — immediately after data is received from the device (default)
Section “Socket”
Section titled “Section “Socket””Configures the local socket the connector binds to.
Configure the following fields:
- Connection type —
TCPorUDP - Address — IP address to bind to
- Port — port to listen on
- Buffer size — size of the received data block buffer
| Parameter | Default | Description |
|---|---|---|
name | TCP Connector Example | Connector name |
type | TCP | Socket type: TCP or UDP |
address | 127.0.0.1 | IP address the connector binds to |
port | 50000 | Port the connector listens on |
bufferSize | 1024 | Size of the received data block buffer in bytes |
{ "type": "TCP", "address": "127.0.0.1", "port": 50000, "bufferSize": 1024}Section “Devices”
Section titled “Section “Devices””An array of device configurations. Only devices whose IP address matches addressFilter are accepted;
all other connections are rejected.
Subsection “Device”
Section titled “Subsection “Device””Click the plus icon to add a new device, then fill in the following fields:
- Address filter — IP address pattern allowed to connect (see examples below)
- Device name — device name in ThingsBoard
- Device profile — device profile in ThingsBoard (optional)
- Encoding — encoding used when writing string data to storage
| Parameter | Default | Description |
|---|---|---|
addressFilter | *.* | IP address filter for allowed client connections |
deviceName | Device Example | Device name in ThingsBoard |
deviceType | default | Device type (profile) in ThingsBoard |
encoding | utf-8 | Encoding used when writing string data |
{ "address": "127.0.0.1:50001", "deviceName": "Device Example", "deviceType": "default", "encoding": "utf-8"}Address filter examples — for a device at 192.168.0.120:5001:
| Address filter | Matches |
|---|---|
192.168.0.120:5001 | Only that exact IP address and port |
*:5001 | Any IP address on port 5001 |
192.168.0.120:* | That IP address on any port |
*:* | Any IP address on any port |
Subsections “Time series” and “Attributes”
Section titled “Subsections “Time series” and “Attributes””Both use a binary byte-slicing converter. Values are extracted from the raw incoming payload by specifying start and end byte positions.
-
Click the pencil icon of the Attributes section to add a new attribute key.
-
Click Add attribute in the opened window.
-
Enter the key name and byte positions, then click Apply.
-
Click the pencil icon of the Time series section to add a new time series key.
-
Click Add time series in the opened window.
-
Enter the key name and byte positions, then click Apply.
You can enable a per-key report strategy. Available strategies:
- On report period — after every report period
- On value change — when a value changes
- On value change or report period — when a value changes or the report period elapses
- On received — immediately after data is received (default)
Both telemetry and attributes use the same field structure:
| Parameter | Default | Description |
|---|---|---|
key | Key name in ThingsBoard | |
byteFrom | 0 | Start byte index (inclusive) for slicing the received buffer |
byteTo | -1 | End byte index (exclusive); -1 means end of buffer |
{ "address": "127.0.0.1:50001", "deviceName": "Device Example", "deviceType": "default", "encoding": "utf-8", "telemetry": [ { "key": "temp", "byteFrom": 0, "byteTo": -1 }, { "key": "hum", "byteFrom": 0, "byteTo": 2 } ], "attributes": [ { "key": "name", "byteFrom": 0, "byteTo": -1 }, { "key": "num", "byteFrom": 2, "byteTo": 4 } ]}Subsection “Attribute request”
Section titled “Subsection “Attribute request””Optional. Lets the device request client-side or shared attributes from ThingsBoard by sending a specially formatted binary message.
-
Click the pencil icon of the Attribute requests section.
-
Click Add attribute request in the opened window.
-
Select the request type, enter the request expression and attribute name expression, then click Apply.
| Parameter | Default | Description |
|---|---|---|
type | shared | Attribute type to request: shared or client |
requestExpression | ${[0:3]==atr} | Byte-slice expression that detects whether the incoming message is an attribute request |
attributeNameExpression | [3:] | Byte-slice expression that extracts the attribute name from the message |
"attributeRequests": [ { "type": "shared", "requestExpression": "${[0:3]==atr}", "attributeNameExpression": "[3:]" }]To request multiple attributes in a single message, add multiple slice ranges in attributeNameExpression:
"attributeRequests": [ { "type": "shared", "requestExpression": "${[0:3]==atr}", "attributeNameExpression": "[4:19][20:]" }]The device sends: atr sharedAttribute sharedAttribute1
Subsection “Attribute update”
Section titled “Subsection “Attribute update””Optional. Configures how ThingsBoard shared attribute updates are forwarded to the connected device.
-
Click the pencil icon of the Attribute updates section.
-
Click Add attribute update in the opened window.
-
Select encoding and fill in the Attribute on platform field, then click Apply.
| Parameter | Default | Description |
|---|---|---|
encoding | utf-16 | Encoding used when writing the attribute value to the device |
attributeOnThingsBoard | sharedName | Shared attribute name to subscribe to |
"attributeUpdates": [ { "encoding": "utf-16", "attributeOnThingsBoard": "sharedName" }]Subsection “RPC methods”
Section titled “Subsection “RPC methods””Optional. Maps ThingsBoard RPC calls to write operations on the connected device.
-
Click the pencil icon of the RPC methods section.
-
Click Add method in the opened window.
-
Fill in Method name, select encoding, and set With Response, then click Apply.
| Parameter | Default | Description |
|---|---|---|
methodRPC | rpcMethod1 | RPC method name |
withResponse | true | Send the device’s response back to ThingsBoard |
methodProcessing | write | Operation type |
encoding | utf-8 | Encoding used when writing data to the device |
"serverSideRpc": [ { "methodRPC": "rpcMethod1", "withResponse": true, "methodProcessing": "write", "encoding": "utf-8" }]Every telemetry and attribute key also has a built-in set RPC method available automatically — no manual
entry required. The required parameters are withResponse, methodProcessing, and encoding. See the
Reserved RPC methods guide for details.