赞
踩
目录:
工具
步骤
运行结果
工具:
1. 华为手机,需要有多设备协同功能。在设置->更多连接->多设备协同,查看是否有多设备协同功能,此功能使用的就是coap协议。
2. Hi3861开发板
步骤:
1. 修改源码,发布一个Serivce
2. 启动Hi3861开发板,并连接WIFI,对Hi3861设备接收广播和响应广播处添加日志,使用串口工具查看日志。
3. 使用路由器上进行抓包。udp,端口是5684
4. 将多设备协同开关打开。在打开开关的瞬间,可以看到Hi3861开发板接收到了多条广播请求,同时对多条广播进行响应
运行结果:
可以看到Hi3861开发板对华为手机发现设备时发出的广播进行响应,但手机上并没有展示出Hi3861设备信息,可能是还需要一些其他信息,或者传递的信息手机并不支持,具体原因不详,不清楚手机端对Hi3861发送的响应报文是如何处理的,但Hi3861通过HarmonyOS系统能力,已经能成功与手机进行交互了。下一步就是通过解决如何在手机上展示并通过HarmonyOS系统能力进行通信,如获取设备温度。
下面一张截图中手机的IP是192.168.1.216,Hi3861开发板的IP是192.168.1.232,可以看到开发板对手机广播的成功响应。
[18:56:32.719]收←◆ready to OS start
sdk ver:Hi3861V100R001C00SPC025 2020-09-03 18:10:00
formatting spiffs...
[18:56:33.040]收←◆FileSystem mount ok.
wifi init success!
GetService name:GetService name:
get feature name.
GetService name:
get feature name.
[Register Test][TaskID:954112][Step:0][Reg S:example, F:example] Time: 330!
GetService name:
GetService name:
GetService name:[Boot Test][TaskID:0xe8c44][Step:1][Reg Finish S:example]Time: 340!
GetService name:Register Test,Oninit1Register Test,Oninit
[DISCOVERY] InitLocalDeviceInfo ok
[DISCOVERY] Init socket success.
[DISCOVERY] liteos_m init wifi event.
[DISCOVERY]CoapInitWifiEvent()
[DISCOVERY]CreateMsgQue()
[DISCOVERY]OnWifiConnectionChanged bind.()
[DISCOVERY]RegisterWifiEvent()
[DISCOVERY]RegisterWifiEvent success.
[DISCOVERY]create message queue task.
[DISCOVERY]create message queue success.
[DISCOVERY] init cop listen thread.
[DISCOVERY] CreateCoapListenThread
[DISCOVERY] CreateCoapListenThread2
[DISCOVERY]CoapWriteMsgQueue().
[DISCOVERY] InitService ok
[DISCOVERY] PublishCallback publishId=1, result=0
demo service publish success.1get feature name.GetService name:[DISCOVERY]ReadMsgQue().
[DISCOVERY]CoapHandleWifiEvent().
[DISCOVERY] WifiEventTrigger 1.
[DISCOVERY] WifiEventTrigger[DISCOVERY] CoapReadHandle()
[DISCOVERY] CoapReadHandle coin select begin
[DISCOVERY] CoapReadHandle, select
GetCommonDeviceInfo is success.
[DISCOVERY] CoapGetIp().
[DISCOVERY] WifiEventTrigger .
[DISCOVERY] WifiEventTrigger ret is 0.
[DISCOVERY] WifiEventTrigger BusManager().
[TRANS] OpenTcpServer inet_pton fail, rc=0:(null)
[TRANS] InitListenFd OpenTcpServer fail
[AUTH] StartBus StartListener fail
[DISCOVERY] WifiEventTrigger StartBusManager(1) fail
[DISCOVERY]ReadMsgQue().
00 00:00:00 0 68 D 0/HIVIEW: hilog init success.
00 00:00:00 0 68 D 0/HIVIEW: log limit init success.
00 00:00:00 0 68 I 1/SAMGR: Bootstrap core services(count:3).
00 00:00:00 0 68 I 1/SAMGR: Init service:0x4c4c14 TaskPool:0xfa9a4
00 00:00:00 0 68 I 1/SAMGR: Init service:0x4c4c38 TaskPool:0xfb014
00 00:00:00 0 68 I 1/SAMGR: Init service:0x4c6d88 TaskPool:0xfb1d4
00 00:00:00 0 100 I 1/SAMGR: Init service 0x4c4c38 success!
00 00:00:00 0 0 I 1/SAMGR: Init service 0x4c4c14 success!
00 00:00:00 0 200 D 0/HIVIEW: hiview init success.
00 00:00:00 0 200 I 1/SAMGR: Init service 0x4c6d88 success!
00 00:00:00 0 200 I 1/SAMGR: Initialized all core system services!
00 00:00:00 0 0 I 1/SAMGR: Bootstrap system and application services(count:1).
00 00:00:00 0 0 I 1/SAMGR: Init service:0x4c4cf0 TaskPool:0xeba70
00 00:00:00 0 68 I 1/SAMGR: Init service 0x4c4cf0 success!
00 00:00:00 0 68 I 1/SAMGR: Initialized all system and application services!
00 00:00:00 0 0 I 1/SAMGR: Bootstrap dynamic registered services(count:0).
[18:56:53.855]发→◇AT+STARTSTA
□
[18:56:53.860]收←◆AT+STARTSTAbusy!
busy!
busy!
OK
[18:57:03.997]发→◇AT+CONN=,86:73:03:de:fc:14,3,"12345678"
□
[18:57:04.002]收←◆AT+CONN=,86:73:03:de:fc:14,3,"12345678"busy!
busy!
busy!
busy!
OK
[18:57:04.780]收←◆+NOTICE:SCANFINISH
[18:57:05.265]收←◆+NOTICE:CONNECTED
[DISCOVERY]CoapConnectionChangedHandler().
[DISCOVERY]CoapWriteMsgQueue().
[DISCOVERY]CoapHandleWifiEvent().
[DISCOVERY] WifiEventTrigger 1.
[DISCOVERY] WifiEventTrigger GetCommonDeviceInfo is success.
[DISCOVERY] CoapGetIp().
[18:57:20.196]发→◇AT+DHCP=wlan0,1
□
[18:57:20.200]收←◆AT+DHCP=wlan0,1busy!
busy!
OK
[18:57:21.210]收←◆[DISCOVERY] WifiEventTrigger 192.168.43.112.
[DISCOVERY] WifiEventTrigger ret is 0.
[DISCOVERY] WifiEventTrigger BusManager().
[TRANS] OpenTcpServer inet_pton rc=1
[TRANS] OpenTcpServer fd=1
[TRANS] WaitProcess begin
[TRANS] StartListener ok
[TRANS] OpenTcpServer inet_pton rc=1
[TRANS] OpenTcpServer fd=2
[TRANS] StartSelectLoop create trans_session_task
[TRANS] SelectSessionLoop begin
[AUTH] StartBus ok
[DISCOVERY] WifiEventTrigger CoapRegisterDeviceInfo().
[DISCOVERY]ReadMsgQue().
[18:57:36.642]收←◆[DISCOVERY] HandleReadEvent()
[DISCOVERY] COAP_SoftBusDecode()
[DISCOVERY] PostServiceDiscover()
[DISCOVERY] GetServiceDiscoverInfo()
[DISCOVERY] GetServiceDiscoverInfo()
[DISCOVERY] ParseServiceDiscover()
{"deviceId":"{\"UDID\":\"EB1204FC4F250C892EBD67E46D0CEA03FFC16347541C95954434F22494231CCE\"}","devicename":"nova 5 Pro","type":14,"hicomversion":"2.1.0.0","mode":1,"deviceHash":"2850086000394994110","serviceData":"","wlanIp":"192.168.43.241","capabilityBit[DISCOVERY] ParseServiceDiscover(coap://192.168.43.241/device_discover)
[DISCOVERY]CoapResponseService().
[DISCOVERY]PrepareServiceDiscover().
[DISCOVERY]init data().
{"deviceId":"{\"UDID\":\"BE753141CDEC87CE61D564BFD84C908E966011DEB00BF46690FC97B133AA795B\"}","devicename":"DEV_L0","type":241,"hicomversion":"","mode":0,"deviceHash":"4174638","serviceData":"port:56968,,","wlanIp":"192.168.43.112","capabilityBitmap":[64]}[DISCOVERY]CoapSendRequest().
[DISCOVERY]CoapSendRequest remote ip:192.168.43.241.
CoapSocketSend:3,294
send result:294\[DISCOVERY]send success.
[DISCOVERY] CoapReadHandle, select
[DISCOVERY] HandleReadEvent()
[DISCOVERY] COAP_SoftBusDecode()
[DISCOVERY] PostServiceDiscover()
[DISCOVERY] GetServiceDiscoverInfo()
[DISCOVERY] GetServiceDiscoverInfo()
[DISCOVERY] ParseServiceDiscover()
{"deviceId":"{\"UDID\":\"EB1204FC4F250C892EBD67E46D0CEA03FFC16347541C95954434F22494231CCE\"}","devicename":"nova 5 Pro","type":14,"hicomversion":"2.1.0.0","mode":1,"deviceHash":"2850086000394994110","serviceData":"","wlanIp":"192.168.43.241","capabilityBit
[DISCOVERY] ParseServiceDiscover(coap://192.168.43.241/device_discover)
[DISCOVERY]CoapResponseService().
[DISCOVERY]PrepareServiceDiscover().
[DISCOVERY]init data().
{"deviceId":"{\"UDID\":\"BE753141CDEC87CE61D564BFD84C908E966011DEB00BF46690FC97B133AA795B\"}","devicename":"DEV_L0","type":241,"hicomversion":"","mode":0,"deviceHash":"4174638","serviceData":"port:56968,,","wlanIp":"192.168.43.112","capabilityBitmap":[64]}[DISCOVERY]CoapSendRequest().
[DISCOVERY]CoapSendRequest remote ip:192.168.43.241.
CoapSocketSend:4,294
send result:294\[DISCOVERY]send success.
[DISCOVERY] CoapReadHandle, select
作者:mb5f8960971f61a
想了解更多内容,请访问: 51CTO和华为官方战略合作共建的鸿蒙技术社区https://harmonyos.51cto.com
【免费直播公开课- 让鸿蒙智能家居开发板与AWS IoT云完美连通 】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。