Professional Documents
Culture Documents
INRIA
November 7, 2014
2 Using RIOT
4 Reading a Sensor
Agenda
2 Using RIOT
4 Reading a Sensor
The Architecture
RIOT
boards
iot-lab_M3
core
cpu
cortex-m3_common
stm32f1
dist
doc
drivers
at86rf231
isl29020
examples
hello-world
pkg
libcoap
sys
net
network_layer
sixlowpan
tests
Dos
Use static memory
Select the priorities carefully
Minimize stack usage with DEVELHELP and CREATE_STACKTEST
Use threads
Donts
Don’t use threads
Dos
Use static memory
Select the priorities carefully
Minimize stack usage with DEVELHELP and CREATE_STACKTEST
Use threads
Increase flexibility, modularity, and robustness by using IPC.
Donts
Don’t use threads
Try not to use more than one thread per module.
Don’t create threads for one-time tasks.
Don’t use the POSIX wrapper if implementing something from scratch
Consult the Wiki: http://wiki.riot-os.org
...and the API documentation: http://doc.riot-os.org
Agenda
2 Using RIOT
4 Reading a Sensor
It’s time to send our first packet (assuming that the first node is still running and configured to
address 42.):
> txtsnd 42 riotlab
[ transceiver ] Sending packet of length 8 to 42: riotlab
[ transceiver ] Packet sent : 60
Call just BOARD=iot-lab_M3 make all to build the binary (elf and hex are built).
Flash the nodes like usual (using the IoT-Lab web interface).
If you want use it somewhat more comfortable than using netcat, you can use the
same tool which is used for a locally connected node: pyterm.
You can find it in dist/tools/pyterm.
For example, run pyterm -ts m3-7:20000 on grenoble.iot-lab.info.
> help
help
Command Description
---------------------------------------
nc RIOT netcat - arbitrary UDP connections and listens
ping Send an ICMPv6 echo request to another node
reboot Reboot the node
id Gets or sets the node ’ s id .
ps Prints information about running threads .
addr Gets or sets the address for the transceiver
eui64 Gets or sets the EUI -64 for the transceiver
chan Gets or sets the channel for the transceiver
txtsnd Sends a text message to a given node via the transceiver
pan Gets or sets the pan id for the transceiver
monitor Enables or disables address checking for the transceiver
ifconfig Configures a network interface
The selection of commands depends on the configuration of your application (and may vary a
little bit for different platforms).
Let’s communicate
The sixlowapp application provides you with two custom (application defined) shell commands:
1 ping: The famous ICMP diagnosis tool.
2 nc: A very basic variation of netcat for arbitrary UDP connections.
After we flashed two nodes, we’ll have to find out their IPv6 addresses using ifconfig:
> ifconfig
INFO #
INFO # Iface 0 HWaddr : 0 xa86c Channel : 11 PAN ID : 0 x0001
INFO # EUI -64: 4d -5 e - fd -8 e -47 -3 c -5 f -80
INFO # Source address mode : short
INFO # Transceivers :
INFO # * at86rf231
INFO # inet6 addr : fe80 :: ff : fe00 : a86c /128 scope : local
INFO # inet6 addr : ff02 ::1: ff00 : a86c /128 scope : local [
multicast ]
INFO # inet6 addr : ff02 ::1/128 scope : local [ multicast ]
INFO #
If you run this example in native, you can also monitor the traffic with Wireshark.
The dissector can be found in dist/tools/wireshark_dissector.
There’s a python framework to setup arbitrary topologies using defined loss-rates:
http://wiki.riot-os.org/Virtual-riot-network
Agenda
2 Using RIOT
4 Reading a Sensor
The Makefile
To create your own RIOT example, you need only two files:
1 A C (or C++) file with a main function
2 A Makefile
You can find a template for a Makefile in dist/Makefile.
# Giving your application a name
APPLICATION = riotlab1
# Choosing a default platform
BOARD ?= native
# Specifying the RIOT folder
RIOTBASE ?= $ ( CURDIR ) /../../ RIOT
# Some helpful compiler flags
CFLAGS += - DSCHEDSTATIST I C S - DDEVELHELP
# Quieten the building process
QUIET ?= 1
# Modules to include :
USEMODULE += posix
USEMODULE += vtimer
# Let RIOT ’ s build system take care of the rest
include $ ( RIOTBASE ) / Makefile . include
The only mandatory thing in your application is a main function with this prototype:
int main(void)
Standard C libraries can be used and parts of POSIX are ble through a wrapper within RIOT.
# include < stdio .h >
# include < unistd .h >
return 0;
}
Instead of POSIX functions is usually advisable (and more efficient) to just use the native RIOT
functions:
return 0;
}
...
const sh ell_command_t sh ell_c ommand s [] = {
{ " ping " , " Send an ICMPv6 echo request to another node " ,
s i x l o w a p p _s e n d _ p i n g } ,
{ NULL , NULL , NULL }
};
...
...and 6LoWPAN
kernel_pid_t monitor_pid =
thread_create ( monitor_stack_buffer , sizeof ( m o n i t o r _ s t a c k _ b u f f e r ) ,
PRIORITY_MAIN - 2 , CREATE_STACKTEST , sixlowapp_monitor ,
NULL , " monitor " ) ;
i p v 6 _ r e g i s t e r _ p a c k e t _ h a n d l e r ( monitor_pid ) ;
...
while (1) {
msg_receive (& m ) ;
if ( m . type == I P V 6 _ P A C K E T _ R E C E I V E D ) {
ipv6_buf = ( ipv6_hdr_t *) m . content . ptr ;
if ( ipv6_buf - > nextheader == I P V 6 _ P R O T O _ N U M _ I C M P V 6 ) {
icmpv6_hdr_t * icmpv6_buf =
( icmpv6_hdr_t *) &(( uint8_t *) ipv6_buf ) [( IPV6_HDR_LEN ) ];
if ( icmpv6_buf - > type == I C M P V 6 _ T Y P E _ E C H O _ R E P L Y ) {
if ( _wa i t i n g _ f o r _ p o n g ) {
msg_t m ;
m . type = I C M P _ E C H O _ R E P L Y _ R C V D ;
_w a i t i n g _ f o r _ p o n g = 0;
msg_send (& m , _waiter_pid , false ) ;
}
}
}
}
}
printf ( " Listening for incoming UDP connection at port % " PRIu16 " \ n " ,
sixlowapp_netcat_listen_port );
int32_t recsize = s o c k e t _ b a s e _ r e c v f r o m ( sock , ( void *) buffer_main ,
UDP_BUFFER_SIZE , 0 , & sa , & fromlen ) ;
if ( recsize < 0) {
printf ( " ERROR : recsize < 0!\ n " ) ;
}
Agenda
2 Using RIOT
4 Reading a Sensor
Agenda
2 Using RIOT
4 Reading a Sensor
Mailing Lists
devel@riot-os.org
users@riot-os.org
IRC on irc.freenode.org, #riot-os
Regular video conferencing meetings
Thank you!
Any questions?