【鴻蒙】分佈式通訊子系統--讓華爲手機發現Hi3861開發板

目錄:session

工具app

步驟iview

運行結果socket

 

工具:工具

1. 華爲手機,須要有多設備協同功能。在設置->更多鏈接->多設備協同,查看是否有多設備協同功能,此功能使用的就是coap協議。oop

2. Hi3861開發板post

 

步驟:日誌

1.  修改源碼,發佈一個Serivcecode

2.  啓動Hi3861開發板,並鏈接WIFI,對Hi3861設備接收廣播和響應廣播處添加日誌,使用串口工具查看日誌。orm

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 <time: 0ms> success!
00 00:00:00 0 0 I 1/SAMGR: Init service 0x4c4c14 <time: 0ms> 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 <time: 0ms> 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 <time: 80ms> 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雲完美連通 】

相關文章
相關標籤/搜索