Mobile and Ubiquitous Computing TinyOS application example. Niki Trigoni

Similar documents
Sensor Network Application Development ZIGBEE CONCEPTS 2

Introduction to Programming Motes

BaseStation Based on GenericComm. Aly El-Osery Electrical Engineering Dept. New Mexico Tech Socorro, NM

Programming TinyOS. Lesson 2. Execution Flow. Tasks. commands. Events generated by interrupts preempt tasks Tasks do not preempt tasks

Mobile and Ubiquitous Computing Routing Protocols. Niki Trigoni

Programming Sensor Networks

Sensor Network Application Development ZIGBEE CONCEPTS 0

Sensor Networks. Part 3: TinyOS. CATT Short Course, March 11, 2005 Mark Coates Mike Rabbat. Operating Systems 101

The Emergence of Networking Abstractions and Techniques in TinyOS

Crossbow: MoteWorks Getting Started Guide. Presented by Catherine Greene, Bretny Khamphavong, Chloe Norris, and Nancy White

LiteOS Application Note AN-101: Mote-PC communication and data display

TinyOS. Jan S. Rellermeyer

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM

Embedded OS Case Study: TinyOS

Self-Organization in Autonomous Sensor/Actuator Networks [SelfOrg]

Wireless Systems Laboratory 4 November 2013

Exam Ad Hoc and Sensor Networks HS 2007

% #!" # !" #$ (# ( ' (# (

ANEXO D CÓDIGO DE LA APLICACIÓN. El contenido de los archivos de código fuente almacenados en el directorio Nodo desconocido es el siguiente:

WSN PLATFORMS, HARDWARE & SOFTWARE. Murat Demirbas SUNY Buffalo

TinyOS. Lecture Overview. UC Berkeley Family of Motes. Mica2 and Mica2Dot. MTS300CA Sensor Board. Programming Board (MIB510) 1.

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja)

Middleware for Wireless Sensor Networks: An Outlook

CS434/534: Topics in Networked (Networking) Systems

REMOTE PROGRAMMING FOR HETEROGENEOUS SENSOR NETWORKS VISHAL BHATIA. BCA(Hons), Devi Ahilya Vishwavidyalaya, India, 2006 A REPORT

TinyOS Lesson 6 Topology Control

Incremental Network Programming for Wireless Sensors. IEEE SECON 2004 Jaein Jeong and David Culler UC Berkeley, EECS

TinyOS an operating system for sensor nets

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

nesc Ø Programming language for TinyOS and applications Ø Support TinyOS components Ø Whole-program analysis at compile time Ø Static language

2018/2/5 话费券企业客户接入文档 语雀

nesc 1.2 Language Reference Manual

Input from Files. Buffered Reader

Exposure to Sensor Motes

Exceptions Handling Errors using Exceptions

The Emergence of Networking Abstractions and Techniques in TinyOS

A VIRTUALLAB APPROACH FOR WIRELESS SENSOR MOTES AND WIRELESS SENSOR NETWORKS

Sensors Network Simulators

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja)

WSN Programming. Introduction. Olaf Landsiedel

Getting started with Java

1. Download the JDK 6, from

Undergraduate Research Project Portfolio. School of Engineering and Applied Sciences

Abstractions for Safe Concurrent Programming in Networked Embedded Systems

SwissQM: A Virtual Machine for Sensor Networks

IT101. File Input and Output

File Operations in Java. File handling in java enables to read data from and write data to files

TinyOS an operating system for sensor nets. Embedded Operating Systems

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

A sample print out is: is is -11 key entered was: w

2.6 Error, exception and event handling

nesc Prof. Chenyang Lu How should network msg be handled? Too much memory for buffering and threads

Wireless Embedded Systems and Networking. How to get TinyOS open source dist.

WSN Programming. Introduction. Olaf Landsiedel. Programming WSNs. ! What do we need to write software for WSNs?! Programming language

This resource describes how to program the myrio in C to perform timer interrupts.

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

Array. Array Declaration:

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Java Input/Output. 11 April 2013 OSU CSE 1

Group Members: Chetan Fegade Nikhil Mascarenhas. Mentor: Dr. Yann Hang Lee

Practical Exploitation of the Energy-Latency Tradeoff for Sensor Network Broadcast

Networking Level Laboratory Mote-Computer Serial Communication

CSPP : Introduction to Object-Oriented Programming

Data Structures. Home

Wireless Sensor Networks (WSN)

Motivation. Introduction to Wireless Sensor Networks. Office Building Fire. EEC173B Lecture:

ICU 58 SpoofChecker API Changes

6 System Processes Keyboard Command Decoder CRT Display... 26

Self-test Java Programming

Networked Embedded Software: Programming. Luca Mottola Politecnico di Milano, Italy and SICS Swedish ICT (home.dei.polimi.

Simulation of Sensor Network

Asynchronous Serial Communication Protocol (without Flow Control) using TLM 2.0 (Example of Non memory based protocol )

Internship at Sentilla. Chris Merlin March 08 - June 08

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Title Description Participants Textbook

16-Dec-10. Consider the following method:

ADHOC ROUTING BASED DATA COLLECTION APPLICATION IN WIRELESS SENSOR NETWORKS MALLIKARJUNA RAO PINJALA B.E, OSMANIA UNIVERSITY, INDIA, 2004 A REPORT

CS11 Java. Fall Lecture 4

Programming TinyOS. Lesson 3. Basic Structure. Main.nc

Politecnico di Milano Advanced Network Technologies Laboratory. TinyOS

A TEMPORAL MESSAGE ORDERING AND OBJECT TRACKING APPLICATION. by LAKSHMAN KAVETI

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

Authentication Layer

The nesc Language: A Holistic Approach to Networked Embedded Systems

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Java Review Outline. basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for

Question 1a) Trace of program

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

struct Properties C struct Types

GlobalLogic Technical Question Paper

09/08/2017 CS2530 INTERMEDIATE COMPUTING 9/8/2017 FALL 2017 MICHAEL J. HOLMES UNIVERSITY OF NORTHERN IOWA TODAY S TOPIC: Exceptions and enumerations.

EL6483: Brief Overview of C Programming Language

Software debouncing of buttons

Full file at Chapter 2 - Inheritance and Exception Handling

Advanced Java Programming. Networking

CSC 1214: Object-Oriented Programming

1.1 The hand written header file

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

Transcription:

Mobile and Ubiquitous Computing TinyOS application example Niki Trigoni www.dcs.bbk.ac.uk/~niki niki@dcs.bbk.ac.uk

Application Consider an application with the following functionality: The gateway node sets a timer to fire every X msecs (say X=500msecs) When the timer is fired the gateway node increments a counter by one (resetting it to 0 when it becomes 100) and does two things: It sends the counter value to the computer through the serial port. It broadcasts a message with the counter value. Other nodes within one hop from the gateway receive the gateway s message (with the gateway s counter value) and toggle the leds to reflect the counter value (CV). if CV < 30, toggle the red leds if 30 <= CV < 60, toggle the yellow leds if 60 <= CV <=100, toggle the green leds

Useful interfaces Leds Timer SendMsg ReceiveMsg parameterised interfaces A parameterized interface allows a component to provide multiple instances of an interface that are parameterized by a runtime or compile-time value. For more details read: http://www.tinyos.net/tinyos-1.x/doc/tutorial/lesson2.html. For example, the TimerC component provides 256 instances of the Timer interface, one for each uint8_t value: provides interface Timer[uint8_t id];

Useful components LedsC provides interface Leds; TimerC provides interface Timer [uint8_t id]; GenericComm provides interface SendMsg [uint8_t id]; provides interface ReceiveMsg [uint8_t id];

Message type We must declare the type (and structure) of the messages that will be sent and received in the application. Create a file BroadcastCount.h #ifndef BROADCAST_COUNT_H #define BROADCAST_COUNT_H enum { AM_COUNT_MSG = 100 ; typedef struct Count_Msg { uint16_t value; Count_Msg; #endif

Configuration BroadcastCountC includes BroadcastCount; configuration BroadcastCountC { Include the.h file that describes the message structure implementation { components Main, BroadcastCountM, LedsC, TimerC, GenericComm as Comm; Main.StdControl -> BroadcastCountM; Main.StdControl -> Comm.Control; BroadcastCountM.Leds -> LedsC; BroadcastCountM.ReceiveCountMsg -> Comm.ReceiveMsg [AM_COUNT_MSG]; BroadcastCountM.SendCountMsg -> Comm.SendMsg [AM_COUNT_MSG]; BroadcastCountM.CountTimer -> TimerC.Timer[unique("Timer")];

Radio handling What is the meaning of the following code? BroadcastCountM.SendCountMsg -> Comm.SendMsg[AM_COUNT_MSG] The GenericComm component provides 256 different instances of the SendMsg interface, one of which is SendMsg[AM_COUNT_MSG]. Messages have handler IDs that reflect their type. The messages of this application have handler ID AM_COUNT_MSG. BroadcastCountM uses the interface SendMsg (with the alias SendCountMsg), which is provided by GenericComm (with the alias Comm). GenericComm (with the alias Comm) provides interface instance SendMsg [AM_COUNT_MSG], which is used by BroadcastCountM to send messages of type AM_COUNT_MSG.

Module BroadcastCountM includes BroadcastCount; module BroadcastCountM { provides { interface StdControl; uses { interface SendMsg as SendCountMsg; interface Leds; interface ReceiveMsg as ReceiveCountMsg; interface Timer as CountTimer; implementation {

BroadcastCountM local variables includes BroadcastCount; module BroadcastCountM { implementation { uint16_t value; uint8_t serial=0; TOS_Msg message; uint16_t counter = 1; // value of the incoming counter message // flag that shows whether a message was just sent to // the serial port, or whether it was just broadcast // structure to store an outgoing or incoming message // value of the counter

BroadcastCountM provides StdControl implementation { // implementation of BroadcastCountM command result_t StdControl.init() { call Leds.init(); return SUCCESS; command result_t StdControl.start() { //Gateway if (TOS_LOCAL_ADDRESS==0) { call CountTimer.start( TIMER_REPEAT, 500 ); call Leds.redOn(); return SUCCESS;

BroadcastCountM provides StdControl // continued from previous page command result_t StdControl.stop() { //Gateway if(tos_local_address==0) { call CountTimer.stop(); call Leds.redOff(); return SUCCESS;

BroadcastCountM uses ReceiveMsg as ReceiveCountMsg event TOS_MsgPtr ReceiveCountMsg.receive (TOS_MsgPtr receivedmessage) { // if the current node is not the gateway if (TOS_LOCAL_ADDRESS!= 0) { Count_Msg * payload; payload = (Count_Msg *) receivedmessage->data; value = (uint16_t) payload->value; if (value<30) { call Leds.redToggle(); call Leds.greenOff(); call Leds.yellowOff(); else if (value>=30 && value<60) { else { return receivedmessage;

BroadcastCountM uses Timer as CountTimer event result_t CountTimer.fired() { Count_Msg * payload; call Leds.greenOn(); payload = (Count_Msg *) message.data; payload->value = counter; //BCAST for radio, UART for serial call SendCountMsg.send(TOS_UART_ADDR, sizeof(count_msg), &message); return SUCCESS;

BroadcastCountM uses SendMsg as SendCountMsg event result_t SendCountMsg.sendDone(TOS_MsgPtr sentmessage, result_t result) { if (serial==0) // if the senddone was signalled as a result of sending to the serial port { serial=1; call SendCountMsg.send(TOS_BCAST_ADDR, sizeof(count_msg), &message); else // if the senddone was signalled after broadcasting to neighbor nodes { serial=0; counter++; if(counter>100) counter=1; call Leds.greenOff(); return SUCCESS;

Java class ListenCount.java that reads messages from the serial port import net.tinyos.tools.*; import java.io.*; import net.tinyos.packet.*; import net.tinyos.util.*; import net.tinyos.message.*; public class ListenCount { public static void main(string args[]) throws IOException { PacketSource reader = BuildSource.makePacketSource(); if (reader == null) { System.err.println("Invalid packet source (check your MOTECOM environment variable)"); System.exit(2); // continued

Java class ListenCount.java that reads messages from the serial port // continued from last page try { reader.open(printstreammessenger.err); for (;;) { byte[] packet = reader.readpacket(); double first = (double)unsignedbytetoint(packet[11]); double second = (double)unsignedbytetoint(packet[10]); double light = 256.0d*first+second; System.out.println(light); System.out.flush(); catch (IOException e) { System.err.println("Error on " + reader.getname() + ": " + e); public static int unsignedbytetoint(byte b) { return (int) b & 0xFF;

How to run the application Go to the directory where the code of the application is Connect a sensor node to the serial port Write motelist. This command should return which port the sensor node uses to connect to the computer (say this is COM7) Write export MOTECOM=serial@COM7:tmote MOTECOM is an environment variable that Java uses to know which port it should listen to make tmote reinstall.0 // to install code to the gateway node make tmote reinstall.1 // to install code to another node run the ListenCount program to listen to the serial port