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.74k stars 844 forks source link

[HELP]How to manipulate values before sending to thingsboard server? #277

Closed pehedima closed 4 years ago

pehedima commented 4 years ago

I use a normal temperature sensor (MODBUS RTU) to send the temperature to thingsboard server. The read value from the device is the temperature multiplied by 10. That means, that the value of the register is for example 194 -> 19.4 degrees Celsius. This value should be send to thingsboard server.

What is the easiest way to calculate that before sending?

Here the tb_gateway.yaml and the JSON script to communicate with the device.

modbus-serial-temperature-config.zip tb_gateway.zip

Thanks in advance.

imbeacon commented 4 years ago

Hi @pehedima,

I added parameters "divider" and "multiplier", specially for this, you can update your gateway to the version from master branch and check it.

To use it, you need just put "divider": 10 into you config like:


{
  "server": {
    "name": "temerature serial",
    "type": "serial",
    "port": "/dev/ttyUSB0",
    "baudrate": 9600,
    "timeout": 35,
    "method": "rtu",
    "devices": [
      {
        "unitId": 1,
        "deviceName": "TEMP-Home-python-balena-serial",
        "attributesPollPeriod": 3600000,
        "timeseriesPollPeriod": 5000,
        "sendDataOnlyOnChange": false,
         "timeseries":[
            {
               "tag":"Temperatur_Buero",
               "type":"long",
               "functionCode":3,
               "address":0,
               "registerCount":1,
               "byteOrder":"BIG",
               "divider": 10
            }
         ]
      }
    ]
  }
}
pehedima commented 4 years ago

Thanks you for your fast reply and the implementation of the two new parameters :) It's working.

Only the 'multiplier'-function should be changed from:

decoded_data = decoded_data/configuration["multiplier"]

to:

decoded_data = decoded_data*configuration["multiplier"]

Then everthing should work correctly.

imbeacon commented 4 years ago

Oh, yep thanks.

SuperCodesMaker commented 3 years ago

Oh, yep thanks.

Hi @pehedima,

I added parameters "divider" and "multiplier", specially for this, you can update your gateway to the version from master branch and check it.

To use it, you need just put "divider": 10 into you config like:


{
  "server": {
    "name": "temerature serial",
    "type": "serial",
    "port": "/dev/ttyUSB0",
    "baudrate": 9600,
    "timeout": 35,
    "method": "rtu",
    "devices": [
      {
        "unitId": 1,
        "deviceName": "TEMP-Home-python-balena-serial",
        "attributesPollPeriod": 3600000,
        "timeseriesPollPeriod": 5000,
        "sendDataOnlyOnChange": false,
         "timeseries":[
            {
               "tag":"Temperatur_Buero",
               "type":"long",
               "functionCode":3,
               "address":0,
               "registerCount":1,
               "byteOrder":"BIG",
               "divider": 10
            }
         ]
      }
    ]
  }
}

Hello, I know "devicer" and "multiplier" can config in *json file,but can you add "offset" too? for example ,Calibrate the temperature. source value is 10, offset = -2,end value is 8.