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