ThingsBoard Edge 设备连接

28 篇文章 16 订阅
28 篇文章 0 订阅
本文详细介绍了如何在ThingsBoard中使用Edge设备进行设备配置、遥测数据上传、属性管理(包括服务端、共享和客户端属性)、设备告警设置以及规则链管理的过程。
摘要由CSDN通过智能技术生成

# ThingsBoard

https://iothub.org.cn/docs/iot/
https://iothub.org.cn/docs/iot/tb-edge/edge-device/

一、创建设备

1.创建设备配置

在 ThingsBoard 服务端创建设备配置 test-edge
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在 Edge 端查看设备配置
在这里插入图片描述

2.创建设备

在 Edge 端创建设备 edge-device
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在服务端查看设备
在这里插入图片描述

# 访问令牌
lMrdczEw1rJHhBejzumZ

二、上传遥测

1.MQTTX 工具

在这里插入图片描述

2.上传遥测

# 发布主题
v1/devices/me/telemetry


# 发布数据
{
  "stringKey": "value1",
  "booleanKey": true,
  "doubleKey": 42.0,
  "longKey": 73,
  "jsonKey": {
    "someNumber": 42,
    "someArray": [1,2,3],
    "someNestedObject": {"key": "value"}
  }
}
  • 发送遥测数据
    在这里插入图片描述

  • Edge 端遥测数据
    在这里插入图片描述

  • ThingsBoard 服务端遥测数据
    在这里插入图片描述

三、属性

1.属性类型

属性主要分为三种:

  • 服务端属性:服务端定义,服务端使用,设备端不能使用
  • 共享属性:服务端定义,设备端可以使用,不能修改
  • 客户端属性:设备端定义属性,服务端可以使用,不能修改

1.服务端属性
在这里插入图片描述

2.共享属性
在这里插入图片描述

3.客户端属性
在这里插入图片描述

2.上传客户端属性

package com.iothub.attribute;
import com.iothub.mqtt.EmqClient;
import com.iothub.mqtt.MqttProperties;
import com.iothub.mqtt.QosEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

@Component
public class Upload {

    @Autowired
    private EmqClient emqClient;

    @Autowired
    private MqttProperties properties;

    @PostConstruct
    public void init(){
        //连接服务端
        emqClient.connect(properties.getUsername(),properties.getPassword());
        //订阅一个主题
        //emqClient.subscribe("testtopic/#", QosEnum.QoS1);
    }

    @Scheduled(fixedRate = 2000)
    public void publish(){

        String data = getData();

        emqClient.publish("v1/devices/me/attributes",data,
                QosEnum.QoS1,false);
    }

    private String getData(){

        String data = "{\n" +
                "\t\"attribute1\": \"value1\",\n" +
                "\t\"attribute2\": true,\n" +
                "\t\"attribute3\": 42.0,\n" +
                "\t\"attribute4\": 73,\n" +
                "\t\"attribute5\": {\n" +
                "\t\t\"someNumber\": 42,\n" +
                "\t\t\"someArray\": [1, 2, 3],\n" +
                "\t\t\"someNestedObject\": {\n" +
                "\t\t\t\"key\": \"value\"\n" +
                "\t\t}\n" +
                "\t}\n" +
                "}";

        return data;
    }
}
  • Edge 端显示
    在这里插入图片描述

  • 服务端显示
    在这里插入图片描述

3.下载共享属性

package com.iothub.attribute;
import com.iothub.mqtt.EmqClient;
import com.iothub.mqtt.MqttProperties;
import com.iothub.mqtt.QosEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import javax.annotation.PostConstruct;

//@Component
public class Download {

    @Autowired
    private EmqClient emqClient;

    @Autowired
    private MqttProperties properties;

    @PostConstruct
    public void init(){
        //连接服务端
        emqClient.connect(properties.getUsername(),properties.getPassword());
        //订阅一个主题
        emqClient.subscribe("v1/devices/me/attributes/response/+", QosEnum.QoS1);
    }

    @Scheduled(fixedRate = 2000)
    public void publish(){

        String data = getData();

        emqClient.publish("v1/devices/me/attributes/request/1",data, QosEnum.QoS1,false);
    }

    private String getData(){

        String data = "{\n" +
                "\t\"clientKeys\": \"attribute1,attribute2\",\n" +
                "\t\"sharedKeys\": \"shared1,shared2\"\n" +
                "}";

        return data;
    }
}

共享属性需要在 Edge 端创建,会同步到服务端
在这里插入图片描述
在这里插入图片描述

4.订阅共享数据

package com.iothub.attribute;
import com.iothub.mqtt.EmqClient;
import com.iothub.mqtt.MqttProperties;
import com.iothub.mqtt.QosEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import javax.annotation.PostConstruct;

//@Component
public class Subscribe {
    @Autowired
    private EmqClient emqClient;

    @Autowired
    private MqttProperties properties;

    @PostConstruct
    public void init(){
        //连接服务端
        emqClient.connect(properties.getUsername(),properties.getPassword());
        //订阅一个主题
        emqClient.subscribe("v1/devices/me/attributes", QosEnum.QoS1);
    }

    @Scheduled(fixedRate = 2000)
    public void publish(){

        String data = getData();

        //emqClient.publish("v1/devices/me/attributes/request/1",data, QosEnum.QoS1,false);
    }

    private String getData(){

        String data = "{\n" +
                "\t\"clientKeys\": \"attribute1,attribute2\",\n" +
                "\t\"sharedKeys\": \"shared1,shared2\"\n" +
                "}";

        return data;
    }
}

四、设备告警

1.配置告警规则

在 ThingsBoard 服务端创建告警规则
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.清除报警规则

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • Edge 端查看告警规则
    在这里插入图片描述

3.测试

v1/devices/me/telemetry


{
	"temperature": 62.2,
	"humidity": 79
}
3.1.设备告警
{
	"temperature": 62.2,
	"humidity": 79
}

在这里插入图片描述

  • Edge 端告警
    在这里插入图片描述

  • 服务端告警
    在这里插入图片描述

3.1.清除告警
{
	"temperature": 42.2,
	"humidity": 79
}

在这里插入图片描述
在这里插入图片描述

五、规则链

1.规则管理

在服务端创建、修改规则链
在这里插入图片描述
在这里插入图片描述

2.Edge 查看规则链

在这里插入图片描述
在这里插入图片描述

# ThingsBoard

https://iothub.org.cn/docs/iot/
https://iothub.org.cn/docs/iot/tb-edge/edge-device/
  • 17
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IoTHub - 物联网开源技术社区

支持开源技术! 传播开源文化!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值