-
Notifications
You must be signed in to change notification settings - Fork 56
Generic wiselib application tinyos
##Basic Requirements
Before compiling your first application, the appropriate paths must be set. Therefore the file
wiselib/applications/Makefile.template
must be copied to
wiselib/applications/Makefile.local
and the paths for the platforms to be used for compilation must be adapted.
Without an existing Makefile.local
(see above), it is not possible to compile any application in the applications
folder!
Once this is done, change to
wiselib/applications/example_app
For the Tinyos integration, the corresponding [Installing TinyOs] (http://docs.tinyos.net/index.php/Installing_TinyOS_2.1.1) documentation should be used. On my Debian system, I did the following:
- Installed
nesc
andtinyos-tools
from the given repository (e.g.,deb http://tinyos.stanford.edu/tinyos/dists/ubuntu <distribution> main
) viaapt-get
- Downloaded TinyOs 2.1.1(converted it with
alien --to-tgz ...
to tar archive) - Generated
tinyos.sh
, whereTOSROOT, TOSDIR, CLASSPATH, MAKERULES
were exported. Addedtinyos.sh
to~/.bashrc
. - Downloaded and compiled both
mspgcc4
andavr-gcc
separately, since C++-support is needed - see Compiler Setup for details
Before working with Tinyos on real nodes, we are going to let a Wiselib application run in [TOSSIM] (http://docs.tinyos.net/index.php/TOSSIM) (we assume that you are currently in directory wiselib/applications/example_app
). Run
make tinyos-tossim
to generate the required _TOSSIMmodule.so
. The output should look as follows:
make -f /home/tbaum/develop/wiselib.svn//applications/Makefile.tinyos.tossim micaz sim tinyos-tossim
[...]
g++ -shared -fPIC -DTINYOS -DOSMODEL=TinyOsModel -DTINYOS_TOSSIM -I. -I/home/tbaum/develop/wiselib.svn//wiselib.stable -I/home/tbaum/develop/wiselib.svn//wiselib.testing \
-o out/tinyos_timer.so -c /home/tbaum/develop/wiselib.svn//wiselib.stable/external_interface/tinyos/tinyos_timer.cpp
[...]
compiling /home/tbaum/develop/wiselib.svn//wiselib.stable/external_interface/tinyos/TinyosWiselibGlueAppC to object file sim.o
ncc -c -shared -fPIC -o simbuild/micaz/sim.o -g -O0 - I/home/tbaum/develop/wiselib.svn//wiselib.stable/external_interface/tinyos/ -DTINYOS_TOSSIM -tossim -fnesc-nido-tosnodes=1000 -fnesc-simulate -fnesc-nido-motenumber=sim_node\(\) -fnesc-gcc=gcc -Wall -Wshadow -Wnesc-all -target=micaz -fnesc-cfile=simbuild/micaz/app.c -board=micasb -DDEFINED_TOS_AM_GROUP=0x22 --param max-inline-insns-single=100000 -I/home/tbaum/develop/sensor-os/tinyos/tinyos-2.1.1/tos/lib/printf -DIDENT_APPNAME=\"/home/tbaum/dev\" -DIDENT_USERNAME=\"tbaum\" -DIDENT_HOSTNAME=\"bical\" -DIDENT_USERHASH=0x6ed7351fL -DIDENT_TIMESTAMP=0x4d583d58L -DIDENT_UIDHASH=0x7e300f73L -Wno-nesc-data-race /home/tbaum/develop/wiselib.svn//wiselib.stable/external_interface/tinyos/TinyosWiselibGlueAppC.nc -fnesc-dump=components -fnesc-dump=variables -fnesc-dump=constants -fnesc-dump=typedefs -fnesc-dump=interfacedefs -fnesc-dump=tags -fnesc-dumpfile=app.xml
compiling Python support and C libraries into pytossim.o, tossim.o, and c-support.o
[...]
show sizes...
size _TOSSIMmodule.so
text data bss dec hex filename
261311 6540 575304 843155 cdd93 _TOSSIMmodule.so
_TOSSIMmodule.so
is successfully generated and already contains the example_app
application. Now, TOSSIM can be started to run the application. For simplicity reasons, we already provide a start script that runs a network with 10 nodes. The script is located in wiselib.stable/external_interface/tinyos/tossim
. From the current directory, just run
../../wiselib.stable/external_interface/tinyos/tossim/start-tossim.py
and you should get an output as follows:
Preparing simulation.
Booting 0 at time 27235055722
Booting 1 at time 74506531273
Booting 2 at time 25220777639
Booting 3 at time 90746688971
Booting 4 at time 48789724912
Booting 5 at time 13240591781
Booting 6 at time 24350460061
Booting 7 at time 64820497627
Booting 8 at time 74987932607
Booting 9 at time 77594729803
Starting simulation.
DEBUG (5): Hello World from Example Application!
DEBUG (5): Node 5: Application booted at 0:0:1.324059178.
DEBUG (6): Hello World from Example Application!
DEBUG (6): Node 6: Application booted at 0:0:2.435046006.
[...]
DEBUG (2): received msg at 2 from 3
DEBUG (2): message is hello world!
DEBUG (4): received msg at 4 from 3
DEBUG (4): message is hello world!
Completed simulation.
After having the application run successfully in TOSSIM, we are going to test it on hardware. We will use one TelosB and a MicaZ that will send a message from one to the other. First, we need to compile the application for the TelosB, and run
make clean tinyos-telosb
The last lines of the output should look as follows:
[...]
show sizes...
msp430-size build/telosb/main.exe
text data bss dec hex filename
18636 48 988 19672 4cd8 build/telosb/main.exe
Now, the application can be brought to the node (here, it is connected to /dev/ttyUSB0
). In addition, we want to change the node id to 14. We therefore run the following command:
make tinyos-nodeid-telosb flash-sky PORT=/dev/ttyUSB0 TOS_NODE_ID=14
The make target tinyos-nodeid-telosb
changes the id in the image to the value of TOS_NODE_ID - if not given, default is 1. The make target flash-sky
brings the hex file to the node, whereby the port can be given via PORT (with /dev/ttyUSB0
as default).
Next, we compile the application for MicaZ:
make clean tinyos-micaz
The last lines of the output should look as follows:
[...]
show sizes...
avr-size build/micaz/main.exe
text data bss dec hex filename
20376 218 935 21529 5419 build/micaz/main.exe
Next, the application can be brought to the node (here, it is connected to /dev/ttyUSB1
). In addition, we want to change the node id to 44. We therefore run the following command:
make tinyos-nodeid-micaz flash-micaz PORT=/dev/ttyUSB1 TOS_NODE_ID=44
Finally, we want to see the debug output of the nodes. The current implementation uses the TinyOs Printf Library, so we start two instances of the corresponding Java PrintfClient (the TelosB is at /dev/ttyUSB0
, the MicaZ's UART is at /dev/ttyUSB2
):
java net/tinyos/tools/PrintfClient -comm serial@/dev/ttyUSB0:telosb
java net/tinyos/tools/PrintfClient -comm serial@/dev/ttyUSB2:micaz
When starting the TelosB, it prints the following output:
Hello World from Example Application!
Node 14: Application booted.
broadcast message at 14
And on the MicaZ output, we see
received msg at 44 from 14
message is hello world!