Not receiving CoAP messages on Border Router

nRF52840
NCS 3.0.1
MCUBOOT

OTBR on Raspberry Pi 4

I am running the OTBR on a Raspberry Pi 4 with the RCP on a dongle.  I am running the coap_client on a nRF52840DK.  I have written a simple coap server for the Raspberry Pi, but it is not seeing any messages.

coap server code

#include <coap3/coap.h>
#include <stdio.h>
#include <string.h>

int getCnt = 0;

void hnd_provisioning_get(coap_resource_t *resource,
                     coap_session_t *session,
                     const coap_pdu_t *request,
                     const coap_string_t *query,
                     coap_pdu_t *response)
{
	getCnt++;

	time_t now;
	now = time(NULL);
	
	printf("Provisioning GET received %d times.\n", getCnt);

	unsigned char buf[] = "Provisioning response";

	coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
	coap_add_data(response, strlen((char *)buf), buf);

} //end: hnd_provisioning_get()

int main(void)
{
	coap_context_t *ctx=NULL;
	coap_resource_t *resource=NULL;
	coap_endpoint_t *endpoint=NULL;
	struct coap_address_t addr;

	// Initialize libcoap
	coap_startup();

	// Set up the server address (UDP, port 5683)
	// Set up for IPv6 wildcard address
 	coap_address_init(&addr);
   	addr.addr.sin6.sin6_family = AF_INET6;
    	addr.addr.sin6.sin6_addr = in6addr_any; 		// Listen on any IPv6 address
    	addr.addr.sin6.sin6_port = htons(COAP_DEFAULT_PORT); 	// Default CoAP port (5683)
    	addr.size = sizeof(addr.addr.sin6);

	// Create CoAP context
	ctx = coap_new_context(NULL);
	if (!ctx)
	{
		printf("Cannot create CoAP context\n");
		return -1;
	}

	
	// Create UDP endpoint
	endpoint = coap_new_endpoint(ctx, &addr, COAP_PROTO_UDP);
	if (!endpoint)
	{
		printf("Cannot create endpoint\n");
		coap_free_context(ctx);
		coap_cleanup();
		return -1;
	}

	// Create resources
	resource = coap_resource_init(coap_make_str_const("provisioning"),0);
	if (!resource)
	{
		printf("Cannot create resource: provisioning\n");
		coap_free_context(ctx);
		coap_cleanup();
		return -1;
	}

	// Register GET handlers
	coap_register_handler(resource,COAP_REQUEST_GET, hnd_provisioning_get);

	// Add resource to context
	coap_add_resource(ctx, resource);
	
	printf("CoAP server running on port %d...\n", COAP_DEFAULT_PORT);
	
	// Main loop to process CoAP packets
	while(1)
	{
		//coap_io_process(ctx, COAP_IO_NO_WAIT);
		coap_io_process(ctx, COAP_IO_WAIT);		// MSEC
printf("\rGetCnt: %d", getCnt);
	} // endwhile: 1

	// Cleanup
	coap_free_context(ctx);
	coap_cleanup();

	return 0;
} //end: main()

When I run the coap_server and then restart the coap_client, I can see the "provisionng" messages on Wireshark, but there is no response from the coap server.

The Raspberry Pi shows:

c@raspberrypi4:~/coap_server $ ./coap_server
CoAP server running on port 5683...

If I run netcat, it seems to receive the UDP message from the coap_client:

:~/coap_server $ netcat -lu :: 5683
H+}▒u▒=T▒▒provisioning▒▒▒6▒R▒▒^C

What's wrong with my setup?

Mary

Parents
  • Hi Mary,

    Thanks for checking with us regarding your questions.

    I hope you’ve already verified that the original Thread Client and Server examples work as expected on the nRF DKs. Your questions are a bit outside our direct support scope, but I’m happy to share some advice that might help you move forward.

    It’s likely that your CoAP server is running on an IPv4 LAN by default. As per the OpenThread Border Router document, proper NAT64 configuration is required for communication between the IPv6-based Thread network and an external IPv4 network.

    To resolve this, you can either:

    • Set up the server directly within the OpenThread network, or

    • Ensure that NAT64 is correctly configured to bridge the IPv6 Thread devices to the IPv4 LAN.

    Please confirm which network your server is using to and verify whether a connection can be established.

    For further technical insights, I recommend checking or posting your question in the OpenThread GitHub Discussions, where the Thread/OTBR developer community is very active.

    Best regards,
    Charlie

Reply
  • Hi Mary,

    Thanks for checking with us regarding your questions.

    I hope you’ve already verified that the original Thread Client and Server examples work as expected on the nRF DKs. Your questions are a bit outside our direct support scope, but I’m happy to share some advice that might help you move forward.

    It’s likely that your CoAP server is running on an IPv4 LAN by default. As per the OpenThread Border Router document, proper NAT64 configuration is required for communication between the IPv6-based Thread network and an external IPv4 network.

    To resolve this, you can either:

    • Set up the server directly within the OpenThread network, or

    • Ensure that NAT64 is correctly configured to bridge the IPv6 Thread devices to the IPv4 LAN.

    Please confirm which network your server is using to and verify whether a connection can be established.

    For further technical insights, I recommend checking or posting your question in the OpenThread GitHub Discussions, where the Thread/OTBR developer community is very active.

    Best regards,
    Charlie

Children
  • The first message send from the client is the "provisioning" request using a multicast address.  It worked after I made these changes:

    On the coap server:

    •  coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);  to support multicast
    • // Join multicast group
      if (coap_join_mcast_group(ctx, "ff03::1") < 0) {
      printf("Failed to join multicast group ff03::1\n");
      coap_free_context(ctx);
      coap_cleanup();
      return -1;
      }

    On the client:

    • Set "provisioning" request code to non-confirmable, and no payload

    Now it works.

    Mary

Related