CIS 700 Project: Group-Based Programming using Tiny OS

Louise Avila
December 22, 2006

This project is a TinyOS 2.x. application that implements group based programming expressions using NesC. A client application running on a PC sends messages to motes to form groups and report back readings from the member nodes' sensors.

Mote Application

When the mote receives a message from the client to form a group, it initializes a structure using the information from the message. With Tiny OS Active Messages, a message format is specified as a structure in a header file. The structure is then sent and received as the payload of a packet. The information the mote retrieves is:

The mote stores each structure in an array. When the timer fires, the mote iterates through the array and checks which groups it belongs to. For those groups where it is to produce a stream, it uses the latest sensor reading, creates a message with the value of the reading, its group ID and instance ID and sends the reading either to the coordinator or to the client through the BaseStation.

Implementation

The NesC application running on the motes wires together several implementations of interfaces provided with the TinyOS installation, such as:

In TinyOS applications, a component that uses an implementation of an interface calls the commands the implementation provides and implements the events of the interface. For example, the Group application calls the timer start command and implements the timer fired event. It calls the sensor's read command and implements the readDone event.

Client Application

The client application is written in Java using TinyOS Java APIs to communicate with the motes.

The client class implements the MessageListener interface, an interface for listening to messages built from net.tinyos.message.Message. The TinyOS mig tool was used to generate these Message subclasses from the message structures defined in NesC. They encode and decode the Active Messages received from the BaseStation so the client can just use the Message object to retrieve information sent by the mote. It uses a MoteIF object to send messages to and receive messages from a mote running the Base Station application.

Base Station Application

The client communicates with the motes by transmitting messages through the existing BaseStation application provided with the Tiny OS installation. The BaseStation is installed on a mote which is connected to a PC via the serial port.

The BaseStation acts as a simple Active Message bridge between the serial and radio links. On the serial link, BaseStation sends and receives simple active messages; on the radio link, it sends radio active messages.

Communication With Motes

The client initializes all the motes by sending them a message instructing each mote to form an instance of the group "AllNodes." Each mote responds by sending an acknowledgement message containing its ID, the group ID and the instance ID.

The client sends a second message that has the same semantics as the following GBP expression:

DEFINE GROUP Group1
FOR EACH g1 in AllNodes
AS EVERY g1
PRODUCES Stream1 unsigned int as light
END DEFINE

This expression instructs each instance of the AllNodes group to form its own group and report its photo sensor readings. Again each node sends back an acknowledgement and begins reporting back its photo readings to the Base Station which sends them to the client. The client then outputs the readings.

The last message from the client is:

DEFINE GROUP Group2
AS EVERY g2 in AllNodes
PRODUCES Stream2 unsigned int as AVERAGE(light OVER ALL)
END DEFINE

This expressions instructs each instance of AllNodes to form a group with other nodes and report the average photo sensor reading. In this application, node 2 is hard-coded as the coordinator node; the other nodes report their readings to this node which computes the average reading and sends it to the BaseStation. ( Due to some bug, these reports were not showing up at the client.)

Source code

Groups.zip