利用M2M实现设施之间联动
方案设计
基于IoT物联网平台中规定引擎的M2M能力,咱们能够实现设施间联动通信,技术计划如下:
1.创立产品
1.1 油烟机
创立设施
通信Topic
1.2 燃气灶
创立设施
通信Topic
2.注册设施
2.1 油烟机设施
2.2 燃气灶设施
注册设施,并绑定指标油烟机
3.规定引擎配置 M2M规定
3.1 解决数据
SELECT
attribute('targetId') as rangehoodId,
status,
windPower
FROM
"/a****h/+/user/change/rangehood"
3.2 转发数据
4.设施开发
4.1 油烟机设施
设施端开发
const mqtt = require('aliyun-iot-mqtt');
var options = {
productKey: "替换",
deviceName: "替换",
deviceSecret: "替换",
regionId: "cn-shanghai"
};
//建设连贯
const client = mqtt.getAliyunIotMqttClient(options);
client.subscribe(`/${options.productKey}/${options.deviceName}/user/control/params`)
client.on('message', function(topic, message) {
console.log("sub topic => " + topic)
console.log("message => " + message)
})
4.2 燃气灶设施
设施端开发
const mqtt = require('aliyun-iot-mqtt');
var options = {
productKey: "替换",
deviceName: "替换",
deviceSecret: "替换",
regionId: "cn-shanghai"
};
var pubTopic = `/${options.productKey}/${options.deviceName}/user/change/rangehood`;
//建设连贯
const client = mqtt.getAliyunIotMqttClient(options);
//上报数据
client.publish(pubTopic, getPostData(), { qos: 0 });
function getPostData() {
const payloadJson = {
status: "on", //on,off
windPower: "high" //low,middle,high
}
console.log("Pub Topic => " + pubTopic)
console.log("Payload => " + JSON.stringify(payloadJson))
return JSON.stringify(payloadJson);
}
5.联机运行
5.1 设施启动
油烟机
$ node range-hood.js
sub topic => /a1zTlSPM9Ni/s001/user/control/params
message => {"windPower":"high","rangehoodId":"s001","status":"on"}
燃气灶
$ node gas-stove.js
Pub Topic => /a****h/z001/user/change/rangehood
Payload => {"status":"on","windPower":"high"}
5.2 设施运行日志
【往期回顾】
1.自建MQTT集群迁徙阿里云IoT平台
2.IoT时代:WiFi配网技术分析
3.微信小程序和IoT智能家居实际
4.IoT云端通用数据解析脚本实际
物联网平台产品介绍详情:https://www.aliyun.com/produc…
阿里云物联网平台客户交换群
发表回复