Skip to content
Snippets Groups Projects
Commit e10e5795 authored by Ken Bannister's avatar Ken Bannister
Browse files

gcoap: Update CLI example for rebase on sock

parent af1eca90
No related branches found
No related tags found
No related merge requests found
# Default Makefile, for host native networking # Default Makefile, for host native GNRC-based networking
# name of your application # name of your application
APPLICATION = gcoap APPLICATION = gcoap
...@@ -29,8 +29,6 @@ BOARD_BLACKLIST := nrf52dk ...@@ -29,8 +29,6 @@ BOARD_BLACKLIST := nrf52dk
USEPKG += nanocoap USEPKG += nanocoap
# Required by nanocoap, but only due to issue #5959. # Required by nanocoap, but only due to issue #5959.
USEMODULE += posix USEMODULE += posix
# Required by nanocoap to compile nanocoap_sock.
USEMODULE += gnrc_sock_udp
# Include packages that pull up and auto-init the link layer. # Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
...@@ -38,6 +36,7 @@ USEMODULE += gnrc_netdev_default ...@@ -38,6 +36,7 @@ USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules # Specify the mandatory networking modules
USEMODULE += gnrc_ipv6_default USEMODULE += gnrc_ipv6_default
USEMODULE += gnrc_sock_udp
USEMODULE += gcoap USEMODULE += gcoap
# Additional networking modules that can be dropped if not needed # Additional networking modules that can be dropped if not needed
USEMODULE += gnrc_icmpv6_echo USEMODULE += gnrc_icmpv6_echo
......
# Border router Makefile for SLIP based networking # Border router Makefile for GNRC and SLIP based networking
# Assumes use of SAMR21 board # Assumes use of SAMR21 board
# name of your application # name of your application
...@@ -45,14 +45,13 @@ CFLAGS += -DSLIP_BAUDRATE=$(SLIP_BAUDRATE) ...@@ -45,14 +45,13 @@ CFLAGS += -DSLIP_BAUDRATE=$(SLIP_BAUDRATE)
USEPKG += nanocoap USEPKG += nanocoap
# Required by nanocoap, but only due to issue #5959. # Required by nanocoap, but only due to issue #5959.
USEMODULE += posix USEMODULE += posix
# Required by nanocoap to compile nanocoap_sock.
USEMODULE += gnrc_sock_udp
# Include packages that pull up and auto-init the link layer. # Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
USEMODULE += gnrc_netdev_default USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif USEMODULE += auto_init_gnrc_netif
# Specify the mandatory networking modules # Specify the mandatory networking modules
USEMODULE += gnrc_sock_udp
USEMODULE += gcoap USEMODULE += gcoap
# Add a routing protocol # Add a routing protocol
USEMODULE += gnrc_rpl USEMODULE += gnrc_rpl
......
# gcoap Example # 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: We support two setup options for this example:
......
...@@ -96,22 +96,27 @@ static ssize_t _stats_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len) ...@@ -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) static size_t _send(uint8_t *buf, size_t len, char *addr_str, char *port_str)
{ {
ipv6_addr_t addr; ipv6_addr_t addr;
uint16_t port;
size_t bytes_sent; size_t bytes_sent;
sock_udp_ep_t remote;
remote.family = AF_INET6;
remote.netif = SOCK_ADDR_ANY_NETIF;
/* parse destination address */ /* parse destination address */
if (ipv6_addr_from_str(&addr, addr_str) == NULL) { if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
puts("gcoap_cli: unable to parse destination address"); puts("gcoap_cli: unable to parse destination address");
return 0; return 0;
} }
memcpy(&remote.addr.ipv6[0], &addr.u8[0], sizeof(addr.u8));
/* parse port */ /* parse port */
port = (uint16_t)atoi(port_str); remote.port = (uint16_t)atoi(port_str);
if (port == 0) { if (remote.port == 0) {
puts("gcoap_cli: unable to parse destination port"); puts("gcoap_cli: unable to parse destination port");
return 0; 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) { if (bytes_sent > 0) {
req_count++; req_count++;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment