Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

coap-chat: adapt to new gcoap API #74

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions coap-chat/coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ static const coap_resource_t _resources[] = {
};

static gcoap_listener_t _listener = {
&_resources[0],
sizeof(_resources) / sizeof(_resources[0]),
NULL,
NULL
.resources = &_resources[0],
.resources_len = sizeof(_resources) / sizeof(_resources[0]),
.next = NULL,
};

static ssize_t _chat_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, void *ctx)
Expand Down Expand Up @@ -109,9 +108,17 @@ int coap_post(char *addr, char *msgbuf, size_t msglen)
gcoap_req_init(&pdu, buf, CONFIG_GCOAP_PDU_BUF_SIZE,
COAP_POST, COAP_CHAT_PATH);

memcpy(pdu.payload, msgbuf, msglen);
coap_opt_add_format(&pdu, COAP_FORMAT_TEXT);
len = coap_opt_finish(&pdu, COAP_OPT_FINISH_PAYLOAD);

len = gcoap_finish(&pdu, msglen, COAP_FORMAT_TEXT);
if (pdu.payload_len >= msglen) {
memcpy(pdu.payload, msgbuf, msglen);
len += msglen;
}
else {
DEBUG("[CoAP] coap_post: ERROR. The message buffer is too small for the message\n");
return -1;
}

DEBUG("[CoAP] coap_post: sending msg ID %u, %u bytes\n",
coap_get_id(&pdu), (unsigned) len);
Expand Down
1 change: 0 additions & 1 deletion coap-chat/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "msg.h"

#include "net/gcoap.h"
#include "kernel_types.h"
#include "shell.h"

#define BUFLEN (64U)
Expand Down