openthread Coap Client and Coap Server Example

Hi,

I am having some issues with the CoAP Client and Server on nrf Connect SDK v2.1.2.

I have flashed two nrf52840 dev kits with the examples, one with the CoAP Client and the other with the CoAP Server. If I understand the example documentation correctly, the boards should find each other automatically around 15 seconds after both boards have booted. In my case, this does not happen. After the boards have booted, I get the following output from the serial outputs.

As you can see, both dev kits are booting up as leaders with different router IDs. When I run "ot state" both return with "leader." LED 1 is solid green on both dev kits. When I press button 2 on the client, nothing happens on the server. I have retried this multiple times and I always get the same issue. 

However, if I run the CoAP CLI example first and go through the Thread network initiation commands (ot channel, PANID, etc.), and then flash the CoAP client/server examples, it will work okay. This includes control of the light on the CoAP server by pressing button 2 on the CoAP client. If I erase the flash before flashing the CoAP client/server example, the example won't run correctly.

Both boards have the same OpenThread network key defined in prj.conf

Is there anything I am running these examples?

Thanks,

  • That looks strange. I tried the unmodified samples just now, using NCS v2.1.2, and this was my result:

    using the "ot state" command also verifies that they have the roles that they claim during the startup. I started by erasing the flash (nrfjprog -e) before programming the samples, so no network data was stored before programming these boards.

    However, if I run the CoAP CLI example first and go through the Thread network initiation commands (ot channel, PANID, etc.), and then flash the CoAP client/server examples, it will work okay.

    That is probably because the network data is not deleted when you reprogram the board (because it uses a different region of the flash). But you should not need to run the CLI sample first to store the network data. 

    Can you try to erase the flash, program the client/server samples, and run these commands on both boards:

    ot state
    ot panid
    ot extpanid
    ot networkkey
    ot channel
    ot psck

    Do they report the same values on all of them?

    Best regards,

    Edvin

  • Thanks for your quick reply. After seeing it ran ok on your machine I decided to uninstall and reinstall the nrf connect sdk and it works ok on the development kits.

    However, I'm still having issues when trying to run the client on my custom board and the server on a development kit. 

    My custom board pcb contains an raytac mdbt50Q module and some other hardware, I have tested it with another application firmware that uses Bluetooth and it works correctly.

    I am using the "overlay-logging.conf" to run the application as a "sleepy end device". Again this works ok on the development kits but not on the custom board/

    I've attached a .txt file of the server logs with additional logging enabled

    =~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2022.12.09 13:05:20 =~=~=~=~=~=~=~=~=~=~=~=
    [00:00:01.860,076] <inf> [N] Mle-----------: RLOC16 0400 -> fffe
    uart:~$ [00:00:01.860,595] <inf> [I] Mle-----------: AttachState Idle -> Start
    uart:~$ [00:00:01.860,870] <inf> [I] Notifier------: StateChanged (0x10000040) [Rloc- ActDset]
    uart:~$ [00:00:02.050,903] <inf> [N] Mle-----------: Attach attempt 1, AnyPartition reattaching with Active Dataset
    uart:~$ [00:00:02.051,025] <inf> [I] Mle-----------: AttachState Start -> ParentReq
    uart:~$ [00:00:02.052,124] <inf> [I] Mle-----------: Send Parent Request to routers (ff02:0:0:0:0:0:0:2)
    uart:~$ [00:00:02.057,189] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:84, chksum:0a50, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:02.057,495] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:02.057,800] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ [00:00:02.803,314] <inf> [I] Mle-----------: Send Parent Request to routers (ff02:0:0:0:0:0:0:2)
    uart:~$ [00:00:02.806,823] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:84, chksum:3314, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:02.807,159] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:02.807,464] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ uart:~$ uart:~$ [00:00:03.554,565] <inf> [I] Mle-----------: Send Parent Request to routers and REEDs (ff02:0:0:0:0:0:0:2)
    uart:~$ [00:00:03.560,241] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:84, chksum:43fd, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:03.560,577] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:03.560,882] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ uart:~$ uart:~$ [00:00:04.805,786] <inf> [I] Mle-----------: Send Parent Request to routers and REEDs (ff02:0:0:0:0:0:0:2)
    uart:~$ [00:00:04.809,844] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:84, chksum:a55e, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:04.810,180] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:04.810,485] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ [00:00:05.669,982] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ uart:~$ [00:00:06.057,006] <inf> [I] Mle-----------: Send Parent Request to routers and REEDs (ff02:0:0:0:0:0:0:2)
    uart:~$ [00:00:06.060,760] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:84, chksum:a955, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:06.061,096] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:06.061,401] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ uart:~$ [00:00:07.308,227] <inf> [I] Mle-----------: Send Parent Request to routers and REEDs (ff02:0:0:0:0:0:0:2)
    uart:~$ [00:00:07.312,927] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:84, chksum:50c3, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:07.313,262] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:07.313,568] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ uart:~$ [00:00:08.558,471] <inf> [I] Mle-----------: AttachState ParentReq -> Idle
    uart:~$ [00:00:08.559,570] <inf> [N] RouterTable---: Allocate router id 1
    uart:~$ [00:00:08.560,241] <inf> [N] Mle-----------: RLOC16 fffe -> 0400
    uart:~$ [00:00:08.560,394] <inf> [N] Mle-----------: Role detached -> leader
    uart:~$ [00:00:08.560,943] <inf> [N] Mle-----------: Leader partition id 0x1785d35f
    uart:~$ [00:00:08.561,340] <inf> [I] Notifier------: StateChanged (0x100012a5) [Ip6+ Role Rloc+ PartitionId NetData Ip6Mult+ ActDset]
    uart:~$ [00:00:08.562,408] <inf> [I] Mle-----------: Send Data Response (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:00:08.562,530] <inf> [I] BbrLeader-----: PBBR state: None
    uart:~$ [00:00:08.562,713] <inf> [I] BbrLeader-----: Domain Prefix: ::/0, state: None
    uart:~$ [00:00:08.587,554] <inf> [I] Settings------: Saved NetworkInfo {rloc:0x0400, extaddr:6669063f93c56565, role:leader, mode:0x0f, version:4, keyseq:0x0, ...
    uart:~$ [00:00:08.587,890] <inf> [I] Settings------: ... pid:0x1785d35f, mlecntr:0x7df, maccntr:0x7d0, mliid:170d500574d8ab3f}
    uart:~$ [00:00:08.588,043] <inf> [I] AnnounceSender: Started
    uart:~$ [00:00:08.593,444] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:96, chksum:b816, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:08.593,780] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:08.594,085] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ uart:~$ [00:00:09.233,764] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:00:09.239,379] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:c1f0, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:09.239,715] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:09.240,020] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ [00:00:11.479,095] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:00:11.484,405] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:7a37, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:11.484,741] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:11.485,015] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ [00:00:15.387,756] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:00:15.391,571] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:a4ee, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:15.391,876] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:15.392,181] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ [00:00:19.681,579] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ [00:00:21.637,634] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:00:21.643,615] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:26ae, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:21.643,920] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:21.644,226] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ [00:00:32.577,453] <inf> [I] MeshForwarder-: Received IPv6 UDP msg, len:84, chksum:00ca, ecn:no, from:b2c3f76a9af7158f, sec:no, prio:net, rss:-41.0
    uart:~$ [00:00:32.577,789] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:b0c3:f76a:9af7:158f]:19788
    uart:~$ [00:00:32.578,094] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:2]:19788
    uart:~$ [00:00:32.579,010] <inf> [I] Mle-----------: Receive Parent Request (fe80:0:0:0:b0c3:f76a:9af7:158f)
    uart:~$ [00:00:32.579,803] <inf> [I] Mle-----------: Delay Parent Response (fe80:0:0:0:b0c3:f76a:9af7:158f)
    uart:~$ [00:00:33.018,463] <inf> [I] Mle-----------: Send delayed message (fe80:0:0:0:b0c3:f76a:9af7:158f)
    uart:~$ [00:00:33.025,146] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:133, chksum:8143, ecn:no, to:b2c3f76a9af7158f, sec:no, prio:net
    uart:~$ [00:00:33.025,482] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:33.025,787] <inf> [I] MeshForwarder-:     dst:[fe80:0:0:0:b0c3:f76a:9af7:158f]:19788
    uart:~$ uart:~$ uart:~$ [00:00:34.686,828] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ [00:00:37.224,884] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:00:37.228,912] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:6799, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:00:37.229,248] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:00:37.229,522] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ [00:00:37.935,180] <inf> [I] Mle-----------: Child timeout expired
    uart:~$ uart:~$ uart:~$ ot childip
    Done
    
    uart:~$ [00:00:48.690,338] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ [00:01:03.701,995] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ ot childip
    Done
    
    uart:~$ [00:01:08.170,562] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:01:08.175,537] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:4d49, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:01:08.175,872] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:01:08.176,147] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ [00:01:17.709,106] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ [00:01:30.360,687] <inf> [I] Mle-----------: Send Advertisement (ff02:0:0:0:0:0:0:1)
    uart:~$ [00:01:30.365,356] <inf> [I] MeshForwarder-: Sent IPv6 UDP msg, len:90, chksum:4aa3, ecn:no, to:0xffff, sec:no, prio:net
    uart:~$ [00:01:30.365,692] <inf> [I] MeshForwarder-:     src:[fe80:0:0:0:6469:63f:93c5:6565]:19788
    uart:~$ [00:01:30.365,966] <inf> [I] MeshForwarder-:     dst:[ff02:0:0:0:0:0:0:1]:19788
    uart:~$ uart:~$ [00:01:32.715,637] <dbg> [D] Mac-----------: Frame rx failed, error:DestinationAddressFiltered
    uart:~$ uart:~$ ot childip
    Done
    
    uart:~$ 

    On line 78 you can see a log for "Child timeout expired", this line doesn't appear in the logs of the server on the development kit (I can attach these too if needed)

    I've also included a screenshot of the RTT logs from the client running on the custom board below (again I can include the non custom board if needed too)

    When I run the same example on the development kit the example runs attached ok, confirmed by typing ot childip and responding with the child's ip.

    Below I've included my dts file for the custom board (I've had to change the extension to .txt so the upload would work)

    // Copyright (c) 2022 Nordic Semiconductor ASA
    // SPDX-License-Identifier: Apache-2.0
    
    /dts-v1/;
    
    #include <nordic/nrf52840_qiaa.dtsi>
    / {
    	model = "S3_MAX_V3";
    	compatible = "s3-max-v3";
    
    	chosen {
    			zephyr,console = &uart0;
    		zephyr,shell-uart = &uart0;
    		zephyr,uart-mcumgr = &uart0;
    		zephyr,bt-mon-uart = &uart0;
    		zephyr,bt-c2h-uart = &uart0;
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_partition;
    	};
    	leds {
    		compatible = "gpio-leds";
    		led0: led_0 {
    			gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
    			label = "Red LED 0";
    		};
    		led1: led_1 {
    			gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
    			label = "Green LED 1";
    		};
    		led2: led_2 {
    			gpios = <&gpio0 27 GPIO_ACTIVE_LOW>;
    			label = "Blue LED 2";
    		};
    	};
    	pwmleds {
    		compatible = "pwm-leds";
    		pwm_led0: pwm_led_0 {
    			pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    		};
    	};
    	buttons {
    		compatible = "gpio-keys";
    		button0: button_0 {
    			gpios = <&gpio0 0 ( GPIO_ACTIVE_LOW)>;
    			label = "Push button switch 0";
    		};
    	};
    };
    
    &gpiote {
    	status = "okay";
    };
    
    &gpio0 {
    	status = "okay";
    };
    
    &gpio1 {
    	status = "okay";
    };
    
    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 2)>,
    				<NRF_PSEL(UART_RX, 0, 28)>;
    		};
    	};
    
    	uart0_sleep: uart0_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 2)>,
    				<NRF_PSEL(UART_RX, 0, 28)>;
    			low-power-enable;
    		};
    	};
    };	
    
    &uart0 {
    	compatible = "nordic,nrf-uarte";
    	status = "okay";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart0_default>;
    	pinctrl-1 = <&uart0_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    
    
    &flash0 {
    	partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x0 0xc000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0xc000 0x72000>;
    		};
    		slot1_partition: partition@7e000 {
    			label = "image-1";
    			reg = <0x7e000 0x72000>;
    		};
    		scratch_partition: partition@f0000 {
    			label = "image-scratch";
    			reg = <0xf0000 0xa000>;
    		};
    		storage_partition: partition@fa000 {
    			label = "storage";
    			reg = <0xfa000 0x6000>;
    		};
    	};
    };
    
    

    One thing i wanted to ask was; i've had to add uart pins so the firmware will compile even though my board doesn't have uart. Do you know why these uart pins are needed if the there is no console for the "sleep end device" version? 

  • Does your custom board have an external 32KHz XTAL? If not, can you please try to add this line to your prj.conf:

    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y

    hugzy123 said:
    Do you know why these uart pins are needed if the there is no console for the "sleep end device" version? 

    I am not sure about this. Not my area of expertise. I suggest you create a separate ticket with this question. Doesn't the log that you attached come from UART on your custom board?

  • That fixed my issue, our custom board only has an internal LF clock and I forgot you need to tell the SD to use it. The client example on our custom board can now control the led on the server.

    Thank you for your help. 

    "Doesn't the log that you attached come from UART on your custom board?"

    I was using the dev kit for the serial so had access to UART and on the client I was using RTT logs.

Related