1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
| const messageId = "mdl_" + Date.now();
| const timestamp = Date.now();
| //nameSpace:命名空间,需要改改为正确的命名空间代码
| const nameSpace = "Environment"
| const clientCode = "Data-It_XzOffice";
| //此处需改为正确的设备实体唯一ID
| const deviceId = "sensor.miaomiaoc_cn_blt_3_11a1sbr5k5o01_t2_temperature_p_2_1";
| const deviceType = "sensor";
|
| // 按照胜透物联网通信协议生成物模型定义
| const modelMessage = {
| "messageId": messageId,
| "timestamp": timestamp,
| "clientCode": clientCode,
| "deviceId": deviceId,
| "deviceType": deviceType,
| "version": "1.0",
| "data": {
| "model": {
| "deviceInfo": {
| "manufacturer": "小米",
| "model": "MIAOMIAOC_CN_BLT_3_11A1SBR5K5O01_T2",
| "version": "1.0.0",
| "description": "米家温湿度传感器(通过HomeAssistant集成)"
| },
| "properties": {
| "temperature": {
| "dataType": "float",
| "unit": "°C",
| "range": {
| "min": -40,
| "max": 85
| },
| "precision": 1,
| "description": "环境温度"
| }
| },
| "events": {
| "startup": {
| "eventType": "info",
| "description": "设备启动事件"
| }
| },
| "alarms": {
| "TEMP_HIGH": {
| "alarmType": "threshold_exceeded",
| "description": "温度过高报警",
| "defaultThreshold": 35.0
| },
| "TEMP_LOW": {
| "alarmType": "threshold_exceeded",
| "description": "温度过低报警",
| "defaultThreshold": 0.0
| }
| }
| }
| }
| };
|
| // 设置MQTT发布主题
| msg.topic = `${nameSpace}/${deviceType}/${deviceId}/model`;
| msg.payload = JSON.stringify(modelMessage);
| msg.qos = 1;
|
| node.log("设备物模型数据已生成,发布到主题: " + msg.topic);
|
| return msg;
|
|