Difference between revisions of "MansOS tutorial"

From DiLab
Jump to: navigation, search
(New page: == Getting MansOS == See MansOS installation guide. For the purposes of this tutorial, you will need: * MansOS sources. The recommended way is to cecking them out ...)
 
Line 3: Line 3:
See [[Installing MansOS | MansOS installation guide]].
See [[Installing MansOS | MansOS installation guide]].
For the purposes of this tutorial, you will need:
For the purposes of this tutorial, you will need:
* MansOS sources. The recommended way is to cecking them out from SVN by using command "svn co http://mansos.net/svn/mansos/ mansos"
* MansOS sources. The recommended way is to checking them out from SVN by using command "svn co http://mansos.net/svn/mansos/ mansos"
* Development tools, such as msp430-gcc compiler
* Development tools, such as msp430-gcc compiler
* Common UNIX command line tools, such as ''make''
* Common UNIX command line tools, such as ''make''
Line 27: Line 27:
For testing the application on simulator:
For testing the application on simulator:
make pc run
make pc run

The mote should now periodically (one change per second) turn one of its LEDs on and off.

The upload command by default tries to upload the application to serial port /dev/ttyUSB0. If your mote is attached to another port, change '''BSLPORT''' environmental variable to specify the correct port. For example:
$ export BSLPORT=/dev/ttyUSB1
$ make telosb upload
...
./../../../mos/make/scripts/tos-bsl --telosb -c <b>"/dev/ttyUSB1"</b> -r -e -I -p ./build/telosb/image.ihex

To see to which port the mote is attached you can use '''motelist''' utility:
$ motelist
Reference Device Description
---------- ---------------- ---------------------------------------------
M4AOQGBQ /dev/ttyUSB0 Moteiv tmote sky


== Debugging an application ==
== Debugging an application ==


Printf-style debugging is the most commonly used form of debugging for sensor motes.
PRINTF...

MansOS provides several macros for this:
* PRINTF(format, arguments): analogue of ''printf()'' function;
* PRINT(string): just print the string passed as argument; when compared to PRINTF(), this version has the benefit of smaller executable size;
* PRINTLN(string): print the string passed as argument with newline character appended.

By default output from these macros is sent to serial port.

To see one of these macros in action, change directory to ''mansos/apps/demo/CounterToSerial'', compile and upload the application.

=== Listening to serial port ===

To observe the output a program capable to listening the serial port is required. If you don't know what to use, try:
* On Linux or MAC: '''minicom'''
* On Windows: '''putty'''

Use 38400 as baudrate setting, 8 bits, 1 stopbit, parity none, flow control turned off. Here is a complete minicom configuration file for reference:
pu port /dev/ttyUSB0
pu baudrate 38400
pu bits 8
pu parity N
pu stopbits 1
pu rtscts No

Configure minicom/putty so that it listens to the serial port a mote is attached (/dev/ttyUSB0 for minicom by default). Compile and upload the ''CounterToSerial'' application, and launch minicom:

=== Alternatives to serial port output ===

Alternatively, the printed characters can be sent on air by using radio transceiver. To enable this option, add this line:
CONST_DPRINT_TO_RADIO=1
to application's configuration file. In this case, no output to serial port will be produced. You will need another mote which listens to radio and forwards all messages received to its serial port, i.e. acts as a proxy.


Alternatively, the printed characters can be sent to LCD terminal, if pone is attached to the mote.
minicom...


== Analysis of a MansOS application ==
== Analysis of a MansOS application ==
Line 60: Line 105:


* Bidirectional serial port communication
* Bidirectional serial port communication
** Listening to serial port
** Sending data to serial port
** Writing to serial port
** Reading input from serial port


* Radio communication
* Radio communication
** Packet sending
** Including measuring the strength of received radio signal in different channels
** Packet receiving
** In this way, a primitive spectrum analyzer can be built!
** Measuring the strength of received radio signal in different channels (in this way, a primitive spectrum analyzer can be built!)
** Optionally: TinyOS frame format support
** Optionally: rudimentary 802.15.4 MAC frame format support


*Network stack
* Network stack
** Sending data to a specific mote in the network
** Sending data to a specific mote in the network
** Sending data reliably
** Sending data reliably
** Collecting data from the whole network
** Collecting data from the whole network
** Synchronizing time in the whole network


* Management
*Storing data on flash or SD card, optionally using a file system.
** Controlling a specific mote by using an application running on computer
** Controlling whole network of motes at once
** Reading the address, serial number, sensor data etc.
** Rebooting the mote, turning LEDs on and off etc.
** Reprogramming the mote


* Parallel execution
*Sensors:
** Preemptive multitasking
** Optionally, cooperative multitasking (similar to Contiki protothreads)

* Storing data on flash or SD card:
** Optionally, using a file system

* Reading sensors:
** Light
** Light
** Temperature
** Temperature
** Humidity
** Humidity
** Accelerometer and gyroscope
** Accelerometer and gyroscope
** Data from a GPS device
** Data from a GPS device (NMEA stream)
** Other sensors using analogue interface. Just specificy the correct ADC channel you want to read and voila!
** Other sensors using analogue interface. Just specify the correct ADC channel you want to read and voila!
** Other sensors using digital I2C interface (you wikll need to write your own driver for this; hovever, it may be not as hard as it sounds)
** Other sensors using digital I2C interface (you will need to write your own driver for this; however, it may be not as hard as it sounds)


* Using LCD for output
*LCD


*Low power modes:
*Low power modes:
Line 97: Line 158:


Yes...
Yes...

== Glossary ===

''upload'': program the application in a mote

Revision as of 18:05, 13 October 2011

Getting MansOS

See MansOS installation guide. For the purposes of this tutorial, you will need:

  • MansOS sources. The recommended way is to checking them out from SVN by using command "svn co http://mansos.net/svn/mansos/ mansos"
  • Development tools, such as msp430-gcc compiler
  • Common UNIX command line tools, such as make
  • A working Python installation
  • At least one mote (Tmote Sky, Arduino, Epic mote, SADmote etc.) on which to run the application
    • If you don't have any motes, then you can just run MansOS using its built-in simulation platform "pc"

Building and running your first application

Change location in MansOS root directory to mansos/apps/demo/Blink.

Now compile the application and program it in the device.

If you have Tmote Sky:

make telosb upload

If you have Arduino:

make atmega upload

If you have SADmote:

make telosb upload-msp430

For testing the application on simulator:

make pc run

The mote should now periodically (one change per second) turn one of its LEDs on and off.

The upload command by default tries to upload the application to serial port /dev/ttyUSB0. If your mote is attached to another port, change BSLPORT environmental variable to specify the correct port. For example:

$ export BSLPORT=/dev/ttyUSB1
$ make telosb upload
...
./../../../mos/make/scripts/tos-bsl --telosb -c "/dev/ttyUSB1" -r -e -I -p ./build/telosb/image.ihex

To see to which port the mote is attached you can use motelist utility:

$ motelist
Reference  Device           Description
---------- ---------------- ---------------------------------------------
M4AOQGBQ   /dev/ttyUSB0     Moteiv tmote sky

Debugging an application

Printf-style debugging is the most commonly used form of debugging for sensor motes.

MansOS provides several macros for this:

  • PRINTF(format, arguments): analogue of printf() function;
  • PRINT(string): just print the string passed as argument; when compared to PRINTF(), this version has the benefit of smaller executable size;
  • PRINTLN(string): print the string passed as argument with newline character appended.

By default output from these macros is sent to serial port.

To see one of these macros in action, change directory to mansos/apps/demo/CounterToSerial, compile and upload the application.

Listening to serial port

To observe the output a program capable to listening the serial port is required. If you don't know what to use, try:

  • On Linux or MAC: minicom
  • On Windows: putty

Use 38400 as baudrate setting, 8 bits, 1 stopbit, parity none, flow control turned off. Here is a complete minicom configuration file for reference:

pu port             /dev/ttyUSB0
pu baudrate         38400
pu bits             8
pu parity           N
pu stopbits         1
pu rtscts           No 

Configure minicom/putty so that it listens to the serial port a mote is attached (/dev/ttyUSB0 for minicom by default). Compile and upload the CounterToSerial application, and launch minicom:

Alternatives to serial port output

Alternatively, the printed characters can be sent on air by using radio transceiver. To enable this option, add this line:

CONST_DPRINT_TO_RADIO=1

to application's configuration file. In this case, no output to serial port will be produced. You will need another mote which listens to radio and forwards all messages received to its serial port, i.e. acts as a proxy.

Alternatively, the printed characters can be sent to LCD terminal, if pone is attached to the mote.

Analysis of a MansOS application

main.c

Makefile

config

MansOS shell

Demo application...

PC command line tool...

Commands...

MansOS features

MansOS has support for:

  • LEDs
    • On Tmote Sky: red, green, and blue
    • On SADmote: just red
    • On Arduino: just yellow
  • Bidirectional serial port communication
    • Sending data to serial port
    • Reading input from serial port
  • Radio communication
    • Packet sending
    • Packet receiving
    • Measuring the strength of received radio signal in different channels (in this way, a primitive spectrum analyzer can be built!)
    • Optionally: TinyOS frame format support
    • Optionally: rudimentary 802.15.4 MAC frame format support
  • Network stack
    • Sending data to a specific mote in the network
    • Sending data reliably
    • Collecting data from the whole network
    • Synchronizing time in the whole network
  • Management
    • Controlling a specific mote by using an application running on computer
    • Controlling whole network of motes at once
    • Reading the address, serial number, sensor data etc.
    • Rebooting the mote, turning LEDs on and off etc.
    • Reprogramming the mote
  • Parallel execution
    • Preemptive multitasking
    • Optionally, cooperative multitasking (similar to Contiki protothreads)
  • Storing data on flash or SD card:
    • Optionally, using a file system
  • Reading sensors:
    • Light
    • Temperature
    • Humidity
    • Accelerometer and gyroscope
    • Data from a GPS device (NMEA stream)
    • Other sensors using analogue interface. Just specify the correct ADC channel you want to read and voila!
    • Other sensors using digital I2C interface (you will need to write your own driver for this; however, it may be not as hard as it sounds)
  • Using LCD for output
  • Low power modes:
    • msleep() and usleep() functions will automatically put the sensor device in low power mdoe

How different features of MansOS can be turned on and off?

config files

Default config file...

Can MansOS be used just as a library? =

Yes...

Glossary =

upload: program the application in a mote