-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg: add yacoap, Yet another CoAP library #5830
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# name of your application | ||
APPLICATION = yacoap_posix | ||
|
||
# If no BOARD is found in the environment, use this default: | ||
BOARD ?= native | ||
|
||
# This has to be the absolute path to the RIOT base directory: | ||
RIOTBASE ?= $(CURDIR)/../.. | ||
|
||
BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ | ||
nrf6310 pca10000 pca10005 spark-core \ | ||
stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ | ||
yunjia-nrf51822 z1 nucleo-f072 | ||
|
||
# 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 for IPv6 and UDP | ||
USEMODULE += gnrc_ipv6_default | ||
USEMODULE += gnrc_udp | ||
USEMODULE += gnrc_conn_udp | ||
USEMODULE += posix_sockets | ||
USEMODULE += gnrc_icmpv6_echo | ||
USEMODULE += shell | ||
USEMODULE += shell_commands | ||
USEMODULE += ps | ||
# include YaCoAP package | ||
USEPKG += yacoap | ||
|
||
# Set a custom 802.15.4 channel if needed | ||
DEFAULT_CHANNEL ?= 26 | ||
CFLAGS += -DDEFAULT_CHANNEL=$(DEFAULT_CHANNEL) | ||
|
||
# Comment this out to disable code in RIOT that does safety checking | ||
# which is not needed in a production environment but helps in the | ||
# development process: | ||
#CFLAGS += -DDEVELHELP | ||
|
||
# Use different settings when compiling for one of the following (low-memory) | ||
# boards | ||
LOW_MEMORY_BOARDS := nucleo-f334 | ||
|
||
ifneq (,$(filter $(BOARD),$(LOW_MEMORY_BOARDS))) | ||
$(info Using low-memory configuration for microcoap_server.) | ||
## low-memory tuning values | ||
# lower pktbuf buffer size | ||
CFLAGS += -DGNRC_PKTBUF_SIZE=1000 | ||
# disable fib, rpl | ||
DISABLE_MODULE += fib gnrc_rpl | ||
USEMODULE += prng_minstd | ||
endif | ||
|
||
# Change this to 0 show compiler invocation lines by default: | ||
QUIET ?= 1 | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# examples/yacoap_posix | ||
|
||
This example shows basic usage of YaCoAP in RIOT. It shows CoAP client and | ||
server side functions using POSIX sockets. However YaCoAP is completely | ||
independent of any underlying send or receive API, its a plain CoAP packet | ||
handler. So POSIX sockets can be replaced easily, e.g. using RIOTs `conn` or | ||
future `sock` API. | ||
|
||
## CoAP server part | ||
|
||
This example starts a server thread that provides 2 distinct resources, namely: | ||
`/riot/board` and `/riot/mcu`. Both can be accessed using CoAP GET requests. | ||
Further, this example also provides the obligatory `/.well-known/core` in | ||
standard link-format. | ||
|
||
## CoAP client part | ||
|
||
This example provides 2 CoAP client calls through the RIOT shell, as follows: | ||
|
||
* `get <ip>`: retrieving `/.well-known/core` from the specified CoAP server ip | ||
* `put <ip> <path> <content>`: sending a PUT request to the specified CoAP | ||
server creating or modifying resource in `path` with `content`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (C) 2016 smlng <s@mlng.net> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup examples | ||
* @{ | ||
* | ||
* @file | ||
* @brief YaCoAP example showing CoAP client and server functions | ||
* | ||
* @author smlng <s@mlng.net> | ||
* | ||
* @} | ||
*/ | ||
|
||
// standard | ||
#include <inttypes.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
// riot | ||
#include "board.h" | ||
#include "periph/gpio.h" | ||
#include "shell.h" | ||
|
||
int coap_pid = -1; | ||
|
||
extern int coap_start_thread(void); | ||
extern int coap_get(const char *ip); | ||
extern int coap_put(const char *ip, const char *path, const char *content); | ||
|
||
static int cmd_get(int argc, char **argv); | ||
static int cmd_put(int argc, char **argv); | ||
|
||
// array with available shell commands | ||
static const shell_command_t shell_commands[] = { | ||
{ "get", "get ./well-known/core", cmd_get }, | ||
{ "put", "modify a resource", cmd_put }, | ||
{ NULL, NULL, NULL } | ||
}; | ||
|
||
/** | ||
* @brief the main programm loop | ||
* | ||
* @return non zero on error | ||
*/ | ||
int main(void) | ||
{ | ||
// some initial infos | ||
puts(" YaCoAP example - Yet another CoAP library"); | ||
puts("=========================================="); | ||
printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); | ||
printf("This board features a(n) %s MCU.\n", RIOT_MCU); | ||
puts("=========================================="); | ||
LED0_ON; | ||
// start coap receiver | ||
puts(". init coap"); | ||
if ((coap_pid = coap_start_thread()) < 0) { | ||
puts("failed to init coap thread!"); | ||
return 1; | ||
} | ||
puts(":"); | ||
// start shell | ||
puts(". init shell"); | ||
puts(":"); | ||
LED0_OFF; | ||
char line_buf[SHELL_DEFAULT_BUFSIZE]; | ||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); | ||
// should be never reached | ||
return 0; | ||
} | ||
|
||
int cmd_get(int argc, char **argv) | ||
{ | ||
if (argc != 2) { | ||
puts ("USAGE: get <ip>"); | ||
return 1; | ||
} | ||
coap_get(argv[1]); | ||
return 0; | ||
} | ||
|
||
int cmd_put(int argc, char **argv) | ||
{ | ||
if (argc != 4) { | ||
puts("USAGE: put <ip> <path> <content>"); | ||
return 1; | ||
} | ||
coap_put(argv[1], argv[2], argv[3]); | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please port to sock (see #6005).