Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
c9c7bf8d
Commit
c9c7bf8d
authored
6 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
examples: add example for rdcli
parent
899d7fee
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/rdcli/Makefile
+33
-0
33 additions, 0 deletions
examples/rdcli/Makefile
examples/rdcli/README.md
+20
-0
20 additions, 0 deletions
examples/rdcli/README.md
examples/rdcli/main.c
+108
-0
108 additions, 0 deletions
examples/rdcli/main.c
with
161 additions
and
0 deletions
examples/rdcli/Makefile
0 → 100644
+
33
−
0
View file @
c9c7bf8d
# name of your application
APPLICATION
=
rdcli
# 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
)
/../..
USEMODULE
+=
gnrc_netdev_default
USEMODULE
+=
auto_init_gnrc_netif
USEMODULE
+=
gnrc_ipv6_default
USEMODULE
+=
gnrc_icmpv6_echo
USEMODULE
+=
rdcli_standalone
USEMODULE
+=
shell
USEMODULE
+=
shell_commands
USEMODULE
+=
ps
USEMODULE
+=
fmt
# 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
# For debugging and demonstration purposes, we limit the lifetime to 60s
CFLAGS
+=
-DRDCLI_LT
=
60
# Change this to 0 show compiler invocation lines by default:
QUIET
?=
1
include
$(RIOTBASE)/Makefile.include
This diff is collapsed.
Click to expand it.
examples/rdcli/README.md
0 → 100644
+
20
−
0
View file @
c9c7bf8d
CoRE Resource Directory Client Example
======================================
This example application demonstrates the usage of RIOT's Resource Directory
(RD) client module, called
`rdcli`
. This module supports the registration,
update, and removal processes as defined in the
[
Resource Directory Draft
](
https://tools.ietf.org/html/draft-ietf-core-resource-directory-14
)
.
Usage
=====
The examples includes a shell command that you can use to interact with a given
RD server, called
`rdcli`
. Simply use that shell command without parameters for
more information on its usage.
Some connection parameters are configured statically during compile time,
namely the lifetime (
`RDCLI_LT`
) and the node's endpoint name (
`RDCLI_EP`
). You
can change these values during command line by overriding these values in the
application's Makefile, e.g. add
```
CFLAGS += "-DRDCLI_EP=\"MyNewEpName\""
```
This diff is collapsed.
Click to expand it.
examples/rdcli/main.c
0 → 100644
+
108
−
0
View file @
c9c7bf8d
/*
* Copyright (C) 2017-2018 Freie Universität Berlin
*
* 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 CoRE Resource Directory client (rdcli) example application
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include
<stdio.h>
#include
"fmt.h"
#include
"shell.h"
#include
"net/ipv6/addr.h"
#include
"net/gcoap.h"
#include
"net/rdcli_common.h"
#include
"net/rdcli_standalone.h"
#define MAIN_QUEUE_SIZE (8)
static
msg_t
_main_msg_queue
[
MAIN_QUEUE_SIZE
];
/* we will use a custom event handler for dumping rdcli_standalone events */
static
void
_on_rdcli_event
(
rdcli_standalone_event_t
event
)
{
switch
(
event
)
{
case
RDCLI_REGISTERED
:
puts
(
"rdcli event: now registered with a RD"
);
break
;
case
RDCLI_DEREGISTERED
:
puts
(
"rdcli event: dropped client registration"
);
break
;
case
RDCLI_UPDATED
:
puts
(
"rdcli event: successfully updated client registration"
);
break
;
}
}
/* define some dummy CoAP resources */
static
ssize_t
_handler_dummy
(
coap_pkt_t
*
pdu
,
uint8_t
*
buf
,
size_t
len
,
void
*
ctx
)
{
(
void
)
ctx
;
/* get random data */
int16_t
val
=
23
;
gcoap_resp_init
(
pdu
,
buf
,
len
,
COAP_CODE_CONTENT
);
size_t
plen
=
fmt_s16_dec
((
char
*
)
pdu
->
payload
,
val
);
return
gcoap_finish
(
pdu
,
plen
,
COAP_FORMAT_TEXT
);
}
static
ssize_t
_handler_info
(
coap_pkt_t
*
pdu
,
uint8_t
*
buf
,
size_t
len
,
void
*
ctx
)
{
(
void
)
ctx
;
gcoap_resp_init
(
pdu
,
buf
,
len
,
COAP_CODE_CONTENT
);
size_t
slen
=
sizeof
(
"SOME NODE INFOMRATION"
);
memcpy
(
pdu
->
payload
,
"SOME NODE INFOMRATION"
,
slen
);
return
gcoap_finish
(
pdu
,
slen
,
COAP_FORMAT_TEXT
);
}
static
const
coap_resource_t
_resources
[]
=
{
{
"/node/info"
,
COAP_GET
,
_handler_info
,
NULL
},
{
"/sense/hum"
,
COAP_GET
,
_handler_dummy
,
NULL
},
{
"/sense/temp"
,
COAP_GET
,
_handler_dummy
,
NULL
}
};
static
gcoap_listener_t
_listener
=
{
.
resources
=
(
coap_resource_t
*
)
&
_resources
[
0
],
.
resources_len
=
sizeof
(
_resources
)
/
sizeof
(
_resources
[
0
]),
.
next
=
NULL
};
int
main
(
void
)
{
/* we need a message queue for the thread running the shell in order to
* receive potentially fast incoming networking packets */
msg_init_queue
(
_main_msg_queue
,
MAIN_QUEUE_SIZE
);
puts
(
"CoRE RD client example!
\n
"
);
/* setup CoAP resources */
gcoap_register_listener
(
&
_listener
);
/* register event callback with rdcli_standalone */
rdcli_standalone_reg_cb
(
_on_rdcli_event
);
puts
(
"Client information:"
);
printf
(
" ep: %s
\n
"
,
rdcli_common_get_ep
());
printf
(
" lt: %is
\n
"
,
(
int
)
RDCLI_LT
);
char
line_buf
[
SHELL_DEFAULT_BUFSIZE
];
shell_run
(
NULL
,
line_buf
,
SHELL_DEFAULT_BUFSIZE
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment