Some cool demos

From CoMo Robotics
Jump to: navigation, search

Back to Contiki page: Contiki

Back to Wireless Sensor networks page: Wireless Sensor Networks

Contiki contains a number of example and application demos, included in the examples and apps folders. We overview some of them in this page, all located in the examples folder.


The shell example is an application allowing to interact with a sensor node or a network of sensor nodes by means of a UNIX like command line terminal. Different instances of shells are provided:

  • example-shell: Can be compiled for the native target, but not on Tmote Sky because the size of the program is too big.
  • sky-shell: Reduced version, which can be compiled on Tmote Sky nodes. Its content is detailed below.
  • sky-shell-exec: A further reduced version, which however features the exec command allowing to load and execute ELF files.
  • sky-shell-webserver: A shell that includes the command sky-all-data, allowing to collect from a Tmote Sky different sensor measurements and network statistics. This command is used for example by the data collection demo, see below.

To install a shell on the a node, for example the sky-shell, go to the sky-shell, connect a TMote sky to your computer and upload the shell application on the node:

make TARGET=sky sky-shell.upload

You can then login to the node with the command

make login

Upon successful login, the command help gives you the list of all available commands.

  • Sensors:
    • sense: print out sensor data
    • senseconv: convert 'sense' data to human readable format
      To get the sensor readings, use
    • blink [num]: blink LEDs ([num] times)
  • File system:
    • ls: list files
    • format: format the flash-based Coffee file system.
    • write <filename>: write to file. To write a string of character to a file, use
      echo </tt>What's up</tt>| write file.1
      This write the string What's up to a file called file.1. To write straight from the command line to a file, use write file.2, write your text in the console, and finish with CTRL+RETURN.
    • read <filename> [offset] [block size]: read from a file, with the offset and the block size as options. The offset is the number of characters that must be skipped before reading the file, starting from 0. The block size options separates the output of the read functions in blocks of size block size. For example
       echo </tt>12 34 56 78</tt>|write file.3 
       read file.3 1 3 


      2 3
      4 5
      6 7
    • append <filename>: append to file
    • rm <filename>: remove the file named filename
  • System:
    • help or ?: shows the available shell commands.
    • echo <text>: print <text>.
    • size: print the size of the input
    • reboot: reboot the system.
    • binprint: print binary data in decimal format
    • hd: print binary data in hexadecimal format. The output is by word of 16 bits, with inverted bytes. If the size to be output is even, the last element is dropped. For example,


      0x6548 0x6c6c
      The last letter 'o' is dropped. To quit, type CTRL+RETURN.
    • ps: list all running processes. By default, the following processes are executed: Shell server, Shell, Contiki serial shell, Serial driver, CC2420 driver, ctimer process, Sensors, Event timer.
    • kill <command>: stop a specific command.
    • killall: stop all running commands.
    • nodeid <id>: Get the node ID if used without argument, and set the node ID to id otherwise. id is an integer. A strange thing here is that if nodeid is higher than 32767 will the the id to the corresponding signed value, ie., nodeid 32768 gives the node an ID of -32768.
    • randwait <maxtime> <command>: wait for a random time before running a command.
    • repeat <num> : run a command every time seconds.
  • Network:
    • nodes: get the list of nodes in the network (node address in xx.xx format, hop distance, and latency of communication.
    • netcmd <command>: run a command on all nodes in the network. For example
      netcmd reboot
      reboots all nodes.
    • rime-ping <node addr>: sends four PINGs message to a specific node and get a reply. The address is in the format xx.xx. PONG messages gives the RTT (with two values?), and the hop distance.
    • collect: collect data from the network
  • Additional commands, not tested (only the help provided by the shell is given below to describe them):
    • dec64: decode base64 input
    • mac <onoroff>: turn MAC protocol on (1) or off (0)
    • null: discard input
    • packetize: put data into one packet
    • rfchannel <channel>: change CC2420 radio channel (11 - 26)
    • routes: dump route list in binary format
    • send: send data to the collector node
    • sky-alldata: sensor data, power consumption, network stats
    • sniff: dump incoming packets
    • timestamp: prepend a timestamp to data
    • txpower <power>: change CC2420 transmission power (0 - 31)

The commands available for each of the four Sky shells are summarized in the table below.


Data collection

The contiki-sky-2.3 folder contains a JAVA application which provides a graphical interfaces for displaying statistics on the measurements and network topology. The network nodes are programmed with the TmoteSky shell, and the data are collected by means of a shell script which samples every 20 seconds a set of sensor measurements and network statistics. The data are retrieved at the base station and displayed by means of a Java graphical interface, see figure below. The java interface retrieved the data from all the nodes, except the one connected to the base station.


The folder contains the following files:

  • collect-data.conf: Contains some parameters for the data collection application.
  • collect-demo.jar: JAR archive containing the classes for the application. Run
    jar tvf collect-demo.jar
    to see the content of the archive. The main JAVA class is CollectServer.class, contained in the package se.sics.contiki.collect
  • collect-init.script: This file contains the set of shell commands that are transmitted to the network nodes in order to retrieve data. These are:
    echo ~K
    echo killall
    sleep 2
    echo time %TIME% | null
    sleep 2
    echo netcmd { repeat 0 20 { randwait 20 sky-alldata | blink | send } }
    sleep 2
    echo mac 0
    sleep 2
    echo collect | timestamp | blink | binprint &
    which sends to all nodes a command tasking them to report all their data at the base station every 20 seconds. Changing the delivery interval to 2 seconds allows to more quickly check that everything runs properly. Change the '20' into '2' in line 6 for doing that.
  • sky-shell.ihex: This is the shell application compiled for Tmote sky (same as in the contiki-2.3/examples/sky-shell folder).
  • lib: This folder contains two additional JAR files required by the data collection program.
  • tools: A set of tools for interacting with the nodes.

You can launch the application with

java -jar collect-demo.jar

Web server

The web server demo is located in the examples/ski-ip folder. To run this demo, you have to

  1. Install the web server application on your sensor nodes. To do so, simply compile the sky-webserver and upload it to your node:
    make sky-webserver.upload
  2. Next, create a network interface to route IP packet to the serial port. This is done by the tunslip program, which is invoked with all its necessary parameters with the make command
    sudo make linslip


    This should display the following on your console something similar to what is illustrated in the figure above. A few things to be sure this work properly:

    • The make linslip makes use of the tunslip command of tools/sky, and requires superuser privilege to run (hence the sudo). Remember the default password for Instant Contiki is user.
    • The address of your computer must be set to, as defined in the structure uip_fw_netif of the file platform/sly/contiki-sky-main.c. It is pretty annoying that such hard-coded parameters remain in Contiki, and hopefully this will be removed in future versions. If your local address is not, you can change it by running
      sudo hostname
      and then run the linslip command again.
    • The commands ifconfig and route may help you to check that everything is properly set up.
  3. You should now be able to ping the node. The node address is the one displayed by linslip as the gateway address, for example in the figure above. Open a new terminal and run
    where must be replaced with your own gateway address.
  4. If the ping command works properly, open a browser windows and enter this same address. This should open a page, where access to the sensor measurements can for example be displayed, as in the figure below



The Energest demo is located in the examples/energest folder, and was presented at Sensys 2007 and displays the energy consumption of the nodes. The energy consumption is split in Low Power Mode (LPM), CPU, Radio Listen and Radio Transmit, cf. figure below. The energy can be displayed for up to seven nodes, numbered from 42 from 48.


A README file is provided in the energest folder. Before performing the different steps given in the README file, you however have to compile the application by simply running the make command. This should create a folder contiki-energest-demo. Go in this folder and then you can follow the instructions in the README file.

The application runs without problem under the Instant Contiki Linux, although it seems that the following modifications must be brought to the Makefile in the contiki-energest-demo folder:

  • Change CONTIKI=. to CONTIKI=../../..
  • Change -include tools/sky/Makefile to include $(CONTIKI)/platform/sky/
  • Change java -jar energest.jar /dev/com${firstword $(CMOTES)} to java -jar energest.jar ${firstword $(CMOTES)}

The next step consists in programming one node as the base station, and the other nodes with the energest code. Follow the steps in the README file for this. To launch the application, simply run

make rundemo

Once the application is launched, you can click on the total power chart to change the node, or click anywhere else on the screen to toggle the colors used for displaying the different energy usages. The type of program run by the sensor node can be changed by pushing the user button. The lights indicate which type of program runs:

  • Red LED: sending one packet per second
  • Green LED: radio listen 1% duty cycle
  • Green, red LEDs: radio listen 10% duty cycle
  • Blue LED: radio listen 100%
  • Blue, red LEDs: radio listen 10%, CPU low-power mode disabled
  • Blue, green LEDs: sending data 1.2 kilobytes/second
  • Blue, green, red LEDs: sending data 12 kilobytes/second

The code for the java application is in the folder src, and the main code running on the node is in energest-demo.c.