Skip to content

设备动态注册 ​

这篇解决什么 ​

一型一密怎么换 deviceSecret、子设备为什么必须先预创建。读完能对上 registerDevice / registerSubDevices,以及产品开关 registerEnabled。

默认端口 48080 只服务管理端。设备注册打的是网关进程,再 RPC 回 iot-server。产品开关见 产品管理。

示意图:网关验完协议后调管理端 RPC。管理端再验 productSecret 签名。

从哪改 ​

名称说明仓库路径
注册实现registerDevice / registerSubDevicesruoyi-office/yudao-module-iot/.../device/IotDeviceServiceImpl.java
RPC/rpc-api/iot/device/register、/register-subIoTDeviceApiImpl
签名HMAC-SHA256IotProductAuthUtils
HTTP 入口示例POST /auth/register/deviceyudao-module-iot-gateway/.../IotHttpRegisterHandler.java

直连 / 网关:产品必须 registerEnabled=true。签名内容是 deviceName{名}productKey{键},密钥是 productSecret,算法 HMAC-SHA256 hex。通过后自动插入 iot_device,返回 deviceSecret。同一 productKey + deviceName 已存在会抛已注册。

子设备:产品 deviceType 必须是 1。设备行必须事先在管理端建好。网关代理注册,成功后写 gatewayId,返回已有 deviceSecret。不会像直连那样新建子设备行。

方法名:thing.auth.register、thing.auth.register.sub(IotDeviceMessageMethodEnum)。MQTT 常见 topic:/sys/{productKey}/{deviceName}/thing/auth/register。HTTP / CoAP 走 /auth/register/device 与 /auth/register/sub-device/{productKey}/{deviceName}。

关 registerEnabled 后直连注册抛 DEVICE_REGISTER_DISABLED。签名错抛密钥无效。

字段 ​

名称说明仓库路径
productKey / deviceName / sign直连注册请求IotDeviceRegisterReqDTO
productSecret签名密钥,在产品行IotProductDO
deviceSecret注册成功后发给设备IotDeviceRegisterRespDTO
gatewayProductKey / subDevices子设备批量注册IotSubDeviceRegisterFullReqDTO

子设备和直连不是同一套规则

直连:未建设备 → 自动建。子设备:未建设备 → 失败。不要拿直连脚本去注册 deviceType=1 的产品。

签名不要自己拼 JSON

IotProductAuthUtils.buildContent 固定拼接 deviceName + 名 + productKey + 键。字段顺序错了,验签必失败。

示意图:按本仓库实现画的时序。

配置与操作 ​

管理端没有「动态注册」叶子。产品页打开 registerEnabled,设备打网关注册接口,网关再 RPC /rpc-api/iot/device/register。签名内容固定 deviceName{名}productKey{键},密钥 productSecret,HMAC-SHA256 hex。直连通过后自动插入 iot_device 并回 deviceSecret。

子设备产品必须 deviceType=1 且事先建行,不会自动新建。关 registerEnabled 抛 DEVICE_REGISTER_DISABLED。开启见 IoT 功能设计。

IoT 产品

本系统截图:产品页。动态注册开关在产品行 registerEnabled,没有独立注册菜单。

相关篇 ​

联系我们

获取报价、演示和二开方案

微信咨询二维码

微信咨询

17156169080

添加时备注「RuoYi Office」

在线体验商业版