Monday, July 11, 2016

How to set up the Contiki OS communication stack

Objective

Set up the Contiki OS communication stack. For detailed information about the Contiki communication stack, please visit the following web page.

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

This post will explain how to set up the network, MAC, RDC (Radio Duty Cicle), framer and radio layer of your sensor node in Contiki OS 3.0. I used a CM5000 node and Ubuntu 16.04 to test this example. Besides, i used a RIME example named example-broadcast.c

Step 1: Create a project-conf.h archive

Go to your project folder, in this case /home/YOURUSER/Desktop/contiki-3.0/examples/rime, and create an archive called project-conf.h with the following content:


#define NETSTACK_CONF_NETWORK rime_driver // Define the network driver to use
#define NETSTACK_CONF_MAC     csma_driver // Define the MAC driver to use
#define NETSTACK_CONF_RDC     contikimac_driver // Define the RDC driver to use
#define NETSTACK_CONF_FRAMER  framer_802154 // Define the framer driver to use
#define NETSTACK_CONF_RADIO   cc2420_driver // Define the radio driver to use

The lines define the network driver, the MAC driver, the RDC driver, the framer driver and the radio driver respectively.

Step 2: Modify the Makefile

In order to include the previously defined project-conf.h archive within contiki you must tell contiki that it exists. To that end, you must include the following line in the Makefile CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\". Remember that the makefile is located in /home/YOURUSER/Desktop/contiki-3.0/examples/rime.Then, your Makefile must look like this:

CONTIKI = ../..

all: example-abc example-mesh example-collect example-trickle example-polite \
     example-rudolph1 example-rudolph2 example-rucb \
     example-runicast example-unicast example-neighbors

CONTIKI_WITH_RIME = 1
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
include $(CONTIKI)/Makefile.include

Step 3: Modify the contiki-conf.h of your platform

Next, you will need to modify the contiki-conf.h archive of your platform. In this case i am using a CM5000 sky node. Then, i must go to the folder /home/YOURUSER/Desktop/contiki-3.0/platform/sky, open the archive contiki-conf.h, and cut the following code located at the end of the file:


/* include the project config */
/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */

Then, you must copy that code at the beginning of the archive. Finally, you contiki-conf.h archive would look like this:


/* -*- C -*- */

#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H

/* include the project config */
/* PROJECT_CONF_H might be defined in the project Makefile */
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */

Step 4: Compile the example

Finally, you must clean and compile the example example-broadcast.c using the following commands:

make TARGET=sky clean && make TARGET=sky example-broadcast

Then, you must reset manually the node and then login with the following command.

make login

You will see in terminal the selected communication stack, for example, in the below code you can see that i selected Rime in the network layer, CSMA in the MAC layer and ContikiMAC in the RDC layer.

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 8 Hz, radio channel 26
Starting 'Example unicast' 'Reads the Sensors Information'

No comments:

Post a Comment