OpenThread COAP Client to a public server over Internet

Hello,

I am trying to make a Thread COAP Client on nRF52840 DK work with coap.me public server. I have created a Border Router with a Raspberry Pi and a nRF52 dongle and I am sure that it works as I can ping and run COAP CLI commands successfully with the OpenThread CLI sample. I can COAP GET and PUT to coap.me.

The coap.me IPv6 address was converted by me with the well known 64:ff9b::/96 prefix. The path was added to the border router as I can see with ot netdata show. 

The problem is with the COAP Client sample provided. I modified the destination IPv6 address to be the same I use with the CLI sample and the URI path to "coap://coap.me:5683/hello". I have also tried just "hello". No luck so far. 

As I said the CLI sample works fine: I get a response which is "world". Here the CLI commands I use after having joined the Thread network:

ot coap start

ot coap get 64:ff9b:0:0:0:0:8666:da12 hello 

NOTE: in my COAP client program the Thread network is joined automatically as I have added the following options:

CONFIG_OPENTHREAD_JOINER=y
CONFIG_OPENTHREAD_JOINER_AUTOSTART=y
CONFIG_OPENTHREAD_JOINER_PSKD="J01NME"

Indeed I can ping the Border router IPV6 address from my board running the modified COAP Client and vice-versa so they see each other. 

Can you please help to understand why my program directly derived from your COAP client sample does not work while CLI works fine?

Thank you.

Marco

Parents
  • Hi Marco,

    Sorry, I understand what you mean now. Could you share your modification to the CoAP client sample and log during running?

    The reason is to demonstrate developers different CoAP API options they can use for the development, but Zephyr’s CoAP API is the encouraged option.

    Best regards,

    Charlie

  • I did some code clean up and launched the program again to capture the log for you.

    The behaviour is the same. Looks like the UDP frame is sent and received back without going out. I have disabled 802.15.4 frames log but let me know if you want me to capture again with that enabled. For now only IPV6 log is enabled. 

    I also had to increase the coap thread stack size in coap_utils.c (nrf/subsys/net/lib/coap_util).

    I had to rename the .conf file to .txt

    # Enable net module logging
    CONFIG_NET_LOG=y
    # Option for configuring log level in net config library
    CONFIG_NET_CONFIG_LOG_LEVEL_INF=y
    
    # Option for configuring log level in Zephyr L2 logging
    CONFIG_OPENTHREAD_L2_DEBUG=y
    CONFIG_OPENTHREAD_L2_LOG_LEVEL_DBG=y
    #CONFIG_OPENTHREAD_L2_DEBUG_DUMP_15_4=y
    CONFIG_OPENTHREAD_L2_DEBUG_DUMP_IPV6=y
    
    # Option for configuring log level in OpenThread
    CONFIG_OPENTHREAD_LOG_LEVEL_INFO=y
    
    # nRF board library
    CONFIG_DK_LIBRARY=y
    
    # Enable CoAP utils and CoAP protocol
    CONFIG_COAP_UTILS=y
    
    # Configure sample logging setting
    CONFIG_LOG=y
    CONFIG_COAP_CLIENT_LOG_LEVEL_DBG=y
    CONFIG_COAP_CLIENT_LOG_LEVEL_INF=y
    CONFIG_COAP_CLIENT_UTILS_LOG_LEVEL_DBG=y
    CONFIG_COAP_UTILS_LOG_LEVEL_DBG=y
    CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y
    CONFIG_OPENTHREAD_DEBUG=y
    CONFIG_OPENTHREAD_JOINER=y
    CONFIG_OPENTHREAD_JOINER_AUTOSTART=y
    CONFIG_OPENTHREAD_JOINER_PSKD="J01NME"
    
    CONFIG_OPENTHREAD_THREAD_STACK_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
    
    # Adjust log strdup settings
    
    # Generic networking options
    CONFIG_NETWORKING=y
    
    # L2 OpenThread enabling
    CONFIG_NET_L2_OPENTHREAD=y
    
    # Network shell
    #CONFIG_SHELL=y
    #CONFIG_OPENTHREAD_SHELL=y
    #CONFIG_SHELL_ARGC_MAX=26
    #CONFIG_SHELL_CMD_BUFF_SIZE=416
    
    # Network sockets
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_SOCKETS_POLL_MAX=4
    
    CONFIG_ASSERT=y
    CONFIG_ASSERT_NO_COND_INFO=y
    CONFIG_MBEDTLS_SHA1_C=n
    CONFIG_FPU=y
    
    CONFIG_IDLE_STACK_SIZE=4096
    CONFIG_MAIN_STACK_SIZE=4096
    
    CONFIG_DEBUG_OPTIMIZATIONS=y
    CONFIG_THREAD_MONITOR=y
    CONFIG_THREAD_STACK_INFO=y
    CONFIG_TIMESLICING=n
    CONFIG_THREAD_NAME=y
    CONFIG_DEBUG_THREAD_INFO=y
    CONFIG_OPENTHREAD_SOURCES=y
    CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096
    

    Steps from the log:

    1) I launch the program

    2) start commissioning on the border router

    3) press button 1 to join the thread network with assigned passphrase

    4) press button 2 to send a message (COAP GET)

    [00:03:09.048,095] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:03:09.048,126] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:03:09.048,187] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                09 d8 48 ff ff ff ff 34  12 bd 8e 98 0c 06 51 6c |..H....4 ......Ql
                                                42 15 c1 09 00 00 ff ff  ff ff ff 14 0b d9 11 d3 |B....... ........
                                                23 19 a8 a9 a4 f6 93 aa  79 11 89 19 b3 1f 7b 80 |#....... y.....{.
                                                08 18 38 a6 38 05 d8 39  4c e6 8a 43 01 7f 78 bf |..8.8..9 L..C..x.
                                                a2 29 df cd 79 41 ab 5d  0a 20 80 e7 21 66       |.)..yA.] . ..!f  
    [00:03:09.049,468] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:83, chksum:40b4, ecn:no, from:426c51060c988ebd, sec:yes, prio:net, rss:-61.0
    [00:03:09.049,774] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:406c:5106:c98:8ebd]:19788
    [00:03:09.050,079] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:03:09.051,025] <inf> net_openthread: [I] Mle-----------: Receive Announce (fe80:0:0:0:406c:5106:c98:8ebd)
    [00:03:11.509,796] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:03:11.509,826] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:03:11.509,918] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                41 d8 05 34 12 ff ff b1  67 af 82 05 7e d4 d2 7f |A..4.... g...~...
                                                3b 01 f0 4d 4c 4d 4c 5e  26 00 15 e6 16 00 00 00 |;..MLML^ &.......
                                                00 00 00 01 3b 80 ee 8b  0a 74 af 7b b8 eb 74 f9 |....;... .t.{..t.
                                                80 6b ac 6d d6 a8 c4 27  ba fe da 31 4e 9a 90 bb |.k.m...' ...1N...
                                                71 0f c8 c7 54 26 1c                             |q...T&.          
    [00:03:11.510,711] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:92, chksum:5e26, ecn:no, from:d2d47e0582af67b1, sec:no, prio:net, rss:-54.0
    [00:03:11.511,016] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:d0d4:7e05:82af:67b1]:19788
    [00:03:11.511,322] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:03:11.512,329] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:d0d4:7e05:82af:67b1,0xf000)
    [00:03:11.858,032] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:03:11.858,062] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:03:11.858,123] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                41 d8 49 34 12 ff ff bd  8e 98 0c 06 51 6c 42 7f |A.I4.... ....QlB.
                                                3b 01 f0 4d 4c 4d 4c fb  d0 00 15 52 76 00 00 00 |;..MLML. ...Rv...
                                                00 00 00 01 e0 a5 96 ca  27 e1 26 37 62 c4 dc 87 |........ '.&7b...
                                                f2 54 c2 58 fa 09 b9 36  4d f8 a8 45 ce e3 52 5c |.T.X...6 M..E..R\
                                                96 d6 f7 d2 32 20 ab                             |....2 .          
    [00:03:11.858,917] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:92, chksum:fbd0, ecn:no, from:426c51060c988ebd, sec:no, prio:net, rss:-60.0
    [00:03:11.859,252] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:406c:5106:c98:8ebd]:19788
    [00:03:11.859,558] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:03:11.860,534] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:406c:5106:c98:8ebd,0x3000)
    [00:03:13.917,510] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:03:13.923,065] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:6d92, ecn:no, to:0xffff, sec:no, prio:net
    [00:03:13.923,400] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:03:13.923,706] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    [00:00:00.003,540] <inf> ieee802154_nrf5: nRF5 802154 radio initialized
    [00:00:00.003,601] <dbg> net_l2_openthread: openthread_init: (main): openthread_init
    [00:00:00.106,842] <inf> fs_nvs: 8 Sectors of 4096 bytes
    [00:00:00.106,842] <inf> fs_nvs: alloc wra: 0, f90
    [00:00:00.106,872] <inf> fs_nvs: data wra: 0, f8
    [00:00:00.106,933] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 1 aIndex 0
    [00:00:00.108,459] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 2 aIndex 0
    [00:00:00.108,764] <dbg> net_otPlat_settings: otPlatSettingsGet: aKey 2 aIndex 0 not found
    [00:00:00.108,795] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 3 aIndex 0
    [00:00:00.109,283] <inf> net_openthread: [I] Settings------: Read NetworkInfo {rloc:0x9c00, extaddr:727ceb24c42e4979, role:router, mode:0x0f, version:4, keyseq:0x0, ...
    [00:00:00.109,588] <inf> net_openthread: [I] Settings------: ... pid:0x132fd334, mlecntr:0x3eb, maccntr:0x3e9, mliid:98c00112c8282455}
    [00:00:00.109,619] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 5 aIndex 0
    [00:00:00.109,924] <dbg> net_otPlat_settings: otPlatSettingsGet: aKey 5 aIndex 0 not found
    [0m<inf> net[00:00:00.ad: State changed! Flag0 Current role: disabled
    [00:00:00.112,457] <dbg> net_l2_openthread: openthread_enable: (main): iface 0x200006c0 up
    : openthread_enable: (mhread manual
    [00:00 ALL!!!
    [00:00:00.116,973] <dbg> ccket: Open socket...
    [00:00:00.117,156] <dbg> coap_utils: coap_open_socket: Socket opened su00:00:00.117,156] <dbg> coap_utils: coap_open_socket: Open socket DONE!
    [00:00:00.117,523] <dbg> coap_init: CoAP socket receive thread started*** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    [00:00:00.003,540] <inf> ieee802154_nrf5: nRF5 802154 radio initialized
    [00:00:00.003,601] <dbg> net_l2_openthread: openthread_init: (main): openthread_init
    [00:00:00.106,842] <inf> fs_nvs: 8 Sectors of 4096 bytes
    [00:00:00.106,872] <inf> fs_nvs: alloc wra: 0, f90
    [00:00:00.106,872] <inf> fs_nvs: data wra: 0, f8
    [00:00:00.106,964] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 1 aIndex 0
    [00:00:00.108,459] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 2 aIndex 0
    [00:00:00.108,764] <dbg> net_otPlat_settings: otPlatSettingsGet: aKey 2 aIndex 0 not found
    [00:00:00.108,795] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 3 aIndex 0
    [00:00:00.109,283] <inf> net_openthread: [I] Settings------: Read NetworkInfo {rloc:0x9c00, extaddr:727ceb24c42e4979, role:router, mode:0x0f, version:4, keyseq:0x0, ...
    [00:00:00.109,619] <inf> net_openthread: [I] Settings------: ... pid:0x132fd334, mlecntr:0x3eb, maccntr:0x3e9, mliid:98c00112c8282455}
    [00:00:00.109,649] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 5 aIndex 0
    [00:00:00.109,954] <dbg> net_otPlat_settings: otPlatSettingsGet: aKey 5 aIndex 0 not found
    [00:00:00.110,961] <inf> net_openthread: [I] Notifier------: StateChanged (0x101fc300) [KeySeqCntr NetData Channel PanId NetName ExtPanId NetworkKey PSKc SecPolicy ...
    [00:00:00.111,145] <inf> net_openthread: [I] Notifier------: StateChanged (0x101fc300) ... ActDset]
    [00:00:00.111,206] <dbg> net_otPlat_settings: otPlatSettingsGet: otPlatSettingsGet Entry aKey 1 aIndex 0
    [00:00:00.111,785] <inf> net_openthread: [I] AnnounceSender: ChannelMask:{ 11-26 }, period:21500
    [00:00:00.111,907] <inf> net_openthread: [I] AnnounceSender: StartingChannel:15
    [00:00:00.112,030] <inf> net_openthread: [I] AnnounceSender: StartingChannel:15
    [00:00:00.112,060] <inf> net_l2_openthread: State changed! Flags: 0x101fc300 Current role: disabled
    [00:00:00.112,487] <dbg> net_l2_openthread: openthread_enable: (main): iface 0x200006c0 up
    [00:00:00.112,487] <dbg> net_l2_openthread: openthread_enable: (main): OpenThread manual start.
    [00:00:00.116,973] <inf> coap_client_utils: INIT ALL!!!
    [00:00:00.117,004] <dbg> coap_utils: coap_init: INIT CoAP.......
    [00:00:00.117,004] <dbg> coap_utils: coap_open_socket: Open socket...
    [00:00:00.117,156] <dbg> coap_utils: coap_open_socket: Socket opened successfully!
    [00:00:00.117,187] <dbg> coap_utils: coap_open_socket: Open socket DONE!
    [00:00:00.117,523] <dbg> coap_utils: coap_init: CoAP socket receive thread started
    296,966] <inf> net_l2_openthread: OpenThrea 5 2022 16:3[00:00:orkq): Open[00:00:et_l2_opentPromiscuous:--: Role disabled -> det: Attempt toer
    0] <infer, mode:0x0f, version Settings---4, mlecntr:0x3eb, maccn[0m
    [00:00:21.29dbg> net_otPlat_settings: otPlatSingsGet Entr:21.300,079] <dbg> net_otPlat_settings: otPlatSettingsSet: otPlatSettingsSet Entry aKey 3
    [00:00:21.325,592] <inf> net_ [I] Settings------: Saved NetworkInfo {rloc:0x9c00, extaddr:727ceb24c42e4979, role:router, mode:0x0f, version:4, keyseq:0x0, ...
    [00:00:21.325,927] <inf> lecntr:0x7d
    [00:0read: [I] Mle---------ged (0x0100 MLAddr Rloc<inf> net_openthread: [l2_openthread: State changed! Flagsd Current role: detache27,026] <dbg> net_ld: ot_state_changed_handler: (openthread): Ipvthread): Adding fd30:87c9:a6ab:19a2:98c0:112:c828:245578] <dbe80::707c:eb327,239] <dbg> net_d: ot_state[00:00:21.l2_openthrethread): Adding multicafd30:87c9:a6ab:19a2:0:1[00:00:21.3maddr_to_zepng multicas8] <dbg(openthread): Adding m[00:00:21.327,911] <dbg> net_l2_openthread: add_ipv6_maddr_to_zephyr: (openthread): Adding multicast ff03::fc
    [00:00:21.328,002] [[0m
    [00:00:21.328,521] <inf> coap_client: DISCONNECTED!
    [00:00:, sec:no, prio:net
    [00:03] <inf> net_openthread: [I] MeshForwarder-:     src:[788
    .333,648] [  dst:[ff02:0:0:0:0:0:0:2]:19788
    [00:00:22.040,405] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:00:22.040,435] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:00:22.040,527] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                61 dc 4f 34 12 79 49 2e  c4 24 eb 7c 72 bd 8e 98 |a.O4.yI. .$.|r...
                                                0c 06 51 6c 42 7f 33 f0  4d 4c 4d 4c 17 a6 00 15 |..QlB.3. MLML....
                                                56 76 00 00 00 00 00 00  01 49 14 07 7f 42 5b ca |Vv...... .I...B[.
                                                fb 66 02 0d c4 a0 15 28  42 60 26 7f 66 65 df cb |.f.....( B`&.fe..
                                                6f b9 c8 8c 89 ad db 24  28 30 19 0a 4a e5 a6 79 |o......$ (0..J..y
                                                53 3b b7 5d b5 60 54 8b  2e a1 8e 7f 29 e6 2b 4a |S;.].`T. ....).+J
                                                e2 54 a3 69 0b 36 08 63  65 dc f7 22 00          |.T.i.6.c e..".   
    --- 11 messages dropped ---
    [00:00:22.070,556] <inf> net_openthread: [I] AnnounceSender: Started
    [00:00:22.070,587] <inf> net_l2_openthread: State changed! Flags: 0x00001084 Current role: router
    [00:00:22.070,587] <dbg> net_l2_openthread: ot_state_changed_handler: (openthread): Ipv6 multicast address added
    [00:00:22.070,739] <dbg> net_l2_openthread: add_ipv6_maddr_to_zephyr: (openthread): Adding multicast ff02::2
    [00:00:22.070,892] <dbg> net_l2_openthread: add_ipv6_maddr_to_zephyr: (openthread): Adding multicast ff03::2
    [00:00:22.071,075] <inf> coap_client_utils: Thread state changed: 1084
    [00:00:22.071,136] <inf> coap_client_utils: Mesh Local EID Address: fd30.87c9.a6ab.19a2.00.0ff.fe0.9c0
    [00:00:22.071,136] <inf> coap_client_utils: Mesh Local EID Address: fd30.87c9.a6ab.19a2.98c0.112.c828.2455
    [00:00:22.071,166] <inf> coap_client_utils: Mesh Local EID Address: fe80.00.00.00.707c.eb24.c42e.4979
    [00:00:22.071,899] <inf> coap_client: CONNECTED!
    [00:00:22.075,622] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:77, chksum:0078, ecn:no, to:426c51060c988ebd, sec:no, prio:net
    [00:00:22.075,927] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:22.076,263] <inf> net_openthread: [I] MeshForwarder-:     dst:[fe80:0:0:0:406c:5106:c98:8ebd]:19788
    [00:00:22.085,723] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:00:22.085,754] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:00:22.085,815] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                79 dc 50 34 12 79 49 2e  c4 24 eb 7c 72 bd 8e 98 |y.P4.yI. .$.|r...
                                                0c 06 51 6c 42 0d e1 06  00 00 01 81 09 1f aa 42 |..QlB... .......B
                                                b7 eb 90 f1 57 0d 87 61  45 26 6f 8b f5 72 3a f7 |....W..a E&o..r:.
                                                71 1a f2 8e bf 04 70 5f  2b f3 74 31 af d3 d2 17 |q.....p_ +.t1....
                                                47 11 f0 63 f7 25 e8 a7  cc 68 c4 d5 5f 6e 1e 6a |G..c.%.. .h.._n.j
                                                56 27 ad 38 52 7e 4e a6  00 9b 60 04 7a 4b 48 fb |V'.8R~N. ..`.zKH.
                                                92 12 5e e3 27 1c bf 02  ac 3b 27 fa 95 97 a9 82 |..^.'... .;'.....
                                                c8 3b 8e 25 e2 ef a9 d3  98 00 d9 22 22 00       |.;.%.... ..."".  
    [00:00:22.093,383] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:00:22.093,383] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:00:22.093,475] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                79 dc 51 34 12 79 49 2e  c4 24 eb 7c 72 bd 8e 98 |y.Q4.yI. .$.|r...
                                                0c 06 51 6c 42 0d e2 06  00 00 01 ff d5 ca 37 65 |..QlB... ......7e
                                                4a 77 d1 a2 3b f2 b2 b1  f3 8b 22 55 cb ab e8 9a |Jw..;... .."U....
                                                ff 33 85 44 cb 85 aa 80  9d e6 66 72 03 68 a0 11 |.3.D.... ..fr.h..
                                                71 3a c4 13 7a 32 5f d1  ba 73 be 33 79 f4 97 9c |q:..z2_. .s.3y...
                                                75 56 fc 9b 32 61 88 9f  96 42 cf 01 84 52 96 d5 |uV..2a.. .B...R..
                                                b3 73 05 d5 a2 23 4c 26  bd 10 03 72 cc ed 65 71 |.s...#L& ...r..eq
                                                9d 36 f8 49 f7 8f ee d6  cd 2b c3 41 22 00       |.6.I.... .+.A".  
    [00:00:22.100,769] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:00:22.100,799] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:00:22.100,891] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                69 dc 52 34 12 79 49 2e  c4 24 eb 7c 72 bd 8e 98 |i.R4.yI. .$.|r...
                                                0c 06 51 6c 42 0d e3 06  00 00 01 70 b5 8e b5 77 |..QlB... ...p...w
                                                95 77 58 f1 bb d5 55 a6  31 19 05 67 c9 c0 ee 58 |.wX...U. 1..g...X
                                                05 19 f5 76 b0 d3 9e df  40 cc 7a 69 22 d3       |...v.... @.zi".  
    [00:00:22.102,050] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:240, chksum:21cb, ecn:no, from:426c51060c988ebd, sec:yes, prio:net, rss:-60.25
    [00:00:22.102,355] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:406c:5106:c98:8ebd]:19788
    [00:00:22.102,661] <inf> net_openthread: [I] MeshForwarder-:     dst:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:22.104,370] <inf> net_openthread: [I] Mle-----------: Receive Data Response (fe80:0:0:0:406c:5106:c98:8ebd)
    [00:00:22.104,736] <inf> net_openthread: [I] Notifier------: StateChanged (0x00000200) [NetData]
    [00:00:22.105,255] <inf> net_openthread: [I] Mle-----------: Delay Data Response (ff02:0:0:0:0:0:0:1)
    [00:00:22.105,438] <inf> net_openthread: [I] BbrLeader-----: PBBR state: Added
    [00:00:22.105,590] <inf> net_openthread: [I] BbrLeader-----: Rloc16: 0x3000, seqno: 21, delay: 1200, timeout 3600
    [00:00:22.105,804] <inf> net_openthread: [I] BbrLeader-----: Domain Prefix: ::/0, state: None
    [00:00:22.105,987] <inf> net_openthread: [I] Ip6Filter-----: Added unsecure port 1000
    [00:00:22.106,079] <inf> net_openthread: [I] JoinerRouter--: Joiner Router: start
    [00:00:22.106,292] <inf> net_l2_openthread: State changed! Flags: 0x00000200 Current role: router
    [00:00:22.106,323] <inf> coap_client_utils: Thread state changed: 200
    [00:00:22.135,650] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:00:22.135,681] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:00:22.135,772] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                61 dc 0a 34 12 79 49 2e  c4 24 eb 7c 72 b1 67 af |a..4.yI. .$.|r.g.
                                                82 05 7e d4 d2 7f 33 f0  4d 4c 4d 4c 0a 43 00 15 |..~...3. MLML.C..
                                                e9 16 00 00 00 00 00 00  01 df eb 48 49 33 1d d1 |........ ...HI3..
                                                1e 45 2e 5d f3 82 4e 7c  98 67 eb f8 f6 3b e6 53 |.E.]..N| .g...;.S
                                                43 b9 1f dc 91 7a 23 f1  b8 60 ef d2 2c 38 19 c1 |C....z#. .`..,8..
                                                02 cb cb 02 ba c3 96 e7  71 95 37 f7 68 c3 14 2b |........ q.7.h..+
                                                ce 76 22 af b0 a9 32 32  76 d3 f6 27 cc          |.v"...22 v..'.   
    [00:00:22.136,566] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:125, chksum:0a43, ecn:no, from:d2d47e0582af67b1, sec:no, prio:net, rss:-55.0
    [00:00:22.136,871] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:d0d4:7e05:82af:67b1]:19788
    [00:00:22.137,207] <inf> net_openthread: [I] MeshForwarder-:     dst:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:22.138,336] <inf> net_openthread: [I] Mle-----------: Receive Link Accept (fe80:0:0:0:d0d4:7e05:82af:67b1,0xf000)
    [00:00:22.138,702] <inf> net_openthread: [I] Mle-----------: Route table updated
    [00:00:22.138,916] <inf> net_openthread: [I] Mle-----------:     3000 -> ffff, cost:0 1, lqin:3, lqout:3, link:yes
    [00:00:22.139,129] <inf> net_openthread: [I] Mle-----------:     9c00 -> ffff, cost:0 16, lqin:0, lqout:0, link:device
    [00:00:22.139,343] <inf> net_openthread: [I] Mle-----------:     f000 -> ffff, cost:0 16, lqin:0, lqout:3, link:no
    [00:00:22.243,316] <inf> net_openthread: [I] Mle-----------: Send delayed message (ff02:0:0:0:0:0:0:1)
    [00:00:22.260,437] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:240, chksum:ab39, ecn:no, to:0xffff, sec:yes, prio:net
    [00:00:22.260,772] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:22.261,047] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:00:22.849,792] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:00:22.855,010] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:0a06, ecn:no, to:0xffff, sec:no, prio:net
    [00:00:22.855,316] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:22.855,621] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:00:24.348,297] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:00:24.353,210] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:c55b, ecn:no, to:0xffff, sec:no, prio:net
    [00:00:24.353,515] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:24.353,820] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    010] <inf> net_openthread: [I] Mle-----------: Send Adn:no, to:0x[0m
    enthread: [src:[fe80:0:88
    et
    .312,988] rwarder-:  979]:1978802.15.4 fra<dbg> net_l2_openthread018a48
                   0 4d 4c 4d 4... F(tg.s.)
             Pv6 UDP msg, len:92, chksum:8dc0, e> net_openthread: [I] M-:     dst:[ff02:0:0:0:0:0:0:1]:190m<inf> net_openthread:--------: Re80:0:0:0:406c:5106:c98:76,281] I] Mle-----------: Routated
    [00:00:37.876,495] <inf> net_openthread: [I] Mle-----------:     3000 -> ffff, cost:0 1, lqin:3, lqout:3, li:37.876,708[00:00:50.139,068] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:00:50.139,099] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:00:50.139,190] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                41 d8 0b 34 12 ff ff b1  67 af 82 05 7e d4 d2 7f |A..4.... g...~...
                                                3b 01 f0 4d 4c 4d 4c 93  b4 00 15 ea 16 00 00 00 |;..MLML. ........
                                                00 00 00 01 e4 99 46 4f  18 00 f9 22 4d bd 54 c1 |......FO ..."M.T.
                                                9d d5 cc b1 16 c4 9c ca  f8 93 50 97 06 40 20 df |........ ..P..@ .
                                                2a 1d bb a5 fb 27 23                             |*....'#          
    [00:00:50.139,984] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:92, chksum:93b4, ecn:no, from:d2d47e0582af67b1, sec:no, prio:net, rss:-54.0
    [00:00:50.140,319] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:d0d4:7e05:82af:67b1]:19788
    [00:00:50.140,594] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:00:50.141,601] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:d0d4:7e05:82af:67b1,0xf000)
    [00:00:50.141,845] <inf> net_openthread: [I] Mle-----------: Route table updated
    [00:00:50.142,059] <inf> net_openthread: [I] Mle-----------:     3000 -> f000, cost:1 1, lqin:3, lqout:3, link:yes
    [00:00:50.142,272] <inf> net_openthread: [I] Mle-----------:     9c00 -> ffff, cost:0 16, lqin:0, lqout:0, link:device
    [00:00:50.142,486] <inf> net_openthread: [I] Mle-----------:     f000 -> 3000, cost:1 1, lqin:3, lqout:3, link:yes
    [00:00:50.732,330] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:00:50.736,297] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:c79e, ecn:no, to:0xffff, sec:no, prio:net
    [00:00:50.736,602] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:00:50.736,907] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:01:17.628,295] <dbg> net_l2_openthread_recv: (rx_q[0]): Goump: Receiveead: net_pkt_hexdump: 0x20018a48
                                  3b 01 f0 4d 4c 4d 4c 4e  75 00 15 eb 16 00 00 00 |;..MLMLN u.......
                                                00 00 00 01 9d 71 85 ee  ca 22 1a 56 ec b 8f c8 79 c2.          82af67b1, sForwarder-: 
    [00:01:17.629,791] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:01:17.630,798] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:d0d4:7e05:82af:67b1,0xf000)
    [00:01:19.963,287] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:01:19.963,317] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:01:19.963,378] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                41 d8 57 34 12 ff ff bd  8e 98 0c 06 51 6c 42 7f |A.W4.... ....QlB.
                                                3b 01 f0 4d 4c 4d 4c 21  ea 00 15 5c 76 00 00 00 |;..MLML! ...\v...
                                                00 00 00 01 8e c7 4f 9a  f9 92 4d 1a 74 19 70 79 |......O. ..M.t.py
                                                81 28 09 07 76 bb 40 84  5f 6a 34 78 8e 50 33 e1 |.(..v.@. _j4x.P3.
                                                7c e8 a1 ac 6c 21 23                             ||...l!#          
    [00:01:19.964,172] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:92, chksum:21ea, ecn:no, from:426c51060c988ebd, sec:no, prio:net, rss:-60.0
    [00:01:19.964,508] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:406c:5106:c98:8ebd]:19788
    [00:01:19.964,813] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:01:19.965,789] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:406c:5106:c98:8ebd,0x3000)
    [00:01:22.513,885] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:01:22.520,080] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:0ee7, ecn:no, to:0xffff, sec:no, prio:net
    [00:01:22.520,385] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:01:22.520,690] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:01:44.245,483] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:01:44.245,513] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:01:44.245,605] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                41 d8 0d 34 12 ff ff b1  67 af 82 05 7e d4 d2 7f |A..4.... g...~...
                                                3b 01 f0 4d 4c 4d 4c d1  6f 00 15 ec 16 00 00 00 |;..MLML. o.......
                                                00 00 00 01 fc 09 d1 36  80 81 e8 6a 0d ef 0b de |.......6 ...j....
                                                17 da 3f 91 1f d1 3b d0  03 58 82 1e ba 52 92 97 |..?...;. .X...R..
                                                9e a0 e2 66 3c 27 e8                             |...f<'.          
    [00:01:44.246,398] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:92, chksum:d16f, ecn:no, from:d2d47e0582af67b1, sec:no, prio:net, rss:-54.0
    [00:01:44.246,704] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:d0d4:7e05:82af:67b1]:19788
    [00:01:44.247,009] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:01:44.248,016] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:d0d4:7e05:82af:67b1,0xf000)
    [00:01:49.533,935] <dbgsending to OT
    0m<dbg> net_l2_openthre            4c 4d 4c 3 00 |;..MLML5 ...^v...
                0 00 00 01 7 10 e6 5c 5 |....s... ..<...\]
                b8 86 f6 b0 dd 97 47  c5 2c ee 14 21 23                             |..,..!#      rwarder-: Received IPv6 UDP msg, len:92, chksum:359e, ecn:no, from:426c51060c988ebd, sec:no, prio:net, rss:-60.0[0[00:01: <inf> na6,407] <inf> net_opve Advertisement (fe80:0:0:0:406c:5[00:01:54.168,273] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:01:54.172,851] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:9462, ecn:no, to:0xffff, sec:no, prio:net
    [00:01:54.173,156] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:01:54.173,492] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    v: (rx_q[0])_l2_openthre a5 c9 1f 33 |L.)4.S.. .Q.....3
     .."..9
       v6 UDP msg, --------: R05:82af:67b[00:02:07.517,517] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:07.517,547] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:07.517,608] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                59 d8 5b 34 12 ff ff bd  8e 98 0c 06 51 6c 42 0d |Y.[4.... ....QlB.
                                                e4 06 00 00 01 2c d8 7e  2c 00 0f 02 cd c9 d4 e1 |.....,.~ ,.......
                                                51 4d 6d 21 7a 3d 56 20  aa 63 49 f8 89 c0 5f 1f |QMm!z=V  .cI..._.
                                                a5 7d c6 ce 8d e0 9f a0  b7 a0 79 5f e0 e9 57 9c |.}...... ..y_..W.
                                                57 a7 3b 7c fb bf a4 fd  af 47 9b c4 38 e9 f7 70 |W.;|.... .G..8..p
                                                ca 86 42 49 20 ab c1 2a  33 d3 2a 47 7d c0 91 90 |..BI ..* 3.*G}...
                                                63 ec 2c 1e 88 9a 38 7e  45 52 62 c7 15 27 ed 69 |c.,...8~ ERb..'.i
                                                c1 b9 23 61 76 0c d2 21  cd                      |..#av..! .       
    [00:02:07.524,291] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:07.524,291] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:07.524,383] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                59 d8 5c 34 12 ff ff bd  8e 98 0c 06 51 6c 42 0d |Y.\4.... ....QlB.
                                                e5 06 00 00 01 02 51 bf  a0 06 02 86 97 08 44 42 |......Q. ......DB
                                                17 b7 00 c5 2d 09 42 4f  a2 e6 cb f6 36 0f 4d 55 |....-.BO ....6.MU
                                                82 7d ba 7a eb ba 5b b0  ca 31 1a e9 89 c8 2e 62 |.}.z..[. .1.....b
                                                e9 62 56 4a e8 8a 75 65  14 90 cf 7d 97 f5 54 f6 |.bVJ..ue ...}..T.
                                                dc 19 05 9e 88 db 4f 41  1f 1d af 5f 0b 8e ce 46 |......OA ..._...F
                                                60 2a 83 a6 e1 33 e6 1e  ef ab fe ed 13 ac 23 52 |`*...3.. ......#R
                                                e2 f5 ef fc e3 13 21 d3                          |......!.         
    [00:02:07.530,120] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:07.530,151] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:07.530,212] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                49 d8 5d 34 12 ff ff bd  8e 98 0c 06 51 6c 42 0d |I.]4.... ....QlB.
                                                e6 06 00 00 01 50 0b 24  63 e2 26 32 a5 f4 ec cc |.....P.$ c.&2....
                                                37 6f 37 81 75 5b d4 2a  47 8c 09 a9 13 69 e2 75 |7o7.u[.* G....i.u
                                                3e 8d 37 e7 26 d0 9d e4  c0 fd 97 60 ec a7 52 c9 |>.7.&... ...`..R.
                                                3d df cd cb c7 20 a4                             |=.... .          
    [00:02:07.531,402] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:255, chksum:b40f, ecn:no, from:426c51060c988ebd, sec:yes, prio:net, rss:-60.25
    [00:02:07.531,738] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:406c:5106:c98:8ebd]:19788
    [00:02:07.532,043] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:02:07.533,752] <inf> net_openthread: [I] Mle-----------: Receive Data Response (fe80:0:0:0:406c:5106:c98:8ebd)
    [00:02:07.534,149] <inf> net_openthread: [I] Notifier------: StateChanged (0x00000200) [NetData]
    [00:02:07.534,698] <inf> net_openthread: [I] Mle-----------: Delay Data Response (ff02:0:0:0:0:0:0:1)
    [00:02:07.534,881] <inf> net_openthread: [I] BbrLeader-----: PBBR state: Unchanged
    [00:02:07.535,064] <inf> net_openthread: [I] BbrLeader-----: Rloc16: 0x3000, seqno: 21, delay: 1200, timeout 3600
    [00:02:07.535,278] <inf> net_openthread: [I] BbrLeader-----: Domain Prefix: ::/0, state: None
    [00:02:07.535,430] <inf> net_openthread: [I] Ip6Filter-----: Removed unsecure port 1000
    [00:02:07.535,644] <inf> net_l2_openthread: State changed! Flags: 0x00000200 Current role: router
    [00:02:07.535,675] <inf> coap_client_utils: Thread state changed: 200
    [00:02:07.926,269] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:07.926,300] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:07.926,391] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                59 d8 0f 34 12 ff ff b1  67 af 82 05 7e d4 d2 0d |Y..4.... g...~...
                                                c4 01 00 00 01 dd 0e ca  bd c7 51 de 0d 2e a3 34 |........ ..Q....4
                                                2f ed 87 32 a4 3a 88 b0  24 3a dd 0d d8 72 83 36 |/..2.:.. $:...r.6
                                                8a eb 83 76 33 20 d1 55  36 ff 4b b3 58 c3 4e c2 |...v3 .U 6.K.X.N.
                                                58 d8 7f c5 5c 76 31 d9  45 c4 bf 66 dd d6 73 19 |X...\v1. E..f..s.
                                                dd 5a 9f cc ca 79 86 c2  7f 8f fe 8c 1f b9 b5 96 |.Z...y.. ........
                                                dd b9 70 ee 7d 33 55 36  6d 74 07 c5 08 96 ae 9c |..p.}3U6 mt......
                                                df 6d a5 cf 02 45 28 26  98                      |.m...E(& .       
    [00:02:07.933,532] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:07.933,563] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:07.933,654] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                59 d8 10 34 12 ff ff b1  67 af 82 05 7e d4 d2 0d |Y..4.... g...~...
                                                c5 01 00 00 01 0b b5 a8  3b 2c a3 06 a8 77 fd cc |........ ;,...w..
                                                60 75 8a 5b 50 15 c0 af  08 cc 54 2e aa 92 b6 38 |`u.[P... ..T....8
                                                0e 2f 69 c2 e1 09 b0 09  e6 60 10 f9 e6 ba ed e7 |./i..... .`......
                                                be 9e 50 55 51 5c 0a bf  60 3c f4 c5 84 81 7c fb |..PUQ\.. `<....|.
                                                c7 d8 56 f3 49 c5 58 4d  fd d9 cc 9c e5 d1 3c ea |..V.I.XM ......<.
                                                f1 04 8a 8c a9 11 8b c2  1a d9 3a ff 55 a5 30 b4 |........ ..:.U.0.
                                                80 aa 4c 9e 6d d2 26 21                          |..L.m.&!         
    [00:02:07.937,622] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:07.937,622] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:07.937,713] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                49 d8 11 34 12 ff ff b1  67 af 82 05 7e d4 d2 0d |I..4.... g...~...
                                                c6 01 00 00 01 2e ae 41  ed 5f 28 04 dd 90 3a 53 |.......A ._(...:S
                                                b4 6a 15 f3 ae 4b 0f e0  9c f3 27 41 de aa 65 68 |.j...K.. ..'A..eh
                                                f2 4c 35 0b 5b f3 a9 62  9a cb d3 da 92 7c 57 11 |.L5.[..b .....|W.
                                                04 32 24 93 7e 26 31                             |.2$.~&1          
    [00:02:07.938,934] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:255, chksum:de99, ecn:no, from:d2d47e0582af67b1, sec:yes, prio:net, rss:-54.0
    [00:02:07.939,239] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:d0d4:7e05:82af:67b1]:19788
    [00:02:07.939,544] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:02:07.941,284] <inf> net_openthread: [I] Mle-----------: Receive Data Response (fe80:0:0:0:d0d4:7e05:82af:67b1)
    [00:02:08.008,148] <inf> net_openthread: [I] Mle-----------: Send delayed message (ff02:0:0:0:0:0:0:1)
    [00:02:08.025,146] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:255, chksum:c20d, ecn:no, to:0xffff, sec:yes, prio:net
    [00:02:08.025,451] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:02:08.025,756] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:02:14.267,517] <inf> net_openthread: [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    [00:02:14.273,376] <inf> net_openthread: [I] MeshForwarder-: Sent IPv6 UDP msg, len:92, chksum:dba4, ecn:no, to:0xffff, sec:no, prio:net
    [00:02:14.273,681] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:707c:eb24:c42e:4979]:19788
    [00:02:14.273,986] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:02:17.880,340] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got 802.15.4 packet, sending to OT
    [00:02:17.880,371] <dbg> net_l2_openthread: net_pkt_hexdump: Received 802.15.4 frame
    [00:02:17.880,462] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                41 d8 12 34 12 ff ff b1  67 af 82 05 7e d4 d2 7f |A..4.... g...~...
                                                3b 01 f0 4d 4c 4d 4c cc  58 00 15 ef 16 00 00 00 |;..MLML. X.......
                                                00 00 00 01 6b ee 11 9f  a9 69 7c 63 0a 8e 9f 1c |....k... .i|c....
                                                d4 0b dd a5 92 27 b2 f6  7a c9 29 13 f5 3b fd f0 |.....'.. z.)..;..
                                                20 b0 38 e2 75 26 0a                             | .8.u&.          
    [00:02:17.881,225] <inf> net_openthread: [I] MeshForwarder-: Received IPv6 UDP msg, len:92, chksum:cc58, ecn:no, from:d2d47e0582af67b1, sec:no, prio:net, rss:-55.0
    [00:02:17.881,530] <inf> net_openthread: [I] MeshForwarder-:     src:[fe80:0:0:0:d0d4:7e05:82af:67b1]:19788
    [00:02:17.881,835] <inf> net_openthread: [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    [00:02:17.882,843] <inf> net_openthread: [I] Mle-----------: Receive Advertisement (fe80:0:0:0:d0d4:7e05:82af:67b1,0xf000)
    [00:02:20.362,243] <dbg> net_l2_openthread_recf 34 12 ff lB.
                                    3b 01 f0 4d 4c 4d 401 6a bd af 26  cb 79 d4 8c cc 74 3d 91 |....j..& .y...t=.
                                                d5 dd ee 99 4c d6 03 enthread: [I:0:1]:197885106:c98:8eb0m
    [00:02:20.787,841] <dbg> coap_utessage: Send UDP Message!
    [00:02:20.788,360] <dbg> net_l2_openthread 00 64 ff 9b                    001 8c 82 4a 3e a0 e2  fa 0e 1f b8 b5X...J>.. .....hel
                                           ,574] <lient_utils: Send test message. ret:18
    788,635] <dbg> net_: openthrea (openthread): Sending 0 00 00 1a 11 40  00 00                         00 00 00 
             9a |.....f.. ...3..8.
                                     58           2_openthread_recv: (rx_q[0]): Got dbg> net_l2_ net_pkt_hexket
    [00:02:20.l2_openthread: net_pkt_20018a48
                 0 00 00 00 | 00 86 66 da[00:02:33.703,399] <dbg> coap_utils: coap_set_response_callback: Reply callback set!
    [00:02:33.703,430] <dbg> coap_utils: coap_send_message: Send UDP Message!
    [00:02:33.703,826] <dbg> net_l2_openthread: net_pkt_hexdump: IPv6 packet to send
    [00:02:33.703,918] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20019060
                                                60 00 00 00 00 1a 11 40  00 00 00 00 00 00 00 00 |`......@ ........
                                                00 00 00 00 00 00 00 00  00 64 ff 9b 00 00 00 00 |........ .d......
                                                00 00 00 00 86 66 da 12  df c3 16 33 00 1a e9 31 |.....f.. ...3...1
                                                58 01 8c 83 4c 5c 7d 20  be 08 cc c9 b5 68 65 6c |X...L\}  .....hel
                                                6c 6f                                            |lo               
    [00:02:33.704,010] <inf> coap_client_utils: Send test message. ret:18
    [00:02:33.704,071] <dbg> net_otPlat_radio: openthread_handle_frame_to_send: (openthread): Sending Ip6 packet to ot stack
    [00:02:33.704,284] <dbg> net_l2_openthread: ot_receive_handler: (openthread): Injecting Ip6 packet to Zephyr net stack
    [00:02:33.704,284] <dbg> net_l2_openthread: net_pkt_hexdump: Received IPv6 packet
    [00:02:33.704,376] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                60 00 00 00 00 1a 11 40  00 00 00 00 00 00 00 00 |`......@ ........
                                                00 00 00 00 00 00 00 00  00 64 ff 9b 00 00 00 00 |........ .d......
                                                00 00 00 00 86 66 da 12  df c3 16 33 00 1a e9 31 |.....f.. ...3...1
                                                58 01 8c 83 4c 5c 7d 20  be 08 cc c9 b5 68 65 6c |X...L\}  .....hel
                                                6c 6f                                            |lo               
    [00:02:33.704,498] <dbg> net_l2_openthread: openthread_recv: (rx_q[0]): Got injected Ip6 packet, sending to upper layers
    [00:02:33.704,498] <dbg> net_l2_openthread: net_pkt_hexdump: Injected IPv6 packet
    [00:02:33.704,620] <dbg> net_l2_openthread: net_pkt_hexdump: 0x20018a48
                                                60 00 00 00 00 1a 11 40  00 00 00 00 00 00 00 00 |`......@ ........
                                                00 00 00 00 00 00 00 00  00 64 ff 9b 00 00 00 00 |........ .d......
                                                00 00 00 00 86 66 da 12  df c3 16 33 00 1a e9 31 |.....f.. ...3...1
                                                58 01 8c 83 4c 5c 7d 20  be 08 cc c9 b5 68 65 6c |X...L\}  .....hel
                                                6c 6f                                            |lo               
    

    #include <zephyr/kernel.h>
    #include <dk_buttons_and_leds.h>
    #include <zephyr/logging/log.h>
    #include <ram_pwrdn.h>
    #include <zephyr/device.h>
    #include <zephyr/pm/device.h>
    
    #include "coap_client_utils.h"
    
    LOG_MODULE_REGISTER(coap_client, CONFIG_COAP_CLIENT_LOG_LEVEL);
    
    #define OT_CONNECTION_LED DK_LED1
    #define BLE_CONNECTION_LED DK_LED2
    
    
    static void on_ot_connect(struct k_work *item)
    {
    	ARG_UNUSED(item);
    	
    	LOG_INF("CONNECTED!");
    
    	dk_set_led_on(OT_CONNECTION_LED);
    }
    
    static void on_ot_disconnect(struct k_work *item)
    {
    	ARG_UNUSED(item);
    	
    	LOG_INF("DISCONNECTED!");
    
    	dk_set_led_off(OT_CONNECTION_LED);
    }
    
    static void on_button_changed(uint32_t button_state, uint32_t has_changed)
    {
    	uint32_t buttons = button_state & has_changed;
    
    	if (buttons & DK_BTN1_MSK) {
    		coap_client_join_network();
    	}
    
    	if (buttons & DK_BTN2_MSK) {
    		/* send test CoAp message */
    		coap_client_send_test_msg();
    	}
    }
    
    void main(void)
    {
    	int ret;
    
    	LOG_DBG("Start CoAP-client sample");
    
    	if (IS_ENABLED(CONFIG_RAM_POWER_DOWN_LIBRARY)) {
    		power_down_unused_ram();
    	}
    
    	ret = dk_buttons_init(on_button_changed);
    	if (ret) {
    		LOG_ERR("Cannot init buttons (error: %d)", ret);
    		return;
    	}
    
    	ret = dk_leds_init();
    	if (ret) {
    		LOG_ERR("Cannot init leds, (error: %d)", ret);
    		return;
    	}
    	
    	LOG_DBG("INIT");
    
    	coap_client_utils_init(on_ot_connect, on_ot_disconnect);
    }
    
    #include <zephyr/kernel.h>
    #include <net/coap_utils.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/net/openthread.h>
    #include <zephyr/net/socket.h>
    #include <openthread/thread.h>
    
    #include "coap_client_utils.h"
    
    LOG_MODULE_REGISTER(coap_client_utils, CONFIG_COAP_CLIENT_UTILS_LOG_LEVEL);
    
    #define COAP_PORT 5683
    
    #define TEST_URI_PATH 						      "hello"
    //also tried "coap://coap.me:5683/hello"
    
    static bool is_connected;
    
    static struct k_work test_msg_work;
    static struct k_work on_connect_work;
    static struct k_work on_disconnect_work;
    
    
    /* Options supported by the server */
    static const char *const test_option[] = { TEST_URI_PATH, NULL };
    
    /* Destination address */
    static struct sockaddr_in6 dest_addr = {
    	.sin6_family = AF_INET6,
    	.sin6_port = htons(COAP_PORT),
    	.sin6_addr.s6_addr = { 0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, 0x00, 0x00,
    			       0x00, 0x00, 0x00, 0x00, 0x86, 0x66, 0xda, 0x12 },
    	.sin6_scope_id = 0U
    };
    
    
    static void printIPv6Address(const otIp6Address addr)
    {
      LOG_INF("Mesh Local EID Address: %x%x.%x%x.%x%x.%x%x.%x%x.%x%x.%x%x.%x%x",
            addr.mFields.m8[0],
            addr.mFields.m8[1],
            addr.mFields.m8[2],
            addr.mFields.m8[3],
            addr.mFields.m8[4],
            addr.mFields.m8[5],
            addr.mFields.m8[6],
            addr.mFields.m8[7],
            addr.mFields.m8[8],
            addr.mFields.m8[9],
            addr.mFields.m8[10],
            addr.mFields.m8[11],
            addr.mFields.m8[12],
            addr.mFields.m8[13],
            addr.mFields.m8[14],
            addr.mFields.m8[15]);
    }
    
    static void printUnicastAddresses(struct openthread_context *ot)
    {
      const otNetifAddress *n;
    
      n = otIp6GetUnicastAddresses(ot->instance);
      while (n != NULL)
      {
        printIPv6Address((const otIp6Address)n->mAddress);
        n = n->mNext;
      };
    }
    
    static int msg_reply(const struct coap_packet *response, struct coap_reply *reply, const struct sockaddr *from)
    {
    	ARG_UNUSED(reply);
    	ARG_UNUSED(from);
    	LOG_INF("GOT %d bytes -> %s", response->max_len, response->data);
    	
    	return 1;
    }
    
    static void send_test_msg(struct k_work *item)
    {
    	int ret = 0;
    
    	ARG_UNUSED(item);
    
      ret = coap_send_request(COAP_METHOD_GET,
          (const struct sockaddr *)&dest_addr,
          test_option, NULL, 0, msg_reply);
      LOG_INF("Send test message. ret:%d", ret);
    }
    
    static void on_thread_state_changed(uint32_t flags, void *context)
    {
    	struct openthread_context *ot_context = context;
    	
    	LOG_INF("Thread state changed: %x", flags);
    
    	if (flags & OT_CHANGED_THREAD_ROLE) {
    		switch (otThreadGetDeviceRole(ot_context->instance)) {
    		case OT_DEVICE_ROLE_CHILD:
    		case OT_DEVICE_ROLE_ROUTER:
    		case OT_DEVICE_ROLE_LEADER:
    		{
    			k_work_submit(&on_connect_work);
    			is_connected = true;
    			printUnicastAddresses(ot_context);
    			break;
    		}
    
    		case OT_DEVICE_ROLE_DISABLED:
    		case OT_DEVICE_ROLE_DETACHED:
    		default:
    			k_work_submit(&on_disconnect_work);
    			is_connected = false;
    			break;
    		}
    	} 
    	else if (flags & OT_CHANGED_JOINER_STATE) {
    		LOG_INF("Joiner state changed");
    	}
    }
    
    static void submit_work_if_connected(struct k_work *work)
    {
    	if (is_connected) {
    		k_work_submit(work);
    	} else {
    		LOG_INF("Connection is broken");
    	}
    }
    
    void coap_client_utils_init(ot_connection_cb_t on_connect,
    			    ot_disconnection_cb_t on_disconnect)
    {
    	LOG_INF("INIT ALL!!!");
    	
    	coap_init(AF_INET6, NULL);
    
    	k_work_init(&on_connect_work, on_connect);
    	k_work_init(&on_disconnect_work, on_disconnect);
    	k_work_init(&test_msg_work, send_test_msg);
    
    	openthread_set_state_changed_cb(on_thread_state_changed);
    }
    
    void coap_client_join_network(void)
    {
    	openthread_start(openthread_get_default_context());
    }
    
    void coap_client_send_test_msg(void)
    {
    	submit_work_if_connected(&test_msg_work);
    }
    
    /*
     * Copyright (c) 2020 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    #include <zephyr/kernel.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/net/coap.h>
    #include <net/coap_utils.h>
    #include <zephyr/net/socket.h>
    
    LOG_MODULE_REGISTER(coap_utils, CONFIG_COAP_UTILS_LOG_LEVEL);
    
    #define MAX_COAP_MSG_LEN 256
    #define COAP_VER 1
    #define COAP_TOKEN_LEN 8
    #define COAP_MAX_REPLIES 1
    #define COAP_POOL_SLEEP 500
    #define COAP_OPEN_SOCKET_SLEEP 200
    #if defined(CONFIG_NRF_MODEM_LIB)
    #define COAP_RECEIVE_STACK_SIZE 1096
    #else
    #define COAP_RECEIVE_STACK_SIZE 996
    #endif
    
    const static int nfds = 1;
    static struct pollfd fds;
    static struct coap_reply replies[COAP_MAX_REPLIES];
    static int proto_family;
    static struct sockaddr *bind_addr;
    
    static K_THREAD_STACK_DEFINE(receive_stack_area, 2048);
    static struct k_thread receive_thread_data;
    
    static int coap_open_socket(void)
    {
    	int sock;
    	
    	LOG_DBG("Open socket...");
    
    	while (1) {
    		sock = socket(proto_family, SOCK_DGRAM, IPPROTO_UDP);
    		if (sock < 0) {
    			LOG_ERR("Failed to create socket %d", errno);
    			k_sleep(K_MSEC(COAP_OPEN_SOCKET_SLEEP));
    			continue;
    		}
    		else
    		{
    			LOG_DBG("Socket opened successfully!");
    		}
    		break;
    	}
    
    	if (bind_addr) {
    		if (bind(sock, bind_addr, sizeof(*bind_addr))) {
    			LOG_ERR("Failed to bind socket, errno: %d", errno);
    		}
    	}
    	
    	LOG_DBG("Open socket DONE!");
    
    	return sock;
    }
    
    static void coap_close_socket(int socket)
    {
    	(void)close(socket);
    }
    
    static void coap_receive(void)
    {
    	static uint8_t buf[MAX_COAP_MSG_LEN + 1];
    	struct coap_packet response;
    	struct coap_reply *reply = NULL;
    	static struct sockaddr from_addr;
    	socklen_t from_addr_len;
    	int len;
    	int ret;
    
    	while (1) {
    		fds.revents = 0;
    
    		if (poll(&fds, nfds, -1) < 0) {
    			LOG_ERR("Error in poll:%d", errno);
    			errno = 0;
    			k_sleep(K_MSEC(COAP_POOL_SLEEP));
    			continue;
    		}
    
    		if (fds.revents & POLLERR) {
    			LOG_ERR("Error in poll.. waiting a moment.");
    			k_sleep(K_MSEC(COAP_POOL_SLEEP));
    			continue;
    		}
    
    		if (fds.revents & POLLHUP) {
    			LOG_ERR("Error in poll: POLLHUP");
    			continue;
    		}
    
    		if (fds.revents & POLLNVAL) {
    			LOG_ERR("Error in poll: POLLNVAL - fd not open");
    
    			coap_close_socket(fds.fd);
    			fds.fd = coap_open_socket();
    
    			LOG_INF("Socket has been re-open");
    
    			continue;
    		}
    
    		if (!(fds.revents & POLLIN)) {
    			LOG_ERR("Unknown poll error");
    			continue;
    		}
    
    		from_addr_len = sizeof(from_addr);
    		len = recvfrom(fds.fd, buf, sizeof(buf) - 1, 0, &from_addr,
    			       &from_addr_len);
    
    		if (len < 0) {
    			LOG_ERR("Error reading response: %d", errno);
    			errno = 0;
    			continue;
    		}
    
    		if (len == 0) {
    			LOG_ERR("Zero length recv");
    			continue;
    		}
    
    		ret = coap_packet_parse(&response, buf, len, NULL, 0);
    		if (ret < 0) {
    			LOG_ERR("Invalid data received");
    			continue;
    		}
    
    		reply = coap_response_received(&response, &from_addr, replies,
    					       COAP_MAX_REPLIES);
    		if (reply) {
    			coap_reply_clear(reply);
    		}
    	}
    }
    
    static int coap_init_request(enum coap_method method,
    			     enum coap_msgtype msg_type,
    			     const char *const *uri_path_options, uint8_t *payload,
    			     uint16_t payload_size, struct coap_packet *request,
    			     uint8_t *buf)
    {
    	const char *const *opt;
    	int ret;
    
    	ret = coap_packet_init(request, buf, MAX_COAP_MSG_LEN, COAP_VER,
    			       msg_type, COAP_TOKEN_LEN, coap_next_token(),
    			       method, coap_next_id());
    	if (ret < 0) {
    		LOG_ERR("Failed to init CoAP message");
    		goto end;
    	}
    
    	for (opt = uri_path_options; opt && *opt; opt++) {
    		ret = coap_packet_append_option(request, COAP_OPTION_URI_PATH,
    						*(const uint8_t *const *)opt, strlen(*opt));
    		if (ret < 0) {
    			LOG_ERR("Unable add option to request");
    			goto end;
    		}
    	}
    
    	if (payload) {
    		ret = coap_packet_append_payload_marker(request);
    		if (ret < 0) {
    			LOG_ERR("Unable to append payload marker");
    			goto end;
    		}
    
    		ret = coap_packet_append_payload(request, payload,
    						 payload_size);
    		if (ret < 0) {
    			LOG_ERR("Not able to append payload");
    			goto end;
    		}
    	}
    
    end:
    	return ret;
    }
    
    static int coap_send_message(const struct sockaddr *addr,
    			     struct coap_packet *request)
    {
    	LOG_DBG("Send UDP Message!");
    
    	return sendto(fds.fd, request->data, request->offset, 0, addr,
    		      sizeof(*addr));
    }
    
    static void coap_set_response_callback(struct coap_packet *request,
    				       coap_reply_t reply_cb)
    {
    	struct coap_reply *reply;
    
    	reply = &replies[0];
    	
    	LOG_DBG("Reply callback set!");
    
    	coap_reply_clear(reply);
    	coap_reply_init(reply, request);
    	reply->reply = reply_cb;
    }
    
    void coap_init(int ip_family, struct sockaddr *addr)
    {
    	proto_family = ip_family;
    	
    	LOG_DBG("INIT CoAP.......");
    	
    	if (addr) {
    		bind_addr = addr;
    	}
    
    	fds.events = POLLIN;
    	fds.revents = 0;
    	fds.fd = coap_open_socket();
    
    	/* start sock receive thread */
    	k_thread_create(&receive_thread_data, receive_stack_area,
    			K_THREAD_STACK_SIZEOF(receive_stack_area),
    			(k_thread_entry_t)coap_receive, NULL, NULL, NULL,
    			/* Lowest priority cooperative thread */
    			K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1), 0,
    			K_NO_WAIT);
    	k_thread_name_set(&receive_thread_data, "CoAP-sock-recv");
    	LOG_DBG("CoAP socket receive thread started");
    }
    
    int coap_send_request(enum coap_method method, const struct sockaddr *addr,
    		      const char *const *uri_path_options, uint8_t *payload,
    		      uint16_t payload_size, coap_reply_t reply_cb)
    {
    	int ret;
    	struct coap_packet request;
    	uint8_t buf[MAX_COAP_MSG_LEN];
    
    	ret = coap_init_request(method, COAP_TYPE_NON_CON, uri_path_options,
    				payload, payload_size, &request, buf);
    	if (ret < 0) {
    		goto end;
    	}
    
    	if (reply_cb != NULL) {
    		coap_set_response_callback(&request, reply_cb);
    	}
    
    	ret = coap_send_message(addr, &request);
    	if (ret < 0) {
    		LOG_ERR("Transmission failed: %d", errno);
    		goto end;
    	}
    
    end:
    	return ret;
    }
    

  • FYI the IPV6 destination address is the well-known prefix 64:ff9b:: (as mentioned above) added to 0x86, 0x66, 0xda, 0x12 which is IPV4 134.102.218.18 (coap.me). 

  • Hi Marco,

    Sorry for the late reply. I can repeat your issue, need a bit more time to debug the issue plus traveling.

    I will try to give you a reply next week. Is this OK for you?

    Best regards,

    Charlie

Reply Children
  • Ah OK, no problem, I just wanted to know if it was my problem only or not. Let me know if I can help you on this by trying something...

    Thank you very much for your help!

    Marco

  • Hi  I just want to let you know that I have the same problem with the OT APIs directly. I can't even ping a remote server. 

    I have attached my new source code.

    Cheers.

    /*
     * Copyright (c) 2022 Marco Russi
     *
     */
    
    #include <zephyr/kernel.h>
    #include <net/coap_utils.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/net/openthread.h>
    #include <zephyr/net/socket.h>
    #include <openthread/coap.h>
    #include <openthread/ip6.h>
    #include <openthread/message.h>
    #include <openthread/ping_sender.h>
    #include <openthread/thread.h>
    #include "coap_client_utils.h"
    
    
    LOG_MODULE_REGISTER(coap_client_utils, CONFIG_COAP_CLIENT_UTILS_LOG_LEVEL);
    
    
    #define COAP_PORT 5683
    #define PEER_SERVER_IPV4_ADDRESS			  "64.227.117.8"
    //#define PERR_SERVER_IPV6_ADDRESS        "fe80:0:0:0:c8f1:d752:f4fc:2865"
    #define PEER_SERVER_IPV6_ADDRESS        "64:ff9b:0:0:0:0:40e3:7508"
    #define TEST_URI_PATH 						      "ping"
    
    
    static bool is_connected;
    static struct k_work test_ping;
    static struct k_work test_msg_work;
    static struct k_work on_connect_work;
    static struct k_work on_disconnect_work;
    static struct openthread_context *ot_context;
    static struct otNetifAddress *netif;
    static uint8_t buf[32];
    
    
    static void send_test_msg(struct k_work *item);
    static void ping_dest(struct k_work *item);
    static void on_thread_state_changed(uint32_t flags, void *context);
    static void submit_work_if_connected(struct k_work *work);
    static void coap_default_handler(void *context, otMessage *message,
                                     const otMessageInfo *message_info);
    static void print_unicast_addresses(struct openthread_context *ot);
    static void print_ipv6_address(const otIp6Address addr);
    static bool init_coap(struct otInstance *ot);
    static void response_handler(void *aContext,
                                 otMessage *aMessage,
                                 const otMessageInfo *aMessageInfo,
                                 otError aResult);
    static bool send_test_message(struct otInstance *ot);
    static void reply_callback (const otPingSenderReply *aReply, void *aContext);
    static bool ping_send( struct otInstance *ot );
    
    
    static void send_test_msg(struct k_work *item)
    {
      bool ret;
    
      ret = send_test_message(ot_context->instance);
    
      LOG_INF("Send test message -> %s", (true == ret ? "Success" : "FAIL"));
    }
    
    
    static void ping_dest(struct k_work *item)
    {
      bool ret;
    
      ret = ping_send(ot_context->instance);
    
      LOG_INF("PING test -> %s", (true == ret ? "Success" : "FAIL"));
    }
    
    
    static void on_thread_state_changed(uint32_t flags, void *context)
    {
      bool ret;
    	struct openthread_context *ot = context;
    	
    	LOG_INF("Thread state changed: %x", flags);
    
    	if (flags & OT_CHANGED_THREAD_ROLE) {
    		switch (otThreadGetDeviceRole(ot->instance)) {
    		case OT_DEVICE_ROLE_CHILD:
    		case OT_DEVICE_ROLE_ROUTER:
    		case OT_DEVICE_ROLE_LEADER:
    		{
    			k_work_submit(&on_connect_work);
    			is_connected = true;
    			print_unicast_addresses(ot);
    			
    			if (OT_DEVICE_ROLE_ROUTER == otThreadGetDeviceRole(ot->instance))
          {
            ret = init_coap(ot->instance);
    
            LOG_INF("INIT COAP -> %s", (true == ret ? "Success" : "FAIL"));
          }
    			break;
    		}
    
    		case OT_DEVICE_ROLE_DISABLED:
    		case OT_DEVICE_ROLE_DETACHED:
    		default:
    			k_work_submit(&on_disconnect_work);
    			is_connected = false;
    			break;
    		}
    	} 
    	else if (flags & OT_CHANGED_JOINER_STATE) {
    		LOG_INF("Joiner state changed");
    	}
    }
    
    
    static void submit_work_if_connected(struct k_work *work)
    {
    	if (is_connected) {
    		k_work_submit(work);
    	} else {
    		LOG_INF("Connection is broken");
    	}
    }
    
    
    static void coap_default_handler(void *context, otMessage *message,
                                     const otMessageInfo *message_info)
    {
      ARG_UNUSED(context);
      ARG_UNUSED(message);
      ARG_UNUSED(message_info);
    
      LOG_INF("Received CoAP message that does not match any request "
        "or resource");
    }
    
    
    static void print_unicast_addresses(struct openthread_context *ot)
    {
    	netif = otIp6GetUnicastAddresses(ot->instance);
    	while (netif != NULL)
    	{
    		print_ipv6_address((const otIp6Address)netif->mAddress);
    		netif = netif->mNext;
    	};
    }
    
    
    static void print_ipv6_address(const otIp6Address addr)
    {
    	LOG_INF("Mesh Local EID Address: %02x%02x.%02x%02x.%02x%02x.%02x%02x.%02x%02x.%02x%02x.%02x%02x.%02x%02x",
    				addr.mFields.m8[0],
    				addr.mFields.m8[1],
    				addr.mFields.m8[2],
    				addr.mFields.m8[3],
    				addr.mFields.m8[4],
    				addr.mFields.m8[5],
    				addr.mFields.m8[6],
    				addr.mFields.m8[7],
    				addr.mFields.m8[8],
    				addr.mFields.m8[9],
    				addr.mFields.m8[10],
    				addr.mFields.m8[11],
    				addr.mFields.m8[12],
    				addr.mFields.m8[13],
    				addr.mFields.m8[14],
    				addr.mFields.m8[15]);
    }
    
    
    static bool init_coap( struct otInstance *ot )
    {
      otError error;
    
      if (!ot) {
        LOG_ERR("There is no valid OpenThread instance");
        error = OT_ERROR_FAILED;
        goto end;
      }
    
      otCoapSetDefaultHandler(ot, coap_default_handler, NULL);
    
      error = otCoapStart(ot, COAP_PORT);
      if (error != OT_ERROR_NONE) {
        LOG_ERR("Failed to start OT CoAP. Error: %d", error);
        goto end;
      }
    
    end:
      return error == OT_ERROR_NONE ? 1 : 0;
    }
    
    
    static void response_handler(void *aContext,
                                 otMessage *aMessage,
                                 const otMessageInfo *aMessageInfo,
                                 otError aResult)
    {
      uint16_t len, offset;
    
      (void)aContext;
      (void)aMessageInfo;
    
      LOG_INF("I GOT SOMETHING!!!!!");
    
      if (OT_ERROR_ABORT == aResult)
      {
        LOG_INF("ERROR: ABORT");
      }
      else if (OT_ERROR_RESPONSE_TIMEOUT == aResult)
      {
        LOG_INF("ERROR TIMEOUT");
      }
      else
      {
        LOG_INF("ALL GOOD");
      }
    
      len = otMessageGetLength(aMessage);
      LOG_INF("MESSAGE LENGTH: %d", len);
    
      offset = otMessageGetOffset(aMessage);
      LOG_INF("MESSAGE OFFSET: %d", offset);
    
      len = otMessageRead(aMessage, offset, (void *)buf, len);
      LOG_INF("MESSAGE: %s", buf);
    }
    
    
    static bool send_test_message( struct otInstance *ot )
    {
      otError error = OT_ERROR_NO_BUFS;
      otMessage *msg = NULL;
      otMessageInfo msg_info;
    
      memset(&msg_info, 0, sizeof(msg_info));
    
      msg = otCoapNewMessage(ot, NULL);
      if (msg == NULL) {
        goto end;
      }
    
      otCoapMessageInit(msg, OT_COAP_TYPE_CONFIRMABLE, OT_COAP_CODE_GET);
    
      otCoapMessageGenerateToken(msg, OT_COAP_DEFAULT_TOKEN_LENGTH);
    
      error = otCoapMessageAppendUriPathOptions(msg, TEST_URI_PATH);
      if (error != OT_ERROR_NONE) {
        goto end;
      }
    
      //otThreadGetMeshLocalEid(ot);
    
      //bool TRUE to allow IPv6 Hop Limit 0 in mHopLimit, FALSE otherwise.
      //msg_info.mAllowZeroHopLimit = false;
      //uint8_t The ECN status of the packet, represented as in the IPv6 header.
      //mEcn
      //uint8_t The IPv6 Hop Limit value.
      //mHopLimit
      //bool TRUE if packets sent/received via host interface, FALSE otherwise.
      //mIsHostInterface
      //const void *A pointer to link-specific information.
      //mLinkInfo
      //bool  TRUE to allow looping back multicast, FALSE otherwise.
      //mMulticastLoop
      //otIp6Address The peer IPv6 address.
      //msg_info.mPeerAddr = peer_addr;
      otIp6AddressFromString(PEER_SERVER_IPV6_ADDRESS, &msg_info.mPeerAddr);
      //uint16_t The peer transport-layer port.
      msg_info.mPeerPort = COAP_PORT;
      //otIp6Address The local IPv6 address.
      //mSockAddr
      //uint16_t The local transport-layer port.
      //mSockPort = COAP_PORT;
      LOG_INF("GOING TO COAP ADDRESS:");
      print_ipv6_address(msg_info.mPeerAddr);
    
      error = otCoapSendRequest(ot, msg, &msg_info, response_handler, NULL);
    
    end:
      if (error != OT_ERROR_NONE && msg != NULL) {
        otMessageFree(msg);
      }
    
      return error == OT_ERROR_NONE ? 1 : 0;
    }
    
    
    static void reply_callback (const otPingSenderReply *aReply, void *aContext)
    {
      (void)aContext;
    
      LOG_INF("GOT A PING REPLY!!!!!!");
    
      print_ipv6_address(aReply->mSenderAddress);
    }
    
    
    static bool ping_send( struct otInstance *ot )
    {
      otError error = OT_ERROR_NONE;
      otPingSenderConfig config;
    
      memset(&config, 0, sizeof(config));
    
      otIp6AddressFromString(PEER_SERVER_IPV6_ADDRESS, &config.mDestination);
      LOG_INF("GOING TO PING ADDRESS:");
      print_ipv6_address(config.mDestination);
    
      config.mCallbackContext = NULL;
      config.mReplyCallback = reply_callback;
    
      error = otPingSenderPing(ot, &config);
    
      return (error == OT_ERROR_NONE ? 1 : 0);
    }
    
    
    void coap_client_utils_init(ot_connection_cb_t on_connect,
              ot_disconnection_cb_t on_disconnect)
    {
      ot_context = openthread_get_default_context();
    
      k_work_init(&on_connect_work, on_connect);
      k_work_init(&on_disconnect_work, on_disconnect);
      k_work_init(&test_msg_work, send_test_msg);
      k_work_init(&test_ping, ping_dest);
    
      openthread_set_state_changed_cb(on_thread_state_changed);
    }
    
    
    void coap_client_join_network(void)
    {
      openthread_start(ot_context);
    }
    
    
    void coap_client_send_test_msg(void)
    {
      submit_work_if_connected(&test_msg_work);
    }
    
    
    void coap_client_ping_dest(void)
    {
      submit_work_if_connected(&test_ping);
    }
    
    
    

Related