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:
parent
9db31389e0
commit
9d17a74df8
@ -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);
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
#include "msg.h"
|
||||
|
||||
#include "net/gcoap.h"
|
||||
#include "kernel_types.h"
|
||||
#include "shell.h"
|
||||
|
||||
#define BUFLEN (64U)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user