Debugging NesC made easy with Printf library


Put watch , breakpoints ... all sort of such powerful debugging we miss when we do tinyos and nesc. I had a good struggle to find out what went wrong in a code till I figured out serialforwarder and the libraries to print values in between. This again needs many routine calls and stuffs.
To make things easier, there is a library "tinyos printf". Anyone who had used printf in C, same syntax will work. This post is on how to use tinyos printf library.
Before we begin, I assume that you are familiar with serialforwarder interface and simple blink application. Again the screenshots are done with original mote. Avrora users can do the same with micaz compilation, then follow the post using serialforwarder interface with avrora.

This is simple application which generates random numbers with Random interface and prints the value to the screen. All you need is
  1. Include printf path in Makefile
  2. Include printf.h in your application
  3. Invoke the Serialforwarder
  4. Type java net.tinyos.tools.PrintfClient and see the output.
The screenshots are given below.

The corresponding files can be found here

Related posts
Running tinyos programs using avrora
Using Serialforwarder with Avrora

5 comments:

Anonymous said...

I have a generic question regarding mote programming and operation. Is it possible to extract the mote program and memory from a pre-programmed mote?

I would like to extract the binary information from a MICA2 mote. I'm not sure if this is possible, but I'm interested in your thoughts.

Gireesan said...

I have done it with AvrDude in Atmega128 uc.
Never tried in MIB though
www(dot)nongnu(dot)org/avrdude/user-manual/avrdude_9(dot)html

shows dump memory example.
In MicaZ , using JTAG also u can achieve the same.

Anonymous said...

Hi,

I am using TinyOS on BTnode. The PrintfClient sometimes works fine and sometimes not, ie, it will sometimes show the printf messages, and sometimes (or rather, most of the time) not. I did not modify nor use serialAMMessage nor other serial communication modules in my program. Also, I have kept the printf messages as short as possible. Do you have any solution for this?

Thanks in advance.

Gireesan said...

@anonyms
did u use printfflush after printf statement?
if not pl try that...

acydgine said...

Hi Gireesh,

Thanks for your reply.

Yes I did, in fact it seems to be an intermittent problem. It was not working when I left a message here, but yesterday it was fine the whole day, showing printf messages in the codes that I was testing.

Today it is not working again. I am not sure if my computer is at fault for not receiving the messages or is the problem at the PrintfClient's side.

-Wan Ru-