Assignment 2: Developing a program to sense light intensity


The purpose of this assignment is to develop a program for the TelosB motes to sense light intensity.

Requirement:

  1. A mote senses light every 3 seconds and sends this sensor reading to the base station. The sensing mote also should display its sensor reading on its LEDs. The red LED is on whenever the sensor reading is greater than 500. The green LED is on whenever the sensor reading is smaller than 500, and the blue LED is on whenever the sensor reading is smaller than 50.

  2. Use another mote as the base station. When the base station receives a radio message, it simply forwards it to its serial port (TOS_UART_ADDR.), allowing the host PC to receive the data.

  3. The motes should use the message format specified in the header file IntMsg.h which is located at /opt/tinyos-1.x/tos/lib/Counters/.


Create a directory SenseLightToLedsAndRfm in tinyos-1.x/apps/. You must use the same Makefile format as other TinyOS applications such as Blink. This makefile must include:

COMPONENT=<your_application_name>

include $(MAKERULES)

By default, the TelosB motes use DemoSensorC.nc from /platform/msp430, which is wired to the InternalTempC. The light sensor on the device is in HamamatsuC.nc in /platform/telos. There is also a “total solar radiation” (TSR) and a “photosynthetically active radiation” (PAR) sensor. You should write a LightSensorC.nc configuration wired to HamamatsuC using TSR.

In order to avoid collisions with other groups, select a unique GroupID in the range 0x10 through 0x50 for your group. To set the GroupID, set the following line in your Makefile. Before it includes the Makerules file:

DEFAULT_LOCAL_GROUP = 0x40

Every mote should be assigned a unique address which serves as its ID. To set the mote's address during program load, use the following command:

make [re]install.<addr> telosb

where <addr> is the desired device address. Do not use the reserved values TOS_BCAST_ADDR (0xFFFF) or TOS_UART_ADDR (0x007E). A node can identify itself using the macro TOS_LOCAL_ADDRESS.
install - Compile the application for the target platform, set the address and program the device.
reinstall - Set the address and program the device ONLY (does not recompile). This option is significantly faster.

For the base station, you can simply use the application TOSBase which is located at /tinyos-1.x/apps/TOSBase.

In order to get the data from the serial port, you should change your current directory to /tinyos-1.x/tools/java and run the following commands.

export MOTECOM=serial@COM6:telos
java net.tinyos.tools.Listen

(Replace COM6 with the name of the serial port used to access the Telos mote. Use the motelist to check the serial port. )

[For Linux users, you need to make a symlink that makes the USB serial port look like a "standard" serial port. As root, type:
ln -sf /dev/ttyUSB0 /dev/ttyS1

Change the permission of the USB port to let normal users program TelosB through USB port
(so that you don't need to be root to program the mote):
chmod 666 /dev/ttyUSB0

/dev/ttyUSB0 is the USB port where your TelosB mote will be connected (/dev/ttyUSB0 should work in most cases). /dev/ttyS1 should be an unused physical serial port. You can pick another number if you want. If you choose /dev/ttyS1, then the TelosB mote can be accessed using
export MOTECOM=serial@/dev/ttyS1:telos ]

You should see some output resembling the following:

% java net.tinyos.tools.Listen

serial@COM1:57600: resynchronising

04 01 08 32 FF FF FF FF 04 7D 9A 02 01 00

04 01 08 33 FF FF FF FF 04 7D 9A 02 01 00

04 01 08 34 FF FF FF FF 04 7D 9C 02 01 00

This Listen program simply prints the raw data of each packet received from the serial port.

Before continuing, execute unset MOTECOM to avoid forcing all java applications to use the serial port to get packets. If you don't have the javax.comm package installed properly, then the program will complain that it cannot find the serial port. If you do not see that data lines on the screen, you may have chosen a wrong COM port or the mote may not be correctly connected to the computer. One TOS_Msg message is printed per line. You can check /tos/platform/telos/AM.h for reference. In TOS_Msg, the data contains the structure SenseIntMsg defined in SenseLightMsg.h. Here, 9A 02(0x029A) is the value and 01 00(0x0001) is the ID.

The color of the standard LED implementation does not match the actual LEDs on the TelosB motes. So, you should keep in mind that which function in LED implementation corresponds to which LED.