前言
关于 mqtt 相关文章分类:https://blog.csdn.net/freewebsys/article/category/8677221
本文的原文连接是: https://blog.csdn.net/freewebsys/article/details/88840907
未经博主允许不得转载。
博主地址是:http://blog.csdn.net/freewebsys
1,关于
阿里物联网:
https://iot.console.aliyun.com/quick_start
快速入门:
2,使用
第一步输入一个产品名称和设备名称:
第二步,创建成功:
第三步下载sdk,
第四步,使用sdk工具包,模拟一个设备,进行控制,解压缩,然后执行 sh ./start.sh ,注意,不能执行 sh start.sh 需要加当前目录。
查看日志:https://iot.console.aliyun.com/lk/monitor/log
可以看到,下行,发送的控制命令:
其中脚本 start.sh 需要 java sdk 配置环境变量。会编译HelloWorld.java
sh ./start.sh
javac -classpath ".:./jar/iot-mqttclient.0.0.1.jar:./jar/mqttv3-1.2.0.jar:./jar/fastjson-1.2.40.jar:./jar/gson-2.7.jar:./jar/network-core-0.0.1.jar:./jar/iot-linkkit-java.jar:./jar/common-utils-0.0.1.jar:./jar/device_manager_java.jar:./jar/okhttp-3.1.0.jar:./jar/apiclient-0.0.1.jar:./jar/okio-1.6.0.jar" ./HelloWorld.java
2019-03-27 12:42:49.384 - [HelloWorld.java] - main(37):HelloWorld:args=[./device_id_password.json]
2019-03-27 12:42:49.539 - [PersistentEventDispatcher.java] - registerOnTunnelStateListener(88):com.aliyun.alink.linksdk.channel.core.persistent.event.PersistentEventDispatcher:registerOnTunnelStateListener()
2019-03-27 12:42:49.540 - [PersistentEventDispatcher.java] - registerOnPushListener(58):com.aliyun.alink.linksdk.channel.core.persistent.event.PersistentEventDispatcher:registerOnPushListener()
2019-03-27 12:42:49.542 - [PersistentNet.java] - init(43):PersistentNet:init(), SDK Ver = 0.3.0
2019-03-27 12:42:49.594 - [MqttNet.java] - init(70):MqttNet:init()
2019-03-27 12:42:49.594 - [MqttNet.java] - init(90):MqttNet:init(),default cert file
2019-03-27 12:42:49.862 - [MqttNet.java] - mqttClientConnect(307):MqttNet:mqtt client connect..,ssl://a1Xj26Q9ou6.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883
2019-03-27 12:42:50.134 - [MqttNet.java] - onSuccess(295):MqttNet:connect onSuccess
2019-03-27 12:42:50.135 - [MqttDefaulCallback.java] - connectComplete(49):MqttDefaulCallback:connectComplete,ssl://a1Xj26Q9ou6.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883
2019-03-27 12:42:50.135 - [PersistentEventDispatcher.java] - broadcastMessage(150):com.aliyun.alink.linksdk.channel.core.persistent.event.PersistentEventDispatcher:broadcastMessage(), what=1
2019-03-27 12:42:50.135 - [PersistentEventDispatcher.java] - OnTunnelState(225):com.aliyun.alink.linksdk.channel.core.persistent.event.PersistentEventDispatcher:OnTunnelState()
2019-03-27 12:42:50.135 - [HelloWorld.java] - onInitDone(110):HelloWorld:onInitDone result=null
2019-03-27 12:42:50.137 - [ThreadPool.java] - init(33):ThreadPool:core maybe <0 which will cause crash in specific platform: 8
2019-03-27 12:42:50.137 - [ThreadPool.java] - init(44):ThreadPool:Start a ThreadPool with scale between 8 -> 10and core:8
2019-03-27 12:42:50.138 - [MqttNet.java] - subscribeRrpc(194):MqttNet:subscribeRrpc(),topic = /sys/a1Xj26Q9ou6/light001/thing/service/property/set
2019-03-27 12:42:50.141 - [MqttSendExecutor.java] - asyncSend(162):MqttSendExecutor:subscribe: topic: [ /sys/a1Xj26Q9ou6/light001/thing/service/property/set ]
2019-03-27 12:42:50.142 - [MqttNet.java] - subscribeRrpc(217):MqttNet:subscribeRrpc(), registerRrpcListener
2019-03-27 12:42:50.142 - [MqttDefaulCallback.java] - registerRrpcListener(35):MqttDefaulCallback:registerRrpcListener(), topic = /sys/a1Xj26Q9ou6/light001/thing/service/property/set
2019-03-27 12:42:50.143 - [MqttDefaulCallback.java] - connectComplete(52):MqttDefaulCallback:after connectComplete
2019-03-27 12:42:50.180 - [HelloWorld.java] - onSubscribeSuccess(121):HelloWorld:subscribe successfully
2019-03-27 12:42:52.142 - [HelloWorld.java] - reportState(160):HelloWorld:report Hello World.
2019-03-27 12:42:52.143 - [MqttSendExecutor.java] - asyncSend(129):MqttSendExecutor:publish: topic: [ /sys/a1Xj26Q9ou6/light001/thing/event/property/post ]
2019-03-27 12:42:52.144 - [MqttSendExecutor.java] - asyncSend(130):MqttSendExecutor:publish: payload: [ {"id":"230788029","method":"thing.event.property.post","params":{"Status":1,"Data":"Hello, World!"},"version":"1.0"} ]
2019-03-27 12:42:52.146 - [MqttDefaulCallback.java] - deliveryComplete(85):MqttDefaulCallback:deliveryComplete! null
2019-03-27 12:42:52.146 - [HelloWorld.java] - onSuccess(166):HelloWorld:upload successfully
2019-03-27 12:42:57.142 - [HelloWorld.java] - reportState(160):HelloWorld:report Hello World.
2019-03-27 12:42:57.142 - [MqttSendExecutor.java] - asyncSend(129):MqttSendExecutor:publish: topic: [ /sys/a1Xj26Q9ou6/light001/thing/event/property/post ]
2019-03-27 12:42:57.142 - [MqttSendExecutor.java] - asyncSend(130):MqttSendExecutor:publish: payload: [ {"id":"230788029","method":"thing.event.property.post","params":{"Status":1,"Data":"Hello, World!"},"version":"1.0"} ]
2019-03-27 12:42:57.143 - [MqttDefaulCallback.java] - deliveryComplete(85):MqttDefaulCallback:deliveryComplete! null
2019-03-27 12:42:57.143 - [HelloWorld.java] - onSuccess(166):HelloWorld:upload successfully
2019-03-27 12:42:58.236 - [MqttDefaulCallback.java] - messageArrived(65):MqttDefaulCallback:messageArrived,topic = [/sys/a1Xj26Q9ou6/light001/thing/service/property/set] , msg = [{"method":"thing.service.property.set","id":"290963666","params":{"Status":1},"version":"1.0.0"}],
2019-03-27 12:42:58.237 - [PersistentEventDispatcher.java] - broadcastMessage(150):com.aliyun.alink.linksdk.channel.core.persistent.event.PersistentEventDispatcher:broadcastMessage(), what=3
2019-03-27 12:42:58.237 - [MqttDefaulCallback.java] - handleRrpcRequest(90):MqttDefaulCallback:handleRrpcRequest()
2019-03-27 12:42:58.259 - [HelloWorld.java] - onReceived(134):HelloWorld:Received a message: {"Status":1}
2019-03-27 12:42:58.259 - [MqttDefaulCallback.java] - onRrpcResponse(120):MqttDefaulCallback:onRrpcResponse(), reply topic = /sys/a1Xj26Q9ou6/light001/thing/service/property/set_reply
2019-03-27 12:42:58.260 - [MqttSendExecutor.java] - asyncSend(129):MqttSendExecutor:publish: topic: [ /sys/a1Xj26Q9ou6/light001/thing/service/property/set_reply ]
2019-03-27 12:42:58.260 - [MqttSendExecutor.java] - asyncSend(130):MqttSendExecutor:publish: payload: [ {"id":"123", "code":"200","data":{} } ]
2019-03-27 12:42:58.260 - [MqttDefaulCallback.java] - messageArrived(65):MqttDefaulCallback:messageArrived,topic = [/sys/a1Xj26Q9ou6/light001/thing/service/property/set] , msg = [{"method":"thing.service.property.set","id":"290963667","params":{"Data":"112"},"version":"1.0.0"}],
2019-03-27 12:42:58.260 - [PersistentEventDispatcher.java] - broadcastMessage(150):com.aliyun.alink.linksdk.channel.core.persistent.event.PersistentEventDispatcher:broadcastMessage(), what=3
2019-03-27 12:42:58.261 - [MqttDefaulCallback.java] - handleRrpcRequest(90):MqttDefaulCallback:handleRrpcRequest()
2019-03-27 12:42:58.261 - [HelloWorld.java] - onReceived(134):HelloWorld:Received a message: {"Data":"112"}
可以看到 日志 topic /sys/a1Xj26Q9ou6/light001/thing/service/property/set 接受到消息:HelloWorld:Received a message: {“Data”:“112”}
topic /sys/a1Xj26Q9ou6/light001/thing/event/property/post 发送消息 {“Status”:1,“Data”:“Hello, World!”}
查看产品的 topic :
可以看到默认的有 5 个topic ,3个发布 2个订阅。
3,总结
这个快速接入弄的挺好的。降低了iot接入的成本。并且。可以直接演示。
做一个 电灯的开关控制。可以看到日志。iot 接入流程方便很多。使用 3 分钟就完成了设备接入。
有好的东西要学习呢。
本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/88840907
博主地址是:http://blog.csdn.net/freewebsys