Using SerialForwarder Interface of TinyOS with Avrora

Dear reader,
Special thanks for the feedback and comments. Please continue supporting this small effort of mine to tinyos community.
As I promised in last post, here is the first step to analyze the RSSI values from a mote. In order to understand concept of base station and how things are done in real world, the following tutorial may help you.
As usual, sample code is provided at the end

Assumptions:
1) You have done up to the previous post, radio communication using cthreads. If not, please have a look at it. We are using the same program here for further analysis with a base station.
2) The username is "test"
3) You have eclipse installed and running.
4) You know how to add CLASSPATH for custom jar library

Before we begin, a small note on base station. Base station in real time can be a sophisticated node with high transmission range or a normal mote connected to computer. In either way, it act as a sink for data collection. That means, every application you develop using WSN needs to run the base station.

With this, here we begin.
Part 1: Making program ready for SerialForwarder
  1. Copy the folder BaseStation from /opt/tinyos-2.1.0/apps to /home/test/Serial
  2. Take shell and navigate to ~/Serial
  3. Compile the program. "make mica2"
  4. Convert the main program to avrora compatible format convert-avrora build/mica2/main.exe base.od
  5. Move the base.od to parent folder. mv base.od ../
  6. Copy the sender.od from previous example to Serial folder
  7. Instead of our previous post step, command for avrora is different here. " avrora -simulation=sensor-network -seconds=160.0 -monitors=serial,real-time -platform=mica2 -nodecount=1,1 base.od sender.od"
  8. This will give a display "Waiting for serial connection on port 2390..."
If everything is fine, the O/P will be similar to the following


Part 2: Opening a new project in Eclipse and adding TinyOS library
  1. Open a new java project in Eclipse
  2. Copy the following code

Running Program
  1. Add java library path for suport for TinyOS serialforwarder
  2. Compile.
  3. Run the serialforwarder
  4. Modify the entry in serialforwarder to "network@localhost:2390"
  5. Start Server
  6. Now the counter will be running for "packets received"
  7. With out closing the serialforwarder, go back to eclipse and run the Listen
  8. Observe the output.

For those who are done with this.
Please have a look at Octopus project
If you are able to run the code from Octopus in avrora, it's a good sign!!!
Cheers

Download java code
Links you may be interested in
  1. Radio Communication using cthreads(tosthreads library)
  2. Running cthreads (tosthreads) program in Avrora
  3. BlinkToRadio in Avrora
  4. Running TinyOS programs using Avrora

23 comments:

swaroopa said...

hi sir..
I was trying to write an application to broadcast simulated sensor input data using the -sensor-data option in avrora..i have been unable to figure out how to do it,also how to interpret the hexadecimal data output by avrora during simulation of the radio.

Thank you in advance..

Gireesh said...

Hi Swaroopa
Please let me know which program u r running!!!
If you can send me the code, then I can tell in detail!!!

Anonymous said...

Because I am not familiar with eclipse,so I can't follow your example,especially your select 'java application',I don't how to do.

Gireesh said...

hmm.........
To use serialforwarder, you need to know java. And eclipse is open source s/w most popular in working with java. That's why I have written that in assumptions. Sorry that I can't help teaching you with using eclipse. There are so many sites available to do that.

kuldeep said...

I am getting following error ,when trying to run serial forwarder code.
Plz help me


Locking assertion failure. Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0xb1d93767]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_unlock+0x31) [0xb1d938b1]
#2 /usr/lib/libX11.so.6(_XReply+0xfd) [0xb1dd51bd]
#3 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so [0xb1ec1dce]
#4 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so [0xb1eabd77]
#5 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so [0xb1eabef3]
#6 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so(Java_sun_awt_X11GraphicsEnvironment_initDisplay+0x26) [0xb1eac136]
#7 [0xb264fbfa]
#8 [0xb2649b3b]
#9 [0xb2649b3b]
#10 [0xb2647219]
#11 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb77ee2ec]
#12 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb7902f08]
#13 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb77ee11f]
#14 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so(JVM_DoPrivileged+0x32d) [0xb784bbcd]
#15 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/libjava.so(Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2+0x3d) [0xb75e630d]
#16 [0xb264f4ab]
#17 [0xb2649a64]
#18 [0xb2647219]
#19 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb77ee2ec]
Locking assertion failure. Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0xb1d93767]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_lock+0x2e) [0xb1d9381e]
#2 /usr/lib/libX11.so.6 [0xb1dd4518]
#3 /usr/lib/libX11.so.6(XGetVisualInfo+0x26) [0xb1dcb0a6]
#4 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so [0xb1eab0b9]
#5 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so [0xb1eab303]
#6 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so [0xb1eabfa1]
#7 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/xawt/libmawt.so(Java_sun_awt_X11GraphicsEnvironment_initDisplay+0x26) [0xb1eac136]
#8 [0xb264fbfa]
#9 [0xb2649b3b]
#10 [0xb2649b3b]
#11 [0xb2647219]
#12 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb77ee2ec]
#13 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb7902f08]
#14 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so [0xb77ee11f]
#15 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/client/libjvm.so(JVM_DoPrivileged+0x32d) [0xb784bbcd]
#16 /usr/lib/jvm/java-1.5.0-sun-1.5.0.16/jre/lib/i386/libjava.so(Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedAction_2+0x3d) [0xb75e630d]
#17 [0xb264f4ab]
#18 [0xb2649a64]
#19 [0xb2647219]
The toscomm JNI library was not found.
Check that your tinyos-tools package is installed and try
rerunning tos-install-jni.
Aborting.

kuldeep said...

I have solved my last problem.......but now it shows the window TinyOS serial forwarder with blank look (nothing except title),is this the problem with eclipse or our codes.

Gireesh said...

@kuldeep
it takes some time 2 figure out what is happening
Windows, change needed is in /dev/ttyUSB0 to some com port which is similar to windows tinyos tutorials

Kuldeep Yadav said...

hi
thanks Gireesh for your previous reply.I have finished with this application and want to try my hand with Octopus.But i am not sure whether it can be used with Avrora,or it is meant for only real motes.

Gireesh said...

@kuldeep
i was bit bsy,almost forgot 2 reply for the query
http://www.csi.ucd.ie/files/Octopusv_1_4_2.zip
is what i used, and loaded the program in Avrora

sneha said...

hi gireesh sir... ur detailed blog has helped our project reach till this point; lukin eagerly... further

pravaal said...
This comment has been removed by the author.
marianna said...
This comment has been removed by the author.
marianna said...

I am getting following error ,when trying to run serial forwarder code.
Plz help me

The toscomm JNI library was not found.
Check that your tinyos-tools package is installed and try
rerunning tos-install-jni.
Aborting.

Gireesh said...

@mariyana
if it is linux, you may please run sudo tos-install jni
if an error comes, pl post it here

marianna said...

Hi Gireesh

I am getting following error:

Error on sf@localhost:9002: java.net.ConnectException: Connection refused

Thank you for reply!

Gireesh said...
This comment has been removed by the author.
Gireesh said...

@mariyana
u may pl try
java net.tinyos.sf.SerialForwarder

and in that window u see serial@com...
replace it with network@localhost:2390
(step 2)

marianna said...

Gireesh,

thanks a lot, now everythinhg is ok
=D

One question, for to run the SerialFowarder code, I always need to do java net.tinyos.sf.SerialForwarder?
I can't run it from eclipse?

Gireesh said...

@mariana
you may run sf also from eclipse :D

marianna said...

Hi Gireesh,

About the Octopus, I'm trying to run it, but I get the following error? Can you help me?
:)


marianna@marianna-laptop:/opt/tinyos-2.1.1/apps/OctopusDashboard/motes$ make mica2
mkdir -p build/mica2
compiling OctopusAppC to a mica2 binary
ncc -o build/mica2/main.exe -Os -DENERGY_MONITORING=0 -fnesc-separator=__ -Wall -Wshadow -Wnesc-all -target=mica2 -fnesc-cfile=build/mica2/app.c -board=micasb -DDEFINED_TOS_AM_GROUP=0x22 --param max-inline-insns-single=100000 -I/opt/tinyos-2.1.1/tos/lib/net/ -I/opt/tinyos-2.1.1/tos/lib/net/ctp -I/opt/tinyos-2.1.1/tos/lib/net/le -I/opt/tinyos-2.1.1/tos/lib/net/drip -I. -DIDENT_APPNAME=\"OctopusAppC\" -DIDENT_USERNAME=\"marianna\" -DIDENT_HOSTNAME=\"marianna-laptop\" -DIDENT_USERHASH=0x39f52601L -DIDENT_TIMESTAMP=0x4cdc86e8L -DIDENT_UIDHASH=0x3d2ca160L -fnesc-dump=wiring -fnesc-dump='interfaces(!abstract())' -fnesc-dump='referenced(interfacedefs, components)' -fnesc-dumpfile=build/mica2/wiring-check.xml OctopusAppC.nc -lm
In file included from OctopusAppC.nc:41:
In component `OctopusC':
OctopusC.nc:61: interface CC2420Config not found
In file included from OctopusAppC.nc:41:
OctopusC.nc: In function `TimerChannel.fired':
OctopusC.nc:252: interface has no command or event named `setChannel'
OctopusC.nc:253: interface has no command or event named `sync'
OctopusC.nc: At top level:
OctopusC.nc:258: `syncDone' is not in interface `ChannelControl'
OctopusC.nc: In function `setLocalDutyCycle':
OctopusC.nc:902: interface has no command or event named `setLocalDutyCycle'
OctopusC.nc:904: interface has no command or event named `setLocalDutyCycle'
OctopusAppC.nc:80:2: error: #error "No SENSORS defined for this platform"
In component `OctopusAppC':
OctopusAppC.nc: At top level:
OctopusAppC.nc:132: component CC2420ControlP not found
OctopusAppC.nc:133: no match
make: ** [exe0] Erro 1

Gireesh said...

hi mariyana
pl see the installation manual of octopus. You need to modify tinyos installation to get it working

AndrewB said...

There aren't a lot of resources out there for Avrora users, and your site has been very helpful. Thanks!

Adeel Javed said...

hi Gireesh sir,

My question is that, can we specify node id. like for oscilloscope example, if i want to give basestation id=0 and rest of motes from 1 to 9. can we do this? and how to do this in simulation?