打开AliyunIoTSDK.cpp
将
修改为
这是因为Topic中sys是系统的topic,而我们在云规则流转中自定义的topic无sys,并且后缀post和自定义的get也不同
(2)第二步 mqttCheckConnect();后添加订阅topic
注意:按照自定义的Topic填写信息,${deviceName}要改为自己的设备名
(3)产品--功能定义--编辑草稿--添加自定义功能 填写完成--确认-->发布上线
标识符很重要,在程序中若要修改要统一修改,我们直接不改
这样物模型就发布成功了,topic属性列表中可以看到物模型的属性设置
回到arduino,在回调函数中添加语句,将修改后的代码重新下载,打开串口
物联网平台--监控运维--在线调试-------------------设置,显示发送指令成功
arduino串口显示: 接收到的数据
state is connected
Message arrived [/sys/k0zglvFLrJ6/servo/thing/service/property/set] {"method":"thing.service.property.set","id":"1652122612","params":{"PowerSwitch":1},"version":"1.0.0"}
state is connected
state is connected
state is connected
state is connected
state is connected
物模型的topic,后面是物模型,系统topic无法转发,只能转发自定义topic
复制{"method":"thing.service.property.set","id":"1652122612","params":{"PowerSwitch":1},"version":"1.0.0"}
在设备--舵机端--topic列表-----发布消息---粘贴
打开串口滚屏---然后确认---查看串口
state is connected
Message arrived [/k0zglvFLrJ6/servo/user/get] {"method":"thing.service.property.set","id":"550946820","params":{"PowerSwitch":1},"version":"1.0.0"}11111
state is connected
串口中出现了1111,说明通过阿里云成功控制了开发板,对应之前写的程序
如果PowerSwitch == 1,则串口打印11111,调试成功
如果PowerSwitch == 角度值,则执行对应角度程序