ThingsBoard 二次开发 - 设备管理

# ThgingsBoard

https://iothub.org.cn/docs/iot/
https://iothub.org.cn/docs/iot/dev/dev-device/

一、设备规划

1.设备规划

  1. ThingsBoard创建、删除实体等产生消息
  2. 实体更新消息通过规则引擎发送到消息队列(RabbitMQ或Kafka、EMQX)
  3. 通过REST API对设备进行管理(增、删、改、查)

二、准备工作

1.RabbitMQ

device-queue、device-exchange

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

2.规则引擎

2.1.创建规则链

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

2.2.数据整合
msg.msgType = msgType;
msg.entityName = metadata.entityName;
msg.entityType = metadata.entityType;

return {msg: msg, metadata: metadata, msgType: msgType};

在这里插入图片描述

2.3.配置RabbitMQ

在这里插入图片描述

2.4.测试规则引擎

在这里插入图片描述

# 创建设备

{
    "id": {
        "entityType": "DEVICE",
        "id": "e4852e50-68a5-11ee-afb9-c790163a721a"
    },
    "createdTime": 1697077220789,
    "additionalInfo": {
        "gateway": false,
        "overwriteActivityTime": false,
        "description": ""
    },
    "tenantId": {
        "entityType": "TENANT",
        "id": "088202c0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "customerId": {
        "entityType": "CUSTOMER",
        "id": "13814000-1dd2-11b2-8080-808080808080"
    },
    "name": "device4",
    "type": "default",
    "label": "",
    "deviceProfileId": {
        "entityType": "DEVICE_PROFILE",
        "id": "088de9a0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "deviceData": {
        "configuration": {
            "type": "DEFAULT"
        },
        "transportConfiguration": {
            "type": "DEFAULT"
        }
    },
    "firmwareId": null,
    "softwareId": null,
    "externalId": null,
    "msgType": "ENTITY_CREATED",
    "entityName": "device4",
    "entityType": "DEVICE"
}
# 删除设备

{
    "id": {
        "entityType": "DEVICE",
        "id": "e4852e50-68a5-11ee-afb9-c790163a721a"
    },
    "createdTime": 1697077220789,
    "additionalInfo": {
        "gateway": false,
        "overwriteActivityTime": false,
        "description": ""
    },
    "tenantId": {
        "entityType": "TENANT",
        "id": "088202c0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "customerId": {
        "entityType": "CUSTOMER",
        "id": "13814000-1dd2-11b2-8080-808080808080"
    },
    "name": "device4",
    "type": "default",
    "label": "",
    "deviceProfileId": {
        "entityType": "DEVICE_PROFILE",
        "id": "088de9a0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "deviceData": {
        "configuration": {
            "type": "DEFAULT"
        },
        "transportConfiguration": {
            "type": "DEFAULT"
        }
    },
    "firmwareId": null,
    "softwareId": null,
    "externalId": null,
    "msgType": "ENTITY_DELETED",
    "entityName": "device4",
    "entityType": "DEVICE"
}

3.数据

3.1.创建设备
# 数据

{
    "id": {
        "entityType": "DEVICE",
        "id": "f8c1d520-68a1-11ee-afb9-c790163a721a"
    },
    "createdTime": 1697075536754,
    "additionalInfo": {
        "gateway": false,
        "overwriteActivityTime": false,
        "description": ""
    },
    "tenantId": {
        "entityType": "TENANT",
        "id": "088202c0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "customerId": {
        "entityType": "CUSTOMER",
        "id": "13814000-1dd2-11b2-8080-808080808080"
    },
    "name": "device3",
    "type": "default",
    "label": "",
    "deviceProfileId": {
        "entityType": "DEVICE_PROFILE",
        "id": "088de9a0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "deviceData": {
        "configuration": {
            "type": "DEFAULT"
        },
        "transportConfiguration": {
            "type": "DEFAULT"
        }
    },
    "firmwareId": null,
    "softwareId": null,
    "externalId": null
}
# 元数据

{
    "entityName": "device3",
    "entityType": "DEVICE",
    "userEmail": "tenant@thingsboard.org",
    "userId": "08f69680-64f4-11ee-b6d5-bdc7c43c6c8f",
    "userName": "tenant@thingsboard.org"
}
3.2.删除数据
# 数据

{
    "id": {
        "entityType": "DEVICE",
        "id": "f8c1d520-68a1-11ee-afb9-c790163a721a"
    },
    "createdTime": 1697075536754,
    "additionalInfo": {
        "gateway": false,
        "overwriteActivityTime": false,
        "description": ""
    },
    "tenantId": {
        "entityType": "TENANT",
        "id": "088202c0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "customerId": {
        "entityType": "CUSTOMER",
        "id": "13814000-1dd2-11b2-8080-808080808080"
    },
    "name": "device3",
    "type": "default",
    "label": "",
    "deviceProfileId": {
        "entityType": "DEVICE_PROFILE",
        "id": "088de9a0-64f4-11ee-b6d5-bdc7c43c6c8f"
    },
    "deviceData": {
        "configuration": {
            "type": "DEFAULT"
        },
        "transportConfiguration": {
            "type": "DEFAULT"
        }
    },
    "firmwareId": null,
    "softwareId": null,
    "externalId": null
}
# 元数据

{
    "entityName": "device3",
    "entityType": "DEVICE",
    "userEmail": "tenant@thingsboard.org",
    "userId": "08f69680-64f4-11ee-b6d5-bdc7c43c6c8f",
    "userName": "tenant@thingsboard.org"
}

三、REST API

1.设备API

1.1.设备端API

在这里插入图片描述

1.2.设备服务端API

在这里插入图片描述

1.3.设备配置API

在这里插入图片描述

四、REST API测试

1.getDeviceById

在这里插入图片描述

2.deleteDvice

在这里插入图片描述

3.getDeviceInfoById

在这里插入图片描述

4.getDeviceTypes

在这里插入图片描述

5.getDevicesByIds

在这里插入图片描述

# ThgingsBoard

https://iothub.org.cn/docs/iot/
https://iothub.org.cn/docs/iot/dev/dev-device/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

IoTHub - 物联网开源技术社区

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

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

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

打赏作者

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

抵扣说明:

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

余额充值