Mica2 Install Guide
Mica2 Install Guide
a Mica2 MOTE
Sensor Network
Mark Bramwell
mjbramwe@uwaterloo.ca
July 2006
Acknowledgements
This document was prepared in partial fulfillment of a course project, CS-848 Query Processing for
Emerging Applications presented by Professor Ihad IIyas.
Professor IIyas is a member of the Database Systems Research Group within the Department of
Computer Science at the University of Waterloo.
I would like to thank Professor IIyas for providing the Crossbow Mica2 motes used throughout the
duration of the project.
The University of Waterloo is located within the city of Waterloo, Ontario, Canada.
Crossbow Technology Inc is a manufacturer of Wireless Sensor Network hardware and is headquartered
in San Jose, California, USA.
i
Table of Contents
Acknowledgements........................................................................................................................................ i
INTRODUCTION ................................................................................................................................................. 1
Overview ................................................................................................................................................... 1
System Requirements ............................................................................................................................... 2
Software ................................................................................................................................................ 2
Hardware .............................................................................................................................................. 2
SOFTWARE INSTALLATION ................................................................................................................................... 3
Overview ................................................................................................................................................... 3
Installing UCB TinyOS 1.1.11 ..................................................................................................................... 4
The first step… ....................................................................................................................................... 4
Post Installation procedures ................................................................................................................ 5
Updating to TinyOS 1.1.15 cvs build ......................................................................................................... 6
Checking the TOS Installation ................................................................................................................... 7
Building the java tools............................................................................................................................... 8
Setting the Radio Frequency ..................................................................................................................... 8
The TinyDB GUI ......................................................................................................................................... 9
Compiling the TinyDB GUI for the PC .................................................................................................... 9
Starting the TinyDB GUI on the PC ........................................................................................................ 9
HARDWARE INSTALLATION ................................................................................................................................ 10
Overview ................................................................................................................................................. 10
Switch Settings ........................................................................................................................................ 10
MICA2 Mote Settings .......................................................................................................................... 10
MIB510CA Programmer Settings ........................................................................................................ 10
Testing the Motes ................................................................................................................................... 11
Overview ............................................................................................................................................. 11
Connecting the hardware ................................................................................................................... 11
Making MicaHWVerify ........................................................................................................................ 11
Programming MicaHWVerify via the MIB510CA programmer ........................................................... 12
Hardware COMMS check .................................................................................................................... 12
ii
MICA2 Radio Test .................................................................................................................................... 13
Installing TinyDB onto the motes............................................................................................................ 14
Overview ............................................................................................................................................. 14
Compiling and installing TinyDB.......................................................................................................... 14
Storing the Results Data in PostgreSQL (Optional) ................................................................................. 15
EXPERIMENTING WITH TINYDB .......................................................................................................................... 17
Overview ................................................................................................................................................. 17
Starting the TinyDB GUI on the PC .......................................................................................................... 17
Displaying the Topology .......................................................................................................................... 17
Simple Queries ........................................................................................................................................ 19
Correlation of Attributes Experiment ..................................................................................................... 21
APPENDIX....................................................................................................................................................... 25
Interesting Web Sites .............................................................................................................................. 25
iii
INTRODUCTION
Overview
This document describes how to implement a Wireless Sensor Network using Mica2 Motes loaded
with TinyOS and TinyDB1. It is assumed that the motes are not currently programmed with TinyDB.
When all of the software installation steps are completed, the operator will be able to use a
Microsoft Windows based PC to insert SQL-like queries into the Sensor Network, perform some
measurements and have the results returned to the base PC.
1
TinyOS + TinyDB is a declarative Database for Sensor Networks. WEB: http://telegraph.cs.berkeley.edu/tinydb/
1
System Requirements
Although it is possible to run the software under Linux or Microsoft Windows, all examples in this guide
will assume that the PC is 450mhz or better and is running Microsoft Windows XP with Service Pack2.
1. A java based Graphical User Interface (GUI) that runs on a MS Windows based PC
2. A Compiled C program that runs as an embedded application on the mote (flashed as firmware)
3. A software development environment that allow creation of the above 2 items
Software
TinyOS is extremely sensitive to hardware and software configurations. The system has many
dependencies that rely on specific versions of software components. Using older or newer versions of a
particular component may cause incompatibilities resulting in the system refusing to build and execute.
This document includes a CD-ROM that contains all of the necessary software components to build a
system from the ground up and allows you to perform some simple experiments.
Hardware
The hardware used in this guide was a selection of MICA2 Motes from Crossbow Technology Inc2. The
Motes were model MPR400CB using the CC1000 900mhz data radio. The sensor boards used were the
MTS300CA which enables the mote to measure temperature, sound and light in addition to the battery
voltage (used to power the Motes). The base station interface unit, model MIB510CA, is RS232 based
and serves two main purposes (1) It allows the user to reprogram any mote by plugging the mote
directly into the base (2) operates as part of the root node interface giving the PC a data conduit onto
the radio based sensor network.
2
Crossbow Technology Inc is a manufacturer of RF Sensor Network hardware and software WEB: www.xbox.com
2
NOTE: The MIB510CA interface must be connected to the PC via RS232. Many modern laptops are being
produced without a serial/RS232 interface (DE9 port). If your laptop does not have such a port, you must
use an USB to Serial Adapter such as the Startech ICUSB232 (pictured below).
SOFTWARE INSTALLATION
Overview
This section will describe how to install the UBC TinyOS + TinyDB software onto a PC running Windows-
XP.
3
Installing UCB TinyOS 1.1.11
The firststep…
The first step is to install the base system of TinyOS. All of the required files can be found on the
included CDROM or downloaded from the following website:
http://www.tinyos.net/dist-1.1.0/tinyos/windows/
The installer is called tinyos-1.1.11-3is.exe. It is suggested that you perform a complete installation and
stay with the default settings.
HINT: Have patience when starting the installer. It performs some system checks that can take up to 1
minute to complete; eventually the splash screen pictured above will appear.
Depending on the speed of the machine and whether or not anti-virus software is installed3, it can take
up to 15 minutes for the Installer to complete all steps.
3
Anti-virus software will dramatically slow down the installation as it scans thousands of files, many of them java
source files which tend to be targets of virus writers. The Installer contains no viruses.
4
Post Installation procedures
You should now have a Windows Program Group called Cygw in.Start the ‘Cygw in bash shell’w hich w ill
give you a Unix-like environment under Windows.
Ifyou do not receive the error,skip this section and go directly to the ‘U dating TinyO S 1.1.15 cvs build’.
The first time you start the bash shell, it is possible that an error will be printed complaining about some
missing security files. Not every installation of TinyOS receives the error pictured above, it depends on
what networking protocols are configured into your PC and if you are authenticating against a network
server (such as Microsoft Active Directory).
As suggested by the error message pictured above, run the following 2 commands:
5
After the commands have completed, exit the shell and open a new one. A completely different set of
messages will appear. The output should look similar to the picture below:
Once again you should exit the shell. You have completed the initial installation of the base software.
Now that TinyOS 1.1.11 is installed, the system should be immediately upgraded to version 1.1.15. Open
a new ‘cygw in bash shell’w indow . You must change the working directory to the same directory that
contains the updated RPM file.
mount
cd /cygdrive/e/software
6
Checking the TOS Installation
It is important that the development environment is capable of compiling applications without difficulty.
The TinyOS distribution includes a program that will verify the configuration of your machine and will
report back if any errors are found. The test must complete without errors, do not continue to any other
steps in this document if you have errors in your configuration.
To test your softw are configuration,start a ‘cygw in bash shell’and type the follow ing command:
toscheck
Most likely you will receive an error the first time you test your system. The CLASSPATH error is caused
by a configuration issue with the java environment and will look similar to the screen shot pictured
below.
To fix this problem, you must edit one of the configuration files and make a few changes.
7
Lines 57 & 60 were this:
print "$addpath;$oldpath\n";
But should be this:
print "$addpath;$oldpath;.\n";
After you have made the edits to the file, save them and exit the shell. Open a new shell and re-run the
toscheck. It should now complete without errors
This step compiles the java tools. Type in the commands below and wait for them to complete:
cd /opt/tinyos-1.x/tools/java
make
cd /opt/tinyos-1.x/tools/java/jni
make install
The MICA2 platform can be purchased with a variety of radio chipsets. It is important that the proper
frequency range is configured into the source code. The chip used on the MPR400CB,MICA2,900MHZ is
the CC1000 running at 900mhz.
Using whatever editor is familiar to you, edit the configuration constants for the MICA2 radio frequency
Filename: opt/tinyos-1.x/tos/platform/mica2/CC1000Const.h
Starting at Line 214, change the file to look like the following:
#ifdef CC1K_DEFAULT_FREQ
#define CC1K_DEF_PRESET (CC1K_915_998_MHZ)
#endif
#ifdef CC1K_MANUAL_FREQ
#define CC1K_DEF_FREQ (CC1K_915_998_MHZ)
#endif
#ifndef CC1K_DEF_PRESET
#define CC1K_DEF_PRESET (CC1K_915_998_MHZ)
#endif
8
The TinyDB GUI
Compiling the TinyDB GUI for the PC
The TinyOS + TinyDB system is comprised of 2 major components. One part of the system runs as a java
application on the ROOT PC providing the menus and graphing environment; the other part of the
system runs as compiled C code on the motes themselves.
To compile the java GUI for the PC, type the following commands:
cd /opt/tinyos-1.x/tools/java/net/tinyos/tinydb/
make
The following commands will start the TinyDB GUI on the PC:
cd /opt/tinyos-1.x/tools/java
java net.tinyos.tinydb.TinyDBMain
WARNING: The commands listed above are case sensitive. They must be entered exactly as shown
otherw ise a ‘java.lang.N oClassD efFoundError’m essage w illbe displayed and the system w illrefuse to
start.
HINT: If you are using anything but COM1, you will receive an error when the GUI tries to start. The
resolution is to modify the Tinydb configuration file to point to the proper com port.
As an example, on one particular laptop running an USB-to-Serial adapter, Windows XP assigned COM4
to the device. The reference from COM1 had to be changed to COMx (where in this case x=4).
comm.string:serial@COM1$57600
comm.string:serial@COM4$57600
After the modification was completed, java was able to start TinyDB without difficulty.
9
HARDWARE INSTALLATION
Overview
This section of the document will describe the steps required to setup, test and program the MICA2
hardware with the appropriate codes.
Switch Settings
MICA2 Mote Settings
The MICA2 platform has a single slide switch. It is the power switch for the batteries. Various websites
state that the batteries should not be installed while programming the motes because the programmer
board provides the power while the mote is connected.
During normal operation (not connected to the programmer), slide the switch to the ON position which
will provide battery power to the mote.
WARNING: Do not attempt to power the mote from both the on-board batteries as well as the
programmer board. Always slide the MICA2 power switch to OFF while connected to the programmer.
The programmer has a single slide switch that affects how data is sent on the serial com port. It must be
in the OFF position to both program and use the motes.
10
Testing the Motes
This section will describe how to test the MICA2 mote hardware.
Overview
The programmer must be connected to the PC with a serial cable. If you do not have a serial
port on your PC, an USB to Serial adapter must be used.
All examples in this guide will assume you are connected to COM1:
You must plug a MICA2 into the MIB510CA programmer.
A sensor-board is not required for this test.
The programmer must be powered via a wall adapter
Both the MICA2 and the MIB510CA must have their slide switches set to OFF.
Making MicaHWVerify
O pen a ‘cygw in bash shell’and type the follow ing com m ands:
cd /opt/tinyos-1.x/apps/MicaHWVerify
make mica2
At this point you now have a custom MICA2 compatible program ready to be programmed into the
mote.
11
Programming MicaHWVerify via the MIB510CA programmer
The previous step created an application ready for transferring into the MICA2.
To write the firmware image to the MICA2 chip, type the following command:
This step will attempt to communicate with the MICA2. Make sure the slide-switches on both the
programmer board and the MICA2 are set to OFF.
make –f jmakefile
To run the program and display a small report, type the following command:
It all goes well, you should see a small report that displays the Node Serial ID (as pictured below)
The commands listed above are case sensitive. Type them exactly as shown, the only deviation being the
COM Port if you are not using COM1. It is helpful to perform this test on at least 2 MICA2 nodes.
12
MICA2 Radio Test
This test requires 2 MICA2 nodes. One unit will be used as the base root node and the 2nd node will be
used as the remote node. During the test, the 2 nodes will communicate with each via the radio link.
Node #1: Take one ofthe nodes that has passed the ‘H ardw are Com m s Check’,installbatteries and slide
the switch to ON. The lights on the MICA2 will start to blink, the node is now active!
Node#0: This node will be our root node and will stay connected to the programmer board. It must
have som e special‘base station’softw are program m ed onto the M ICA2 in order for this test to operate
correctly.
To compile and load the base station software onto the MICA2, type the following commands:
cd /opt/tinyos-1.x/apps/TOSBase
make mica2
make mica2 reinstall mib510,/dev/ttyS0
cd /opt/tinyos-1.x/apps/MicaHWVerify
MOTECOM=serial@COM1:mica2 java hardware_check
The Node Serial ID report will be displayed. Notice that the ID of the remote node was displayed, not the
Node ID of the MICA2 plugged directly into the base station. The base station acted as a data conduit
passing the serial data onto the radio network; the remote node saw the data on the RF interface and
responded.
Re-run the MOTECOM program with the remote node powered off. The test will appear to hang as it
waits for a response from the remote node. Turn on the power on the remote node and the ID will be
displayed within 5 seconds.
13
Installing TinyDB onto the motes
Overview
Each MICA2 must be programmed with an unique copy of the TinyDB software. One node is called the
ROOT Node and during normal operation is always connected directly to the base station (MIB510CA
programmer board). The Node ID of the ROOT Node is always zero. All other nodes must have an
unique non-zero Node ID.
The following steps will compile and install TinyDB on each MICA2 node.
cd /opt/tinyos-1.x/apps/TinyDBApp
2. Compile and install a custom version of TinyDB for the ROOT node (Node#0)
3. Remove the ROOT Node and connect one of your remote nodes. The following command sets
the N ode ID to “1” and program s the M ICA2 node.
Repeat Step #3 until all MICA2 nodes have been programmed. Remember to increment the Node ID
giving each node an unique number.
HINT: To avoid confusion, It is helpful to label the MICA2 nodes with a paper sticker.
HINT: If you are not using COM1, you must use the appropriate driver name:
14
Storing the Results Data in PostgreSQL (Optional)
When TinyDB receives results from the Sensor Network, the data is stored and displayed within the
TinyDB GUI as a spreadsheet. Although this is adequate for quick adhoc queries, it becomes difficult to
access the data if queries are performed over an extended period of time. It may be desirable to have
the data stored within a PostgreSQL database.
PostgreSQL is available on a wide variety of platforms including but not limited to Windows,
Macintosh/OSX and Linux. It is beyond the scope of this document to try to describe how to install
PostgreSQL server on your machine. It is suggested that the above website is used to download and
install the software on the server platform of your choice.
If you decide to use the Windows version of PostgreSQL, a full-screen graphical interface is provided in
addition to the command line tools.
15
Tinydb requires a database to be created called ‘tinydb’.An usernam e called ‘tele’m ust be created and
requires perm ission to access ‘tinydb’.
The TinyDB configuration file must be edited to reflect the username/password and location of the
database.
Configuration file:
/opt/tinyos-1.x/tools/java/net/tinyos/tinydb/tinydb.conf
postgres-user:tele
postgres-passwd:tiny
postgres-db:task
postgres-host:localhost
Once the changes have been made to reflect the true location and attributes of the PostgreSQL
database, you will be able to use the [Log to Database] option in TinyDB.
16
EXPERIMENTING WITH TINYDB
Overview
This section deals with the usage of the Sensor Network. We will perform some simple queries that are
designed to test the netw orks ability to receive and respond to queries as w ellas the base station’s
ability to display the results.
In the paper titled Model Driven Data Acquisition in Sensor Networks4 , it was suggested that there was a
correlation between the values of certain attributes. An experiment will be conducted to investigate this
claim.
The following commands will start the TinyDB GUI on the PC:
cd /opt/tinyos-1.x/tools/java
java net.tinyos.tinydb.TinyDBMain
If the system refuses to start, refer to the section titled ‘The TinyD B G U I’in this docum ent for m ore
information.
4
"Model Driven Data Acquisition in Sensor Networks"; Amol Deshpande, Carlos Guestrin, Samuel Madden, Joseph
Hellerstein, and Wei Hong; VLDB 2004.
17
Displaying the Topology
The first test of the Sensor Network is to determine if indeed you have a network. When you start the
TinyDB GUI, a screen similar to the picture below will appear.
Clicking on the [Display Topology] button causes the system to insert a query into the network that
causes all nodes to respond. Their responses prove that a each node is alive and as well as embedded in
the response is the layout of the network (parent child forwarding tree).
Have patience when you attempt to display the topology. In a 8-node network, it can take up to 1
minute for the result to be displayed.
18
The ‘Sensor N etw ork Topology’screen pictured below is a graphicalrepresentation ofthe layout ofthe
sensor netw ork.The ‘Light’attribute is used to provide a visualindication of the attributes value.
Node 0 is the ROOT Node and was plugged directly into the base station interface. All other nodes were
scattered around three adjoining offices. The office containing Node#4 had the lights turned off (the
room was dark) and the graph clearly shows a low value for that attribute. Node#2 was on the floor
behind a desk in a shadow; the graph shows a darker (but not dark) region near that node. All other
nodes were in brightly lit areas.
HINT: When the topology is first displayed, it might be difficult to read because the icons are either off-
screen or piled on top of each other. Click on [Fit Network] to force the GUI to put all icons on the
visible portion of the graph. You can then click and drag on the Laptop Icon or any Node Icon to move it
to a more appropriate area of the graph.
19
Simple Queries
The strength of the TinyDB GUI is the ease in which the user can inject queries into the Sensor Network
and have the results returned and displayed on the base station PC.
Pictured below is the main screen of TinyDB. To start a query, scroll through the list of available
attributes in box #1. Note that although the list contains all supported attributes, not all nodes will have
the sensors installed to perform that measurement. Make sure you do not try to read from something
that does not exist. When you double-click on an attribute in box #1, the attribute will appear in the
listing in box #2 as well as a SQL-like query will be constructed in box #3. If you have clicked on
something accidently, double-click on the attribute in box #2 to remove it from the list.
When you have selected all of your desired attributes, click on #4 [Send Query] to start the querying of
the network.
20
Once the query has been injected in the Sensor Network, the nodes will perform readings and send back
the results to the base station PC connected to Node 0. A chart will be created in real-time that looks
similar to the one pictured below.
The above graph represents the plot of light from 3 nodes over a period of 2,490 samples.
NOTE: Have patience when you send a new query into the network. It can take over a minute for the
query to be encoded, transmitted to all nodes and the for the first response to migrate through the
network back to the base station PC. Once the results start to arrive, they will do so at the expected rate
without delay.
21
Correlation of Attributes Experiment
In the paper titled Model Driven Data Acquisition in Sensor Networks5 , it was suggested that there was a
correlation between the values of certain attributes. The paper offers the following table to show how
much power (in Joules) is required to perform a sensor reading:
From the above table, we can clearly see that the amount of power required to perform a sensor
reading of the temperature is many times higher than the amount of power required to measure the
motes battery voltage.
The paper claims that if we were to measure both the voltage and the temperature of a mote during a
change in temperature, the plotted curve would show a correlation between the two values (both
would rise or fall together). If this relationship exists, a reduction in power can be realized by frequently
performing voltage measurements instead of temperature readings (refer to the paper for more
detailed information).
For those of us that have tried to start their automobile on a frigid Canadian winter morning, we already
know that battery voltage seems to drop with temperature. However some analytical data showing
evidence of this correlation is preferred.
5
"Model Driven Data Acquisition in Sensor Networks"; Amol Deshpande, Carlos Guestrin, Samuel Madden, Joseph
Hellerstein, and Wei Hong; VLDB 2004.
22
In order to conduct this experiment, a method of cooling the mote is required. A small office refrigerator
was used to chill the device.
The Mica2 mote was placed into the refrigerator and the door was kept closed. Luckily the rubber seals
on the refrigerator are wide enough to allow the radio signal to escape and it did not operate as a
Faraday Cage6. Measurements were taken every 2 seconds over a period of approximately 40 minutes.
Over 1,200 sample readings were performed and reported back to the base PC via the Sensor Network
Note: Only a single Mica2 mote (in addition to the base station) was used during this experiment
6
A Faraday Cage would have blocked the radio signal from reaching the base station. For more information
regarding Faraday Cages, see the following WEB link: http://en.wikipedia.org/wiki/Faraday_cage
23
The TinyDB GUI provides a graphing interface but it is not the best method of displaying the results from
multiple attributes. The resulting data was read into Microsoft Excel and a graph of the two generated
values was plotted.
The graph pictured above clearly shows that as the Mica2 was chilled over a period of 40 minutes, both
the Temperature Sensor as well as the Voltage Sensor reported a drop in the returned attribute values.
The results of this experiment validates the claim s m ade by the authors of‘Model Driven Data
Acquisition in Sensor Networks’when those two specific sensors are used in that type of testing
environment.
24
APPENDIX
What is RS232
http://en.wikipedia.org/wiki/RS232
25