Saturday, November 16, 2013

Simulation of nodes on TOSSIM


I have already written a post on how to simulate a TOSSIM program on MSPSim silulator. However, the issue is that when I tried simulating MicaZ platform on it, it won't work so I thought of going back to the simulator already present in TOSSIM which I could not get to work. It kept throwing error saying "Python.h not found" and a few other python related errors. Few sites suggested to install python but I already had python on my system and yet could not get things to work.

So I began searching for a way to make it work and following are the steps which removed my error:

I am assuming that TOSSIM is already installed on your system. If not, please install it first by following the steps available on many sites. 

Open the .bashrc file by typing the following on terminal 
$ sudo gedit ~/.bashrc

Add the following line at the end of .bashrc file:
export PYTHONPATH=$TOSROOT/support/sdk/python


Close the current terminal and Open a new one and you should be able to see message like setting up TinyOS from tinyos-2.x.sh file.

Few sites said once this is done we are ready to install example application on Sensor mote. However I had to the following extra step as I still kept getting error saying 

fatal error: Python.h: No such file or directory

Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications. To install this package, enter:

$ sudo apt-get install python-dev
OR

$ apt-get install python-dev
Now we can simulate our program/application on TOSSIM.

1. Change directory to application directory and make for micaz (for TinyOS2.x, TOSSIM provide simulation of MICAz motes only).

$ cd /opt/tinyos-2.x/apps/RadioCountToLeds
$ make micaz sim


2. On successful completion it will create TOSSIM library and you will get message on console something like.

*** Successfully built micaz TOSSIM library.

3. Now open python interpreter and type following code to create a mote (node) and boot it up.

$ python
>>> from TOSSIM import *
// Imports the TOSSIM library.
>>> t = Tossim([])
// Creates a TOSSIM object.
>>> m = t.getNode(32)
// getNode will return the object represented by specific mote (ID as 32).
>>> m.bootAtTime(45654)
// node will boot at time 45654.
>>> t.runNextEvent()
// After the statement for booting. We have an event to run so this command will run that event and boot up the mote.



Hope this helps!


Picture courtesy: Google

Friday, November 8, 2013

Simulating telosb on TOSSIM

Today when I started to simulate the blink program on tossim 2.x after following a tutorial which gives description on how to write programs for tossim on Eclipse, I was stuck on the part where instructions were given to install the program on actual hardware to see the output. As I had just started with TOSSIM and didn't have a mote hardware, my hunt for a simulator for telosb started.

I have already installed Eclipse Juno and then installed Yeti2 sdk for TinyOs platform. Following are the steps on how to simulate the program on telosb using MSPSim Simulator:

MSPSim is a Java-based simulator of the MSP430 microcontroller. After dowloading the last version of MSPSIM from here, unzip it and place the folder in any location. I placed it in /opt. You can rename the folder to MSPSim for convenience. Now go to the folder /opt/MSPSim. Now mspsim can be installed by entering the command:
make
in the MSPSim folder. Now create the jar package of MSPSim with the command:
make jar
Then a mspsim.jar is created in the directory. For simplicity, you may want to create an alias to MSPSim:
alias mspsim="java -jar PATH_TO_MSPSIM/mspsim.jar"
After that, MSPSim can be lauched with the command mspsim

Simulating the Blink application:

We show in this section how to use MSPSIm on the Blink application. First we need to compile the application for the TelosB mote which uses the MSP430microcontroller with the command:
make telosb
Since MSPSim can open ELF file we have to rename the program file:
mv build/telosb/main.exe build/telosb/main.elf
Then we can run MSPSim:
java -jar /opt/MSPSim/mspsim.jar build/telosb/main.elf
Five windows of MSPSim should open, in one of then you should see a picture of the mote with the LED blinking at different frequency. In the terminal you should obtain a MSPSim prompt:
Flash got reset!
MSPSim>Autoloading script: PATH_TO_MSPSIM/scripts/autorun.sc
-----------------------------------------------
MSPSim 0.97 starting firmware: main.elf
-----------------------------------------------
MSPSim>

This is how simulation of a program on telosb can be done when you don't have the mote hardware.