Tuesday, April 19, 2016

UDP communication example in RIOT

In a previous post, I wrote about how to try the basic networking example in RIOT OS called "gnrc_networking". In that post, I wrote only about how to ping from one RIOT instance to another. However, this example application supports running a UDP server and a client to deliver data packets. In this blog post, I decided to try describe how I tried that UDB communication. Here we go.

(1) Start the TAP devices as usual.

cd RIOT
./dist/tools/tapsetup/tapsetup -c 2

(2) From a one shell window, run the following commands to start a RIOT instance and set its IP address. When setting the IP address, the value 6 given as the second parameter to the ifconfig command is the name of the network interface of this RIOT instance. We found out that by initially giving the ifconfig command.

cd RIOT/examples/gnrc_networking
make all term PORT=tap0
ifconfig
ifconfig 6 add 2001:db8::1/64

(3) Open another shell window and run the following commands to get another RIOT instance up and running.

make term PORT=tap1
ifconfig
ifconfig 6 add 2001:db8::2/64

(4) Now we can try pinging from the first RIOT instance to the other to check whether we have the connectivity properly.

ping6 2001:db8::2

(5) It's time to try the UDP example. Goto the shell of the first RIOT instance and give the following command to start a UDP server there.

udp server start 8080

(6) Now, goto the second RIOT instance and use the following command to send a string message called  "hello" from the second RIOT instance to the first.

udp send 2001:db8::1 8080 hello

Once this command was entered in the shell of second RIOT instance, we should be able to see that first RIOT instance receives it and prints the details. In case we want to send multiple consecutive UDP packets from the client to the sender, we can specify the number  in the above command. Following line shows the command to send "hello" message 10 times.

udp send 2001:db8::1 8080 hello 10

One thing I like in RIOT more than any other OS for resource constrained devices is this shell prompt with some interesting tools to demonstrate its capabilities.

(7) Finally after exiting from the both RIOT instances by using Ctrl+C, we can stop the TAP devices as follows.

./dist/tools/tapsetup/tapsetup -d

That's all folks!

No comments:

Post a Comment