1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-19 19:43:52 +01:00

Merge pull request https://github.com/RIOT-OS/applications/pull/74 from leandrolanzieri/pr/coap_chat/adapt_new_gcoap_api

coap-chat: adapt to new gcoap API
This commit is contained in:
Martine Lenders 2021-02-05 13:11:25 +01:00 committed by chrysn
commit c71f74e2a9
2 changed files with 13 additions and 7 deletions

View File

@ -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)
@ -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);

View File

@ -22,7 +22,6 @@
#include "msg.h"
#include "net/gcoap.h"
#include "kernel_types.h"
#include "shell.h"
#define BUFLEN (64U)