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;