TinyOS, NesC, and Mica2

Introduction

These are just some notes that I will be maintaining as I work with TinyOS, NesC, and the Mica2 mote platform. While not indented to be a FAQ for the community, I hope that some other people will be able to resolve similar issues more quickly then I have been able to.

This page was originally hosted as TinyOS, NesC, and Mica2 Lessons Learned on my old website.

TinyOS 2.x note

I did download the 2.x distribution, and it seemed to work well… however most of my colleges are TinyOS 1.x experts, so I reverted back. Once I get a handle on TinyOS and NesC, I may covert to 2.x though…

Installation Recommendations

Virtual Machine

The 1.x version of TinyOS requires java 1.4 and special distributions of cygwin and make packages. This is a total pain in the rump if you use cygwin and java for other things besides TinyOS… My solution was to install all this stuff in a Virtual Machine (I used VMWare) so that all the custom distributions required by TinyOS are separated from my primary installations.

Error Messages while Programming the Mote

General Techniques

Try ‘Blink’

First thing to do when you have an error programming a mote is to roll back to the standard ‘Blink’ application and try to install that. This removes all the variables that are related to software…

Try Erasing

Try running this command several times (at least 3) to really clear the mote.(see note on tty’s)

uisp -dprog=mib510 -dserial=/dev/ttyS0 -dpart=ATMega128 --erase

Probably the AVR MCU is not in the RESET state.

This probably means that your mote is not entirely seated on the programming board. Make sure it’s completely seated on the connector and try again.

batteries are low

While trying to upload a program to the mote, the make script errors out with: … Batteries are Low …

Typically, when get this message, I have forgotten to include the serial port on the “make install” command line. It should look something like this (see note on tty’s):

make mica2 install mib510,/dev/ttyS0

I’ve also heard that this problem can occur if you don’t have your environment variables set correctly. Be sure that you have these variables set:

export MAKERULES=/opt/tinyos-1.x/apps/Makerules
export MIB510=COM1

TOSSIM Issues

TOSSIM only starts one of the motes and runs really slow

When I first started trying to debug my application, I started up TOSSIM to find that only one mote would ever start up. If I turned on the debug messages, I found that the one mote that was alive was reporting that it was recieving lots of bits… but I wasn’t even sending anything… argh.

Turns out that all I needed to do was

export DBG=usr1,usr3

It seems (to me) that if there is no evironment variable DBG, TOSSIM flips out. This is hardly a formal description, do if anyone has a better idea of what’s going on, let me know.

Using MoteIF to communicate with a Mote

Serial Port Driver

This section assumes that you have been able to property install the javax.comm package with the correct libraries on your system.

Generating the Java stub

Use a command similar to the following to generate a java stub that MoteIF will populate/read:

mig java -java-classname=com.foo.bar.DataMsg -o DataMsg.java Foo.nc DataMsg

When I run this on my application, it starts complaining about a component that I’m using that it can’t figure out. My workaround for the time being has been to comment this component out, but I would like to eventually figure out how to fix this for real. If you know how, please leave a comment below.

Getting MoteIF started

Here’s some sample code:

PacketSource source = BuildSource.makePacketSource("serial@COM7:mica2");
PhoenixSource phoenixSource = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
MoteIF mif = new MoteIF(phoenixSource);
mif.start();

You’ll need to register your own listener to recieve messages… something like this:

moteIf.registerListener(new DataMsg(), new MessageListener() {...});

Where do I find the PhoenixSource class files?

Put this jar in your classpath… it’s in the TOS distribution/cvs tree.

simdriver.jar

Notes


ttyS0

In the examples above, ttyS0 should be replaced with whatever matches your COM port. (com1 = ttyS0, com2 = ttyS1, com3 = ttyS2, …)

Other Resources

Corrections and Comments

Please add corrections or comments below!