A little HowTo on running TinyOS applications in the Cooja emulation / simulation environment.
- Cooja is included in the Contiki
CVSGit. Hence, make sure you have a recentcvs checkoutgit 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. - Compile your tinyos application with “make telosb”
- 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.

- Hit File –> New Simulation to configure your simulation run.

- Press create and you will see your initial setup.

- 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.


- 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.


- Play with select visualizer skins to customize the sensor visualizations. I prefer mote ids, leds, and radio traffic.

- Activate the radio logger (Plugins –> radio logger) and place all windows conveniently on the screen.

- 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.

- 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
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.
Hmmm, I have always been using the main.exe. Maybe you are not using the CVS head…
Fredrik Österlind wrote here:
http://blog.gmane.org/gmane.os.contiki.devel/month=20100501
that you had to rename the file, that’s what I had to do for it to work.
Yes, that was the case back in May. If you are using the CVS head of Contiki you do not have to this anymore. I am loading the main.exe successfully since a couple of month already.
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
The dbg statements do not work (as far as I know), but you can use the printf library (http://docs.tinyos.net/index.php/The_TinyOS_printf_Library) or normal serial communication via active messages
I have tried to run the example in:
>$TOSROOT/apps/tests/TestPrintfbut 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:telosbHas this method worked before. What could be the issue here.
Thanks.
hmm, I get to see the output in the log when I use printf.
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/TestSerialbut 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:telosbI 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….
Hi,
Thanks for your help with this.
Ive managed to find a solution to the problem from the contiki mailing list:
http://article.gmane.org/gmane.os.contiki.devel/6285/match=issue+printing+out+using+emulated+sky+mote
Dec
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
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
Great! Thanks so much!
I’ll try and I’ll let you know!!!
Cheers