Posting multiple data in IoT gateway Thingsboard

爷,独闯天下 提交于 2019-12-13 03:48:03

问题


I just now started using Thingsboard and I came across this one,https://thingsboard.io/docs/iot-gateway/getting-started/. I have implemented it but the problems that I'm facing are,

1.I can transmit only one Key-value pair. How can I transmit multiple key-value sensor data?

2.Also if there is any other way to access the Cassandra Database so that I can retrieve all mine data to Thingsboard.

Please help. Thanking you.


回答1:


For example, humidity, temperature, gas.

In this case you use one access token/single mqtt session and send data in single json like this

{"humidity":42.2, "temperature":23.3, "gas":45}

If you have multiple sensors attached to single device, send them like this

{"sensorA.humidity":42.2, "sensorB.temperature":23.3, "sensorC.gas":45}

Available topics are static and listed here: https://thingsboard.io/docs/reference/mqtt-api/#telemetry-upload-api




回答2:


You are asking two very different things.

1) You can transmit more key-value pairs at once by correctly mapping the gateway incoming messages. I suppose you are working with MQTT protocol. The default mapping for this protocol is specified in /etc/tb-gateway/conf/mqtt-config.json. This file specifies how to translate the incoming MQTT messages from the broker into the ThingsBoard key-value format, before sending to the server instance of ThingsBoard. To map more than one reading from sensor, you can do somethings like this:

{
  "brokers": [
    {
      "host": "localhost",
      "port": 1883,
      "ssl": false,
      "retryInterval": 5000,
      "credentials": {
        "type": "anonymous"
      },
      "mapping": [
        {
          "topicFilter": "WeatherSensors",
          "converter": {
            "type": "json",
            "filterExpression": "",
            "deviceNameJsonExpression": "${$.WeatherStationName}",
            "timeout": 120000,
            "timeseries": [
              {
                "type": "double",
                "key": "temperature",
                "value": "${$.temperature}"
              },
              {
                "type": "double",
                "key": "humidity",
                "value": "${$.humidity}"
              }
            ]
          }
        }
      ]
    }
  ]
}

This way, if you send a message like {"WeatherStationName":"test", "temperature":25, "humidity":40} to the topic WeatherSensors you will see the two key-value pairs in ThingsBoard server, in a device named "test".

2) The best way to access data stored in the internal ThingsBoard server is via REST API, so that you can query any ThingsBoard instance with the same piece of code regardless of the technology used for the database (Cassandra, PostgreSQL, etc.). You can find a Python example in this repo. The alternative is to use a specific query language for the database, such as SQL for PostgreSQL or CQL for Cassandra.



来源:https://stackoverflow.com/questions/45605022/posting-multiple-data-in-iot-gateway-thingsboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!