terra incognita

Set up Contiki and Cooja on Ubuntu from scratch

2015-07-18 01:26


If you want to set up your Contiki development environment on a server rather than using the Instant Contiki virtual machine, this is for you.



  1. Follow the steps in Contiki wiki page Setup Contiki toolchain in ubuntu 13.04.
  2. Instead of cloning the Contiki repo in the Step 3 mentioned above, you should upload the Contiki folder from the Instant Contiki VM to your server. This is because the repo is outdated somehow. I had the problem that the source file cannot be compiled using the source files in the repo.
  3. Now you should be able to compile example files.


You may want to simulate your application using Cooja on the server, which is useful when you need to do a batch simulation without GUI.

Do the following steps to configure Cooja simulation tools on your server.

  1. Upload all files under the contiki/tools/cooja folder from the Instant Contiki to your server.
  2. Go to cooja directory, run ant run to compile.
  3. Now navigate to cooja/dist folder, run java -jar Cooja.jar -nogui=PATH_TO_YOUR_CSC_FILE. Remember, you need a script to control the simulation. See Using Cooja Test Scripts to Automate Simulations.
  4. You should see log output in the console, which shows you the simulation is running.
  5. After completion, you can find Cooja.testlog file under the dist folder, which is the simulation log file you need.

About "Run test (repeatedly) without GUI"

As mentioned in Using Cooja Test Scripts to Automate Simulations, it does not work anymore. Therefore you need create a shell script to run your test repeated. I have done this, and you can find the shell script below:

if [ "$#" -ne 2 ]; then
    echo "Usage: $0 csc_file repeat_times"
    echo "example: $0 ~/contiki/your_file.csc 10"
cd /home/user/contiki/tools/cooja/dist

for i in `seq 1 $2`
echo ">>>>> Running $i"
java -mx512m -jar cooja.jar -nogui=$1
mv COOJA.testlog "$1.$i.log"