Example Application: Deluge

  1. Node Configuration
  2. Code Generation
  3. Updating Makefile
  4. Build
  5. Run

Deluge provides an efficient method for disseminating large data objects, such as program binaries, to many nodes within a wireless sensor network. Combining this mechanism with a bootloader and command dissemination allows for the wireless programming of nodes. The following features are included with Deluge:

Multihop support: Wirelessly program all nodes in a multihop network without touching your nodes.
Epidemic propagation: Continuous propagation effort by all nodes helps ensure reachability of those nodes with intermittent connectivity.
Redundant data integrity checks: Overlapping CRC calculations to help ensure integrity of program images at all nodes.
Store multiple program images: With each node storing multiple program images, quickly switch your network between different programs without continuous downloading.
Golden image: A program image with minimal support for network programming stored in a safe location on external  flash. Always have a piece of code that will allow for recovery.
Isolated bootloader: A piece of code that is guaranteed to execute after each reset independent of the TinyOS application. The bootloader is responsible for programming the microcontroller and recovers from programming errors by loading the Golden Image.


  1. Node Configuration

#include "gen/cBlinkDeluge_TinyOSModule.h"
#include "gen/cBlinkDeluge_Main.h"

   cBlinkDeluge_Main *m = new cBlinkDeluge_Main(this,main,"Main",getIndex());
  1. Code Generation

NesCT is going to build all the classes in gen directory. Replace "cp" with "copy" and slash (/) with backslash (\) for windows operating system at the following instructions. You may use deluge_nesct.bat and deluge_nesct.sh instead of typing the following.

[root@sinan tictoc]# cd components/
[root@sinan components]# cp BlinkDeluge.nc ../Application.nc
[root@sinan components]# cd ..
[root@sinan tictoc]# ./nesct.exe -DDEFAULT_EEPROM_SIZE=0x100000 -DTOSH_DATA_LENGTH=40 Application.nc


  1. Updating Makefile

Type makemake.bat/makemake.sh to create new Makefile for Win32/Linux.
  1. Build

Type "make" to build the binary.

[root@sinan tictoc]# make
g++ -c -g -fpermissive -fPIC -DWITH_NETBUILDER -w -DTOSNODES=1000 -DLINUX -DPLATFORM_OMNETPP -I./include -I/root/projects/tinyos-1.x/tos/interfaces -I./include_tos -I/opt/omnetpp-3.2/include simstart.cc
g++ tictoc1_n.o debug.o simstart.o tinyos.o tinyosmain.o tossim.o txc1.o -g -L/opt/omnetpp-3.2/lib -lenvir -lcmdenv -lsim_std -lnedxml -lxml2 -ldl -lstdc++ -lpthread -o tictoc

  1. Run

Edit omnetpp.ini file and change wait-for-sf to true. After enabling this option, the simulation will wait 10 seconds before starting to allow sf to connect.

Start SerialForwarder by running ./bin/sf_sim . For windows, you may need to enter the contents of the file yourself in a console windows (cygwin). The exceptions will be lost once we start the simulator.

[root@sinan tictoc]# ./bin/sf_sim
Listening to tossim-serial
SF enabled, 0 clients, 0 packets read, 0 packets written getenv JNI library not found. Env.getenv will not work
(please consult installation directions in
Platform avrmote
Opening tossim-serial source
Connecting to Tossim event port at localhost:10585
Listening for client connections on port 9001
SF enabled, 0 clients, 0 packets read, 0 packets written java.net.ConnectException: Connection refused

To complicate things, let's use four nodes in a line as topology file in ned directory.

[root@sinan tictoc]# cd ned
[root@sinan ned]# cp line.ned ../bin/tictoc1.ned

Set DBG environment to usr3. Type "set DBG=usr3" for windows. Run tictoc

[root@sinan tictoc]#export DBG=usr3

[root@sinan tictoc]#tictoc

You may want to set simulation speed to fast or express mode for this simulation. There are a lot of message exchanges occuring and displaying each of them may cause timeouts at the client side application. Press fast or express from the GUI.

Start the client side sensor node binary file injection utility by running "sh ./bin/deluge_inject.sh" or "bin/deluge_inject.bat" from some other command line window. This application is first going to contact (ping) node 0, compare existing image files against the one that's being injected and ask for confirmation. If you answer yes, the image is going to be disseminated to all nodes in the network.  You can see the progress of by increasing page number.

sh ./bin/deluge_inject.sh
getenv JNI library not found. Env.getenv will not work
(please consult installation directions in
Pinging node ...
Connected to Deluge node.
Ihex read complete:
Total bytes = 23768
Sections = 1
Replace empty image with:
Image: 1
Prog Name: DelugeBasic
Compiled On: Tue Aug 01 19:15:13 EEST 2006
Platform: mica2
User ID: sinan
Hostname: sicomp
User Hash: 0x797a923d
Continue operation? (y/[n]) y
Injecting page [15] of [22] ...

From simulation screen, you should see an output similar to this:

[0] 24:26:28.28222650: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:15)
[0] 24:26:29.61503900: DELUGE: Received REQ_MSG(dest=0,vNum=0,imgNum=1,pgNum=14,pkts=ff)
[1] 24:26:29.80781250: DELUGE: WRITE_DONE Page transfer complete
[1] 24:26:29.80781250: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:15)
[1] 24:26:30.54414050: DELUGE: Received REQ_MSG(dest=1,vNum=0,imgNum=1,pgNum=14,pkts=ff)
[2] 24:26:30.73691400: DELUGE: WRITE_DONE Page transfer complete
[2] 24:26:30.73691400: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:15)
[2] 24:26:31.38144525: DELUGE: Received REQ_MSG(dest=2,vNum=0,imgNum=1,pgNum=14,pkts=ff)
[3] 24:26:31.57421875: DELUGE: WRITE_DONE Page transfer complete
[3] 24:26:31.57421875: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:15)
[0] 32:16:39.22070300: DELUGE: WRITE_DONE Page transfer complete
[0] 32:16:39.22070300: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:16)
[0] 32:16:40.60917950: DELUGE: Received REQ_MSG(dest=0,vNum=0,imgNum=1,pgNum=15,pkts=ff)
[1] 32:16:40.80292950: DELUGE: WRITE_DONE Page transfer complete
[1] 32:16:40.80292950: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:16)
[1] 32:16:41.40156250: DELUGE: Received REQ_MSG(dest=1,vNum=0,imgNum=1,pgNum=15,pkts=ff)
[2] 32:16:41.59531250: DELUGE: WRITE_DONE Page transfer complete
[2] 32:16:41.59531250: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:16)
[2] 32:16:42.30917950: DELUGE: Received REQ_MSG(dest=2,vNum=0,imgNum=1,pgNum=15,pkts=ff)
[3] 32:16:42.50292950: DELUGE: WRITE_DONE Page transfer complete
[3] 32:16:42.50292950: DELUGE PageTransfer: setWorkingPage(imgNum:1,pgNum:16)

Note that, after the file images are disseminated, you cannot send the same image again. NesCT preserves flash file contents in the logger directory. Remove the contents of this folder, then you have a fresh installation.



This project has been supported by Featherlight project at University of Twente, the Netherlands and European Embedded WiseNt project at Yeditepe University.