Browse Source

gcoap: Update CLI example for rebase on sock

pr/spi.typo
Ken Bannister 6 years ago
parent
commit
e10e579593
  1. 5
      examples/gcoap/Makefile
  2. 5
      examples/gcoap/Makefile.slip
  3. 2
      examples/gcoap/README.md
  4. 13
      examples/gcoap/gcoap_cli.c

5
examples/gcoap/Makefile

@ -1,4 +1,4 @@
# Default Makefile, for host native networking
# Default Makefile, for host native GNRC-based networking
# name of your application
APPLICATION = gcoap
@ -29,8 +29,6 @@ BOARD_BLACKLIST := nrf52dk
USEPKG += nanocoap
# Required by nanocoap, but only due to issue #5959.
USEMODULE += posix
# Required by nanocoap to compile nanocoap_sock.
USEMODULE += gnrc_sock_udp
# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
@ -38,6 +36,7 @@ USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules
USEMODULE += gnrc_ipv6_default
USEMODULE += gnrc_sock_udp
USEMODULE += gcoap
# Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo

5
examples/gcoap/Makefile.slip

@ -1,4 +1,4 @@
# Border router Makefile for SLIP based networking
# Border router Makefile for GNRC and SLIP based networking
# Assumes use of SAMR21 board
# name of your application
@ -45,14 +45,13 @@ CFLAGS += -DSLIP_BAUDRATE=$(SLIP_BAUDRATE)
USEPKG += nanocoap
# Required by nanocoap, but only due to issue #5959.
USEMODULE += posix
# Required by nanocoap to compile nanocoap_sock.
USEMODULE += gnrc_sock_udp
# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules
USEMODULE += gnrc_sock_udp
USEMODULE += gcoap
# Add a routing protocol
USEMODULE += gnrc_rpl

2
examples/gcoap/README.md

@ -1,6 +1,6 @@
# gcoap Example
This application provides command line access to gcoap, a GNRC implementation of CoAP. See the [CoAP spec][1] for background, and the Modules>Networking>GNRC>CoAP topic in the source documentation for the structure of the implementation.
This application provides command line access to gcoap, a high-level API for CoAP messaging. See the [CoAP spec][1] for background, and the Modules>Networking>CoAP topic in the source documentation for detailed usage instructions and implementation notes.
We support two setup options for this example:

13
examples/gcoap/gcoap_cli.c

@ -96,22 +96,27 @@ static ssize_t _stats_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len)
static size_t _send(uint8_t *buf, size_t len, char *addr_str, char *port_str)
{
ipv6_addr_t addr;
uint16_t port;
size_t bytes_sent;
sock_udp_ep_t remote;
remote.family = AF_INET6;
remote.netif = SOCK_ADDR_ANY_NETIF;
/* parse destination address */
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
puts("gcoap_cli: unable to parse destination address");
return 0;
}
memcpy(&remote.addr.ipv6[0], &addr.u8[0], sizeof(addr.u8));
/* parse port */
port = (uint16_t)atoi(port_str);
if (port == 0) {
remote.port = (uint16_t)atoi(port_str);
if (remote.port == 0) {
puts("gcoap_cli: unable to parse destination port");
return 0;
}
bytes_sent = gcoap_req_send(buf, len, &addr, port, _resp_handler);
bytes_sent = gcoap_req_send2(buf, len, &remote, _resp_handler);
if (bytes_sent > 0) {
req_count++;
}

Loading…
Cancel
Save