This task is a little bit more advanced so don't be discouraged if things are a little bit harder. With the knowledge you gathered from the previous tasks you should be able to handle it.
It uses the example applications in the RIOT repository.
- Go to the
gnrc_minimalapplication - Compile and run on
native - Should print something like
My address is fe80::d403:24ff:fe89:2460 - Ping RIOT instance from Linux:
ping <RIOT-IPv6-addr>%tapbr0Note: on MAC use bridge0 instead of tapbr0.
- Add the
gnrc_udpmodule to the application's Makefile - To be able to receive packets, a message queue must be created using msg_init_queue:
msg_t msg_queue[num];
msg_init_queue(msg_queue, num);Note: num must be in powers of 2.
- You can register for packets of a certain type and context (port 8888 in our
case) using
gnrc_netreg_register()fromnet/gnrc/netreg.h: - The current thread can be obtained with the
thread_getpid()function fromthread.h
gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(8888, thread_getpid());
gnrc_netreg_register(GNRC_NETTYPE_UDP, &server);- Packets can be received using the IPC receive function msg_receive():
msg_t msg;
msg_receive(&msg);Remember to remove the packet after reception (otherwise the packet buffer will overflow)!
#include "net/gnrc/pktbuf.h"
/* ... */
gnrc_pktsnip_t *pkt = (gnrc_pktsnip_t *)msg.content.ptr;
gnrc_pktbuf_release(pkt);- Extend
gnrc_minimalas such that it counts received UDP packets on port 8888. - Use
netcaton your host to test your application on native node.
- Go to the
gnrc_networkingapplication - Have a look in
udp.chow packets are constructed and send - Compile, flash, and run on the board
BOARD=samr21-xpro make all flash term - Type
help - Start UDP server on port 8888 using
udp server 8888 - Get your IPv6 address using
ifconfig - Send your neighbor some messages using
udp send