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.72k stars 829 forks source link

[HELP] Reading Input Register in Modbus TCP to Thingsboard Gateway #388

Closed adriortega closed 2 years ago

adriortega commented 4 years ago

Hellow, I am trying to read Input Registers from a Modbus TCP map, using the modbus_TCP.json file. In order to know the state and the attributes of some of my devices, I want to read single (boolean) or multiple bits variables, like in the following examples.

Reading a boolean variable: Thats my modbus.json code inside "attributes" of the Device.

{ "tag": "FlagSystemOk", "functionCode": 4, "type": "bits", "objectsCount": 1, "address": 6, "bit":15
},

Result in Thingsboard:

2020-09-10 16:18:54 FlagSystemOk [false,false,false,false,false,false,false,false]

Question: Why does the telemetry shows this 8 bit register, instead of only one or the value of the bit?

Regards and thanks for your answers.

Adrian.

*Versions (please complete the following information):**

imbeacon commented 4 years ago

Hi @adriortega ,

Thank you for your feedback, I have fixed it in the develop/2.4-python branch please try to use it and let me know about the results.

adriortega commented 4 years ago

Hi @adriortega ,

Thank you for your feedback, I have fixed it in the develop/2.4-python branch please try to use it and let me know about the results.

adriortega commented 4 years ago

Hi again @zbeacon . I am very pleased for your fast response and help. I have just used your recently fixed version and I still have some problems in this issue. In the next image you can see the error messages in my command window.

image

It seems as the range of the register is overpassed when I only tried to read the 15th bit of a 16 bits register.

Thanks for your previous help, and I hope that you know how can I solve this new problem. best whises.

Adrian.

imbeacon commented 4 years ago

Please try to set up the value objectsCount to 2 instead 1 in config.

adriortega commented 4 years ago

Hi! Lamentably the error continues. I attach here the command prompt with the messages.

image

Thanks for your help, and I have also another question, can I read 2 o 3 or less than 8 bits of an input register instead of reading the entire register and then decoding it? If so, can you tell me how??

I have tried to do it in the following way:

{ "tag": "MainState", "type": "bits", "functionCode": 4, "objectsCount": 2, "address": 1 },

Thank you very much.

Regards.

Adrian.

samson0v commented 2 years ago

Hi @adriortega, you can read a specific bit using "bit" in the config file but there is no opportunity to read a specific range of bits. Example: зображення

Thanks for your interest in ThingsBoard IoT Gateway.