ThingsBoard Edge 设备连接

news/2024/5/19 12:48:00 标签: edge, 物联网, iot, 边缘计算

文章目录

    • 一、创建设备
      • 1.创建设备配置
      • 2.创建设备
    • 二、上传遥测
      • 1.MQTTX 工具
      • 2.上传遥测
    • 三、属性
      • 1.属性类型
      • 2.上传客户端属性
      • 3.下载共享属性
      • 4.订阅共享数据
    • 四、设备告警
      • 1.配置告警规则
      • 2.清除报警规则
      • 3.测试
        • 3.1.设备告警
        • 3.1.清除告警
    • 五、规则链
      • 1.规则管理
      • 2.Edge 查看规则链

  • ThingsBoard
# 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
# ThingsBoard

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

http://www.niftyadmin.cn/n/5438052.html

相关文章

缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级的理解

一:缓存雪崩 我们可以简单的理解为:由于原有缓存失效,新缓存未到期间 (例如:我们设置缓存时采用了相同的过期时间,在同一时刻出现大面积的缓存过期),所有原本应该访问缓存的请求都去查询数据库了&#xff…

白酒:新型酶制剂在酿造过程中的作用与应用

随着生物技术的不断发展,新型酶制剂在许多领域都得到了广泛的应用。在豪迈白酒的酿造过程中,新型酶制剂也发挥了重要作用。云仓酒庄紧跟科技前沿,积极探索新型酶制剂在酿造过程中的应用,以提高产品质量和生产效率。 首先&#xff…

爱恩斯坦棋小游戏使用C语言+ege/easyx实现

目录 1、游戏介绍和规则 2、需要用到的头文件 3、这里我也配上一个ege和easyx的下载链接吧,应该下一个就可以 4、运行结果部分展示 5、需要用到的图片要放在代码同一文件夹下 6、代码地址(里面有需要用到的图片) 1、游戏介绍和规则 规则如…

蓝桥杯-Sticks-DFS搜索

题目 样例输出是 6 5 题目中给错了,不知道什么时候会改。 思路 --剪枝,否则时间复杂度和空间复杂度过大,会超时。 --注意有多组测试样例时,需要将bool数组重新赋值为false。 --函数类型不是void,return语句不能省…

Windows11企业版安装WSL2和Ubuntu发布版(避坑)

背景 win10企业版升级win11企业版后,安装WSL2,最后安装WSL的Ubuntu发布版,尝试网上各种方法,还是出现文章第三节所写的问题,差点被这问题搞放弃了,全网少有针对这个问题的答案,有也不顶用&…

redis设计与实现(二)——持久化

1. 前言: redis是一个基于内存是键值对数据库,但是并非把数据存入内存就高枕无忧了。为了应对可能出现的进程中止,断电等意外情况,redis提供了持久化功能把数据持久化到硬盘。 2. RDB持久化 2.1. rdb文件的创建 rdb通过创建二…

PHP反序列化--pop链

目录 一、了解pop链 1、pop链: 2、pop链触发规则: (1)通过普通函数触发: (2)通过魔术方法触发: 3、pop链魔术方法例题: 一、了解pop链 1、pop链: pop链…

门店运营三大核心揭秘:打造高效盈利模式的关键

在当今竞争激烈的商业环境中,开设一家成功的实体店并非易事。对于那些渴望投身实体店创业或已经在创业道路上的人来说,了解如何打造高效盈利模式是至关重要的。作为一名经营鲜奶吧5年时间的创业者,我将持续在网上分享开店的干货和见解&#x…