thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.75k stars 844 forks source link

[HELP] ThingsBoard as Modbus TCP server #934

Closed serfreeman1337 closed 2 years ago

serfreeman1337 commented 2 years ago

Describe the issue I'm trying to expose thingsboard's device attributes vie modbus tcp server. Modbus connector does have “slave” section, but it looks like it only exposes registers with constant 'value' field. Am I get it right that 'slave' option is only for constant values and I can't expose device attributes throught it ?

Configuration

tb_gateway.yaml ```yaml thingsboard: host: *** port: 1883 remoteShell: false remoteConfiguration: false statsSendPeriodInSeconds: 3600 minPackSendDelayMS: 0 checkConnectorsConfigurationInSeconds: 60 security: accessToken: *** qos: 1 storage: type: memory read_records_count: 100 max_records_count: 100000 grpc: enabled: false serverPort: 9595 keepaliveTimeMs: 10000 keepaliveTimeoutMs: 5000 keepalivePermitWithoutCalls: true maxPingsWithoutData: 0 minTimeBetweenPingsMs: 10000 minPingIntervalWithoutDataMs: 5000 connectors: - name: Modbus Test type: modbus configuration: modbus_test.json ```
modbus_test.json ```json { "master": { "slaves": [] }, "slave": { "type": "tcp", "host": "0.0.0.0", "port": 5026, "method": "socket", "deviceName": "test2-vfd-1", "deviceType": "delixi-vfd", "pollPeriod": 5000, "sendDataToThingsBoard": false, "byteOrder": "BIG", "wordOrder": "BIG", "unitId": 0, "values": { "holding_registers": [ { "attributes": [ { "tag": "b000", "type": "16int", "objectsCount": 1, "address": 45056, "value": 0 }, { "tag": "b001", "type": "16int", "objectsCount": 1, "address": 45057, "value": 0 } ], "rpc": [ { "tag": "setParam", "type": "16int", "functionCode": 6, "objectsCount": 1, "address": 40960, "value": 0 } ] } ], "coils_initializer": [], "input_registers": [], "discrete_inputs": [] } } } ```

Connector name: Modbus Connector

Versions (please complete the following information):

samson0v commented 2 years ago

Hi @serfreeman1337, no, It isn't. The slave section raises up Modbus "server" that will create all the registers you configured and you can change the value of these registers using any other software and of course, these values will be sent to ThingsBoard.

samson0v commented 2 years ago

@serfreeman1337, any updates? Can we close the issue?

serfreeman1337 commented 2 years ago

and you can change the value of these registers using any other software and of course, these values will be sent to ThingsBoard.

I tried to change them by "Write Single Holding Register" function, but changes are not reflected back to thingsboard (didn't see any client attributes or shared attributes updated).

~~What I wanted to do is to expose thingsboard device's client attributes ("deviceName" parameter) as modbus tcp registers.
"tag" in "values" means client attribute name of "deviceName" thingsboard device ?~~

I think problem is related to my setup. My device itself is already connected via MQTT (sends v1/devices/me/attributes messages) and I'm trying to use gateway to expose it's client attributes via tcp.

UPD: Indeed, after setting sendDataToThingsBoard to true, gateway start to overwrite client attriubtes with register values. Now I get how it's meant to work.