Lesson 7: Injecting and broadcasting packets
Last updated 23 August 2003 |
This lesson discusses the use of simple Java tools to inject packets from a PC into the sensor network, as well as the use of a simple multi-hop broadcast protocol.
We first demonstrate a simple application that receives "command" packets from the radio and interprets them to perform a number of actions, such as turning the LEDs on and off. Program one mote with the apps/SimpleCmd application, and another with apps/TOSBase. Next connect the programming board to the serial port of the computer. The mote programmed with apps/TOSBase should remain on the programming board. TOSBase will act as the base station; a gateway allowing radio communication between the PC and motes programmed with SimpleCmd.
Now run the SerialForwarder as in Lesson 6 using
java net.tinyos.sf.SerialForwarder -comm serial@COM1
The Java application tools/java/net/tinyos/tools/BcastInject is used to inject a command packet into the sensor network from the PC. You can run it using
java net.tinyos.tools.BcastInject <group_id> <command>where <group_id> is the Active Message group ID you are using for your network, specified in decimal. (For example, the default group ID of 0x7d is 125 decimal.) For command you can specify a number of options, but for this lesson the SimpleCmd application understands the following:
In this part of the lesson, we extend the SimpleCmd application and cause it to forward command messages that it receives to other motes in the network. This is accomplished by re-broadcasting the command message once it has been processed. In this way we can form a simple multi-hop routing network, extending the motes' communication range.
This code is in apps/SimpleCmd/BcastM.nc. In addition to processing the command contained within each received message, it re-broadcasts the message if it has not been seen before. Note that in order to install the Bcast application you need to edit apps/SimpleCmd/Makefile and change the line
COMPONENT=SimpleCmdto
COMPONENT=Bcast
BcastM.nc
event TOS_MsgPtr ReceiveCmdMsg.receive(TOS_MsgPtr pmsg){ |
To determine whether a given command message has been seen before, the BcastM component tracks the sequence number contained in the message. If the sequence number of the current message is within 127 of the current message, the command is accepted, processed, and forwarded. Otherwise, it's dropped.
Note that the BcastInject program maintains its sequence number across invocations (saving it in a file called tools/java/bcast.properties). If you remove this file the sequence number generated by BcastInject will be reset to 1. You will need to power-cycle the motes if you do this in order for them to interpret subsequent messages as "new".
Accepting messages with a wide range of sequence numbers (rather than just the previous sequence number plus 1) allows for cases where messages are dropped by the radio stack, for example, due to corruption. This is a fairly crude mechanism, of course, and in a real application you might want to do something more involved, such as packet acknowledgments.