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

coap-chat: adapt to new gcoap API

This commit is contained in:
Leandro Lanzieri 2021-02-04 17:10:25 +01:00 committed by chrysn
parent 9db31389e0
commit 9d17a74df8
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 = { static gcoap_listener_t _listener = {
&_resources[0], .resources = &_resources[0],
sizeof(_resources) / sizeof(_resources[0]), .resources_len = sizeof(_resources) / sizeof(_resources[0]),
NULL, .next = NULL,
NULL
}; };
static ssize_t _chat_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, void *ctx) 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, gcoap_req_init(&pdu, buf, CONFIG_GCOAP_PDU_BUF_SIZE,
COAP_POST, COAP_CHAT_PATH); 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", DEBUG("[CoAP] coap_post: sending msg ID %u, %u bytes\n",
coap_get_id(&pdu), (unsigned) len); coap_get_id(&pdu), (unsigned) len);

View File

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