Free Essay

Tinyos Nesc

In:

Submitted By sjoao
Words 1121
Pages 5
Universidade de Coimbra Faculdade de Ciências e Tecnologia

DEPARTAMENTO DE ENGENHARIA INFORMÁTICA
Protocolos de Comunicação 2

Introdução ao nesC
Aula Prática nº1 Ano Lectivo de 2013/2014 CrossBow®

This first application that you are going to study is called MyApp. As the name suggests it uses one of the timers on the ATmega128L Mote. The timer will be set to fire continuously every second and the Mote red LED will toggle on and off to show this visually. So why go through the trouble of this program? To help the developer unfamiliar with TinyOS, nesC & Motes gain more confidence in embedded programming concepts before tackling more complex applications. The steps that you’ll take to build the application will be as follows: Enter in all necessary code and auxiliary files Build (compile) and download the application Take a closer look at the code and auxiliary files

1. Hardware Requirements This task requires the following hardware: - One Mote: standard editions of MICAz (MPR2400) - One gateway / programming board: MIB520 and the associated hardware (cables, power supply) for each - A Windows PC with MoteWorks installed

2. A simple nesC program: MyApp To get started the first thing to do is to create the application folder (directory) where all your application code and other files will be stored. 1. Change into the directory /MoteWorks/apps/tutorials/ and create a new subfolder (subdirectory) that should have the name as your application is to be called. In this first lesson the application can be called MyApp.

Within the MoteWorks framework a minimum of five files will be in any application’s directory: 1. Makefile (section 2.1) 2. Makefile.component (section 2.2) 3. Application’s configuration written in nesC

2.1 Makefile

The first step in creating an application is to type in the Makefile. To create the Makefile, enter the following text into a new document in Programmer’s Notepad: include Makefile.component include $(TOSROOT)/apps/MakeXbowlocal include $(MAKERULES) When finished save the file with File > Save As… using the following parameters: File name Makefile Save as type All files (“.”) File format No change to file format

2.2 Makefile.component

The next step is to create the Makefile.component file. This file describes the top level application component, MyApp and the name of the sensorboard we are going to use. The sensorboard reference tells the compiler we want to use the pre-built nesC

components for accessing the sensor devices on that board. Each sensorboard has its own set of pre-built nesC sensor components, also referred to as drivers. To create the Makefile.component file, enter the following text into a new document in Programmer’s Notepad: COMPONENT=MyApp SENSORBOARD=mts310 When finished save the file with File > Save As… using the following parameters: File name Makefile.component Save as type All files (“.”) File format No change to file format

2.3 Create the Top-Level Configuration

The application’s configuration is located in the MyApp.nc file. The StdControl interface must always be implemented as the bare minimum for an application. The StdControl interface provides the basic functionality for the TinyOS application to be initialized, started and stopped. To create the application’s configuration, enter the following text into a new document in Programmer’s Notepad: /** * This configuration shows how to use the Timer and LED components **/ configuration MyApp { } implementation { components Main, MyAppM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> MyAppM.StdControl; MyAppM.Timer -> TimerC.Timer[unique("Timer")]; MyAppM.Leds -> LedsC.Leds; } The last two lines in the configuration wire the TimerC and LedsC components to the application’s module. The module can then control the Timer and LED devices by calling functions in the TimerC and LedsC components.

When finished save the file with File > Save As… using the following parameters: File name MyApp.nc Save as type All files (“.”) File format No change to file format

2.4 Create the Module The application’s module is located in the MyAppM.nc file. The module file is where the application programming code is entered. This is where we type in programming code to start the Timer and toggle the red LED on the Mote. To create the application’s module, enter the following text into a new document using Programmer’s Notepad: /** * This module shows how to use the Timer and LED components **/ module MyAppM { provides { interface StdControl; } uses { interface Timer; interface Leds; } } implementation { /** * Initialize the components. * * @return Always returns SUCCESS **/ command result_t StdControl.init() { call Leds.init(); return SUCCESS; } /** * Start things up. This just sets the rate for the clock * component.

* * @return Always returns SUCCESS **/ command result_t StdControl.start() { // Start a repeating timer that fires every 1000ms return call Timer.start(TIMER_REPEAT, 1000); } /** * Halt execution of the application. * This just disables the clock component. * * @return Always returns SUCCESS **/ command result_t StdControl.stop() { return call Timer.stop(); } /** * Toggle the red LED in response to the Timer.fired * event. * * @return Always returns SUCCESS **/ event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } } When finished save the file with File > Save As… using the following parameters: File name MyAppM.nc Save as type All files (“.”) File format No change to file format 2.5 Compile and Install the Code in a Mote

Now that you have edited all the application files we can proceed with the compilation and installation steps.

NOTE: You need to be in the .nc of the app file you want to compile and program before you can execute shell commands from Programmer’s Notepad. You can compile your nesC application code from Programmer’s Notepad. To compile your application: • Select Tools > make micaz • The “Output” section of the Programmers Notepad will print the compiling results to the screen:

• After the compilation has completed you should see “writing TOS image” as the last line in the Output window. If you don’t see this then you have made an error typing in one of your files. Make sure you have success compiling your application before proceeding. You can also install your application to a Mote plugged into your programming board using Programmer’s Notepad. To install your application: • Select Tools > shell. When prompted for parameters, type in make micaz reinstall mib520, com1

NOTE: This example assumes you are using an MIB520 programming board connected to your PC using the COM1 serial port. Please make the necessary adjustments if using a different programming board and/or serial port. • The “Output” section of the Programmers Notepad will print the installation results to the screen:

• Make sure you see the “Uploading: flash” line complete without errors. You should then see the red LED on the Mote blinking on and off every second. Congratulations, you have just written, compiled and installed your first TinyOS embedded application using MoteWorks!

2.6 Exercise Program the timer to fire every 10s.

Similar Documents

Free Essay

Tinyos

...Steps for Installation of TinyOS 2.1.1 over Ubuntu Installing Ubuntu 1. 2. 3. 4. Go to Ubuntu.com Select Get Ubuntu Now Select Run it with Windows Click Start Download. The file you will download is called wubi.exe (also uploaded on course schedule) 5. Install Ubunutu by running the wubi.exe file Installing TinyOS 2.1.1 1. Open Dash home on the top left corner of the desktop screen 2. Search for Terminal and Open a Terminal (i.e., console) 3. Type the following line: $ sudo gedit /etc/apt/sources.list 4. In the file sources.list that would be opened add the following lines at the end of the file and save and close the file afterwards : #tinyos deb http://hinrg.cs.jhu.edu/tinyos oneiric main 5. Back in the terminal (i.e., console) type the following lines: $ sudo apt-get update $ sudo apt-get install tinyos-2.1.1 6. After installation is complete, in the terminal (i.e., console) type the following line: $ gedit ~/.bashrc 7. In the file .bashrc that would be opened add the following lines at the end of the file and save and close the file afterwards : export TOSROOT=/opt/tinyos-2.1.1 export TOSDIR=$TOSROOT/tos export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.:$CLASSPATH export MAKERULES=$TOSROOT/support/make/Makerules export PATH=/opt/msp430/bin:$PATH #Sourcing the tinyos environment variable setup script source /opt/tinyos-2.1.1/tinyos.sh 8. Type exit in the terminal (i.e., console) to close it 9. Open a new terminal, if everything went well you should see a message on top...

Words: 519 - Pages: 3

Free Essay

Student

...WIRELESS SENSOR NETWORK COVERAGE: DEMONSTARTING POWER SAVINGS AND LIMITATIONS WITH MINIMIZED COVERAGE BY SIDNEY I. RUBEY A thesis submitted to the Graduate faculty of the University of Colorado at Colorado Springs in partial fulfillment of the requirements for the degree of Master of Science Department of Computer Science 2011 This thesis for Master of Science degree by Sidney I. Rubey has been approved for the Department of Computer Science by ------------------------------------------------------------------------ Dr. C. Edward Chow, Chair ------------------------------------------------------------------------ Dr. Terrance E. Boult ------------------------------------------------------------------------ Dr. Xiaobo Zhou ----------------------------------------- Date Abstract This paper explores the competing issues of coverage efficiency and power available in wireless sensor networks. Specifically, a shortest distance routing protocol is implemented, and total network system lifetimes are determined using a variety of small percentages of the available system nodes. Using a network simulator developed in Java, wireless sensor nodes are simulated, and power consumption algorithms are included in each node that take into consideration all aspects of power consumption in the operation of the node. Simulating different coverage schemes on the same network system, same initial power sources, and routing protocol, an increase of overall system lifetime of 900% is demonstrated...

Words: 15836 - Pages: 64