TinyOS and Cooja

A little HowTo on running TinyOS applications in the Cooja emulation / simulation environment.

  1. Cooja is included in the Contiki CVS Git. Hence, make sure you have a recent cvs checkout git clone / checkout / branch /… of Contiki on your system. See http://www.sics.se/contiki/download.html for installation instructions.
    2011-03-27: update: contiki is now on Git.
  2. Compile your tinyos application with “make telosb”
  3. In your Contiki installation, go to tools/cooja/ and run “ant”. This requires you to have java and ant installed. After compilation it will greet you with an empty simulation environment.
    cooja1
  4. Hit File –> New Simulation to configure your simulation run.
    cooja2
  5. Press create and you will see your initial setup.
    cooja3
  6. Now it is time to add some sensor nodes. Hit mote types –> create mote type –> sky mote type and select the image (main.exe) of your tinyos application by hitting browse.
    cooja4
    cooja5
  7. Hit open and create and next specify the number of sensor nodes you need with that application image. You can add other application by repeating the steps 6 and 7. Hit create and add to make the sensor nodes appear.
    cooja6cooja7
  8. Play with select visualizer skins to customize the sensor visualizations. I prefer mote ids, leds, and radio traffic.
    cooja8
  9. Activate the radio logger (Plugins –> radio logger) and place all windows conveniently on the screen.
    cooja9
  10. Press start to see the action. Check the timeline to see packets sent and received and also the Leds. Check the loggers to see radio packets and serial communication.
    cooja10
  11. Cooja has many other features such as serial sockets, debugging, etc. I will leave it to you to explore them. Please keep in mind that some functionality in Cooja is specific for Contiki and will not work (or only partially) with TinyOS.
Advertisement

19 thoughts on “TinyOS and Cooja

  1. For others reading this tutorial: you may have to rename the main.exe to main.sky for the create mote function to work.

    The “log printf” function and “variable viewer” are also very useful.

  2. Very helpful. One question. When I am using TOSSIM to simulate a network, I use debug statements:
    dbg("Channel", "Debug Statement");
    to print out….. well, debug statements. You can then add a channel in the TOSSIM script to monitor and print the statements from that channel. Is there a way to add a channel for monitoring in cooja. Is there some other mechanism for printing debug statements in cooja.
    Thnaks

      • I have tried to run the example in:
        >$TOSROOT/apps/tests/TestPrintf
        but this does not seem to produce an output on the “log listener” or the serial port on the node in Cooja.
        note: “log output: printf()’s” in “Select visualizer skins” in “Simulator Visualizer” pane is selected.

        The same binary prints output to serial when used on a physical mote and using:
        java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSB0:telosb

        Has this method worked before. What could be the issue here.

        Thanks.

      • I will try the active message approach but this is not ideal for my use. Will let you know how I get on.

      • Using the example to test serial in:
        >$TOSROOT/apps/tests/TestSerial
        but to no avail. Still no output is recorded on “log listener” or the serial port on the node in Cooja.

        Again using on a physical node and using:
        java net.tinyos.tools.Listener -comm serial@/dev/ttyUSB0:telosb
        I see the expected results.

        Any idea what is wrong here. Is it possible I have some incorrect settings set in the Cooja environment.

        Thanks

      • Yes, this is right. It will not show a readable output in the log, instead you have to use the TinyOS tools directly by connecting to the serial port of Cooja. I can put up a little howto, but it might take some time. Make sure you use a recent CVS checkout (not older than a couple of weeks).

      • Ah I see, thanks for this.
        I have updated to the head of the cvs, however I am still unable to log printf statements.

      • Hmm, do not know. I used it about two weeks ago and it was fine. Let me check on it in the next days….

  3. Hi,

    I tired renaming the main.exe to main.sky and hit compile. Later if i click Create&Add, it is not going through.

    Please advice how to make tinyos code work in cooja?

    Thanks,
    Ganesh

    • Hi,

      hmm, I never rename the main.exe to main.sky. If you check the tutorial below, you will see that I open the main.exe (point 6, second pic). If you have a recent git checkout of cooja (or contiki) there should not be any problems. Try with a simple apps like Blink and later RadioCounttToLeds first.

      Best wishes,
      Olaf

  4. Hi Everyone,
    I like so much this HowTo.
    About TinyOS on COOJA I have a question:
    I would like to simulate a WSN I implemented for TelosB motes. The problem is that my network includes a Base Station connected to a PC which sends messages to the network. Is it possible to implement this behaviour on COOJA?

    Thanks a lot,
    Antonio

    • Sure, just create one node with the base station binary and connect the serial port of it to a socket (right click on the node and then select server socket). Use “-comm network…” in your TinyOS java tools to connect to it, see their documentation for details

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s