CoAP Request Handler?

Hi there!

After having worked with the nRF5 SDK and nRF SDK for Mesh, I'm off to a start for a project with LTE; CoAP to be precise. I'm using the nRF Connect SDK with Visual Studio Code extension and I'm absolutely loving it with my nRF9160 DK.

So, I went ahead and took the CoAP Client Example and have setup an instance of ThingsBoard on my server. I know everyone suggests to use Leshan, but you can be assured that everythings is working correctly; I've written a counter that increments on the dashboard. Hence, I changed the main of the example to this.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static int client_post_send(const char* payload){
int err;
struct coap_packet request;
next_token++;
err = coap_packet_init(&request, coap_buf, sizeof(coap_buf),
APP_COAP_VERSION, COAP_TYPE_NON_CON,
sizeof(next_token), (uint8_t *)&next_token,
COAP_METHOD_POST, coap_next_id());
if (err < 0) {
printk("Failed to create CoAP request, %d\n", err);
return err;
}
const char* path = "api/v1/T2_TEST_TOKEN/telemetry";
err = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
(uint8_t *)path,
strlen(path));
if (err < 0) {
printk("Failed to encode CoAP option, %d\n", err);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Now that this is working, I'd like to also be able to receive messages. As can be seen in the code snippet above. This, however, crashes the nRF... Now I'm wondering if this is even the best approach; polling seems like an indesirable method. Isn't there a way to register a callback that's triggered whenever a POST, GET or PUT request is received?

I could of course be overlooking something since I'm quite new to all this, but I couldn't realy manage to plough through the Zephyr documentation. I'm hoping some of you could help me out.

Kind regards,

A learning Jochem

  • The Server responds appropriately by every request. I know it because used trace collector to trace the transmission. Now what i want, is to be able to get a response from server without having to trace the transmission for me to know if the server responded appriopriately

1 2