首页 > 云计算 > 公有云实践 > 利用规则引擎的M2M实现设备之间联动——实践类
基于IoT物联网平台中规则引擎的M2M能力,我们可以实现设备间联动通信,技术方案如下:

创建设备
通信Topic

创建设备
通信Topic


注册设备,并绑定目标油烟机



SELECT
attribute('targetId') as rangehoodId,s
tatus,
windPower
FROM
"/a****h/+/user/change/rangehood"

设备端开发
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)
})
设备端开发
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);
}
油烟机
$ 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"}


1.自建MQTT集群迁移阿里云IoT平台
2.IoT时代:WiFi配网技术剖析
3.微信小程序和IoT智能家居实践
4.IoT云端通用数据解析脚本实践

阿里云物联网平台客户交流群
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70017009/viewspace-2937327/ ,如需转载,请注明出处,否则将追究法律责任。