Assignment 3: Developing a multihop data collection protocol
In this assignment, we will develop a multihop data collection protocol. The main idea of the protocol is to employ a simple spanning tree for routing. The root of the spanning tree is the base station. When the base station receives a message, it forwards it to its serial port (TOS_UART_ADDR.), allowing the host PC to receive the data.
Basic requirements:
A spanning tree should be built before transmitting the sensor readings to the base station. The protocol should avoid routing loops. That is, every node should select a node as its parent node and only send its sensor readings to this parent node.
Nodes should sample and transmit their light sensor readings once every 10 seconds.
Reliable communications can be assumed, that is, acknowledgement and retransmission may be ignored. However, you will obtain extra credits if you implement them.
Only the parent node of a node forwards messages to the base station. Nodes should not flood or transmit multiple copies of messages. So, you should not use the TOS_BCAST_ADDR broadcast function for transmission.
All nodes should filter the messages whose destination address is not itself (TOS_LOCAL_ADDRESS), or is not the broadcast address TOS_BCAST_ADDR, or does not belong to its TOS_AM_GROUP.
This protocol is for static wireless sensor networks.
In order to decrease the transmission range of a mote, you should set the following line in your Makefile. Include the Makerules file before it:
CFLAGS+=-DCC2420_DEF_RFPOWER=0x1
The transmission range will be reduced to 8+/-4 inch (or 20+/-10 CM). You should distribute the nodes far enough away from each other to make sure data has to be relayed for multiple hops to reach the base station.
In addition to the TinyOS software itself, you should write a java program to display the current state of the network. This program should be written in Java and receive data from the base station using the TinyOS net.tinyos.message library (documented in the TinyOS tutorial).
You will need the mig tool to generate a Java classfile for the message type that you use (Here is an example: MultihopMsg):
mig java -java-classname=MultihopMsg -I$TOSDIR/lib/CC2420Radio/ MultihopMsg.h MultihopMsg > MultihopMsg.java
To receive and parse the messages, write a piece of Java code similar to the following:
import
net.tinyos.util.*;
import
net.tinyos.message.*;
import java.io.*;
import java.util.*;
public class
readmultihop implements MessageListener {
MoteIF mote;
public readmultihop() {try {
System.out.println( "Connecting to mote ..." );
mote = new MoteIF( (net.tinyos.util.Messenger)null );
} catch( Exception e ) {
System.out.println("Could not connect to mote");
System.exit(-1);
}
mote.registerListener( new MultihopMsg(), this );
while(true) { }}
public void messageReceived(int dstaddr, Message msg) {if (msg instanceof MultihopMsg) {
// add your code here.
}}
Your Java program should periodically display a table showing the current network state every 20 seconds, with each row representing one node in the network. The table should have the following columns:
Node ID
Sequence number
Number of hops
Current light sensor value from data source
Data source ID
Percentage of lost packets from data source
You can simply output this table in a text format to stdout.
To test your Java program, first run SerialForwarder to forward data from the serial port to a TCP socket:
change your current directory to /tinyos-1.x/tools/java
export MOTECOM=serial@COM6:telos
java net.tinyos.sf.SerialForwarder -comm serial@COM6:telos
The GUI will be loaded and show the number of packets received by the SerialForwarder program. If no packets are getting through, you can run the Listen program to look at the data coming over the serial port (killing SerialForwarder first):
java net.tinyos.tools.Listen
Once you are getting data into the SerialForwarder, fire up your Java program, which connects to the serial forwarder and receives the messages.