ThingsBoard introduction practice: equipment telemetry and display

Posted by jerr0 on Thu, 09 Dec 2021 00:18:05 +0100

Equipment telemetry and display

1, Basic equipment concept

Observe the equipment panel, which is composed of the following parts:

  • Attribute: basic information, relatively stable
  • Telemetry: status information to be measured
  • Warning: there is a problem with the status of the device or device monitoring
  • Events: events that occur on the device
  • Association: who the equipment belongs to, on which asset, etc
  • Audit log: who did what on the platform

Among them, attribute is the foundation and telemetry is the core.

2, Attributes

ThingsBoard can assign custom attributes to entities and manage them.
Attribute represents the basic information of the device. It exists in key value format and can be seamlessly compatible with IoT devices.

Attributes are divided into client attributes, server attributes and shared attributes. It is easy to understand using the official diagram.

  • Client properties

  • Server properties

  • share property

3, Telemetry

One of the core purposes of the Internet of things is to collect and upload the corresponding telemetry data through sensors. In this regard, ThingsBoard provides a large number of functions related to telemetry data operation:

  • Collect device data using MQTT, CoAP or HTTP protocols.
  • It is stored in Cassandra (efficient, scalable and fault-tolerant NoSQL database) to store timing data.
  • Query the latest time series data value, or query all data in a specific time period.
  • Subscriptions use websockets to subscribe to data updates (for visualization or real-time analysis).
  • Visualization uses configurable and configurable widgets and dashboards to visualize timing data.
  • Filtering and analysis use a flexible rule engine to filter and analyze data (/ docs / user guide / rule engine /).
  • Event alerts trigger event alerts based on collected data.
  • Data is transmitted through the rule engine node to interact with external data (such as Kafka or RabbitMQ rule node)

The official has a blueprint, which is clear at a glance:

4, Street lighting equipment definition

First, define a simple street lamp device with 4 telemetry states:

  • switch
  • brightness
  • Electric quantity
  • position information

These telemetry states are processed and displayed step by step through the chapters.

5, Equipment simulation

If you want to connect the device, you must first find out the API for downloading and uploading data and the API for connecting the device to the platform.

Device API

The main api for communicating with the cloud platform is the device api,
Once the platform is deployed, it can be accessed directly in the browser http://IP:9090/swagger-ui/#/device-api-controller

Telemetry simulation

Download the sdk of the device client with the function of uploading device information from Github.
https://github.com/thingsboard/thingsboard-python-client-sdk
Or install directly using pip3:

pip3 install tb-mqtt-client

Upload telemetry data of analog equipment to equipment platform through mqtt link:

# -*- coding:utf-8 -*-
import random
from time import sleep
from tb_device_mqtt import TBDeviceMqttClient, TBPublishInfo

def send_to(token,telemetry):
    client = TBDeviceMqttClient("IP", token)
    # Connect to ThingsBoard
    client.connect()
    # Sending telemetry without checking the delivery status
    client.send_telemetry(telemetry) 
    # Sending telemetry and checking the delivery status (QoS = 1 by default)
    result = client.send_telemetry(telemetry)
    # get is a blocking call that awaits delivery status  
    success = result.get() == TBPublishInfo.TB_ERR_SUCCESS
    print(success)
    # Disconnect from ThingsBoard
    client.disconnect()

def mock_telemetry():
    t = {
        "turn": 1,
        "light": random.choice(range(0,100)),
        "battery":random.choice(range(10,60)),
    }
    return t

if __name__ == '__main__':
    while True:
        sleep(3)
        tokens = ["token_lamp_1"]
        for token in tokens:
            telemetry = mock_telemetry()
            send_to(token,telemetry)

Please note that!
pip is not the latest version. If you need to use http, you need to download it and install it locally

git clone git@github.com:thingsboard/thingsboard-python-client-sdk.git

6, Power display

Dashboard






Component: power display








Just follow the diagram.

Set as home page



You can see that the home page has become the power diagram of the device.

7, Next step

In this section, we mainly explain the simulation and display of equipment telemetry. The next section is another core function: command issuing.

Topics: IoT thingsboard