Monday, December 12, 2016

How to improve the packet reception rate of your sky nodes

Objective

The objective of this tutorial is to improve the packet reception rate of your sky nodes. For this tutorial, i am going to be using sky CM5000 nodes, Contiki V3.x and Lubuntu 16.04.

Problem

In this section i am going to describe the problem that i had with the CM5000 sky nodes. When i got my CM5000 nodes, the first thing that i wanted to test was sending a unicast message from node 2 to node 1. To that end, i used an example from the rime stack named example-unicast.c located in /home/YOUR_USER/Desktop/contiki/examples/rime. This example is very straightforward since it sends unicast messages from a node to node 1. However, when you run this example you have to make sure that a node within the network has address 1. In order to set one node with address 1, you can see the following tutorial:

http://contiki-iot.blogspot.com.co/2016/06/setting-node-id-for-sky-motes.html

The unicast rime example runs fine. You can see that the messages from node 2 to node 1 arrives. However, the problem is that a huge amount of messages are lost. You may wonder why. Why a huge amount of messages are lost in a simple unicast message sent from node 2 to node 1? What is the problem with the rime unicast example?

Solution to the problem

At first i thought that the wireless channel had a lot of interference. Then, i read in the book Internet of things in 5 days (link below) that wireless channels 15, 20, 25 and 26 do not overlap with WiFi. Besides, the default wireless channel used by Contiki rime is 26, hence, there should not be any interference problems. Additionally, i used the Spectrum Analizer Application available in Contiki, (which is explained in the link below) and i realized that there were no other transmissions in channel 26. In conclusion, the problem was not interference on the wireless channel. So, what was the problem? Why a huge amount of messages were lost when using the rime unicast example?

http://wireless.ictp.it/school_2015/book/#_ieee_802_15_4_channels_and_pan_id

After discarding wireless interference, i started reading about the Contiki stack (See link below). Then, i realized that there was a layer called Radio Duty Cycling which was in charge of turning the radio on and off to save energy.

http://anrg.usc.edu/contiki/index.php/Network_Stack

The default Radio Duty Cycling used by Contiki is called ContikiMAC. To understand the ContikiMAC, please go to the following link:

https://github.com/contiki-os/contiki/wiki/Radio-duty-cycling

After reading the above link, i understood that the receivers periodically turn on their radios to inspect for messages in the channel. So, the answer to my problem was: A lot of messages are lost in the rime unicast example because the receiver node (node 1) does not poll the radio medium with the appropriate frecuency. So, i increased the polling rate and no more messages were lost. In Contiki the polling rate is referred as RDC_CHANNEL_CHECK_RATE. It is important to notice that the RDC_CHANNEL_CHECK_RATE is proportional to the energy consumption of the nodes, i.e. if the node has a higher RDC_CHANNEL_CHECK_RATE, then it will consume more energy.

Implementation of the solution

Before you implement the solution, you must be aware that it will increase the energy consumption of the nodes.

In order to implement the solution all you have to do is to increase the RDC_CHANNEL_CHECK_RATE. In order to do so, you must first create a project configuration file project-conf.h (Please do the following tutorial) :

http://contiki-iot.blogspot.com.co/2016/07/project-configuration-example.html

In the above tutorial i created a project configuration file and changed the necessary stuff to make it work. Besides, in the above tutorial, i changed the radio channel from 26 to 20. But in this tutorial i want to change the RDC_CHANNEL_CHECK_RATE. To do so, just add the following line to your project-conf.h file.

#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 128 //Change the rate at which the node check for radio activity in the channel

The above line says that the node will turn the radio on 128 times per second to check whether there is a packet in the channel. The default RDC_CHANNEL_CHECK_RATE is 8. So, increasing the check frequency to 128 ensures that no packet is lost.

Verify the solution

To verify that the changes were made do this: 1) upload the unicast rime example to a sky node, 2) connect to it via a serial port, 3) the reboot the node manually. You can do the first 2 steps with this command line:

make clean && make TARGET=sky example-unicast.upload && make login

After manually rebooting the node, you should see this:

Rime started with address 2.0
MAC 02:00:00:00:00:00:00:00 Contiki 3.0 started. Node id is set to 2.
nullsec CSMA ContikiMAC, channel check rate 128 Hz, radio channel 20
Starting 'Example unicast'

This is the message shown by the node when it is rebooted. This message shows that the RDC_CHANNEL_CHECK_RATE is equal to 128: channel check rate 128 Hz . If you see that message then your problem is solved. You must not have any lost packets.

No comments:

Post a Comment