Shanghai Jiao Tong University-October 2016

Slides:



Advertisements
Similar presentations
TinyOS Tutorial, Part I Phil Levis et al. MobiSys 2003.
Advertisements

NesC Prepared for the Multimedia Networks Group University of Virginia.
Feb 2007WSN Training: First Steps in nesC Programming1 First Steps in TinyOS and nesC Programming Topics  Timer Application: MyApp  Application directory.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
Peek into TinyOS Programs Vinod Kulathumani. 2 Basics Application consists of one or more components assembled, or wired A component provides and uses.
TinyOS Applications Advanced Computer Networks. TinyOS Applications Outline  AntiTheft Example –LEDs, timer, booting  Sensing Example –Light Sensor.
INTRODUCTION TO TINYOS 2.X AND NESC. Anatomy of TelosB Mote  Limited computational and communication resources  MSP bit microcontroller 10kB RAM.
TinyOS Introduction Advanced Computer Networks. TinyOS Outline  Introduction to the Architecture of TinyOS and nesC  Component Model –Components, interfaces,
Systems Wireless EmBedded nesC Update Eric Brewer with help from David Culler, David Gay, Phil Levis, Rob von Behren, and Matt Welsh.
How to Code on TinyOS Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT.
7/13/2007AIIT Summer Course - D#1 Wireless Embedded Systems and Networking Lab Day 5: Part 1: TinyOS Programming on Open Source Distribution Jaein Jeong.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
June 2008 WEI Short Course TinyOS Timers 1 Wireless Embedded Intrer-Networking Foundations of Ubiquitous Sensor Networks Timers and System Resources David.
Operating Systems CS208. What is Operating System? It is a program. It is the first piece of software to run after the system boots. It coordinates the.
NesC: 1.1 Bumps and Future Directions David Gay, Intel Research, Berkeley (and the nesC and TinyOS teams)
Wednesday, July 15, Network Embedded Systems Mastermind: Prof. Koren.
Bugs in the Wires or, An Exercise in Language Design David Gay Intel Research Berkeley.
Installing software on personal computer
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
TinyOS 2.1 Jun Yi Partially based on the tutorial at IPSN 2009 By Stephen Dawson-Haggerty, Omprakash Gnawali, David Gay, Philip Levis, Răzvan Musăloiu-E.,
The 6713 DSP Starter Kit (DSK) is a low-cost platform which lets customers evaluate and develop applications for the Texas Instruments C67X DSP family.
1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using XServe to display the sensor data message on.
By: R Jayampathi Sampath
April 15, 2005TinyOS: A Component Based OSPage 1 of 27 TinyOS A Component-Based Operating System for Networked Embedded Systems Tom Bush Graduate College.
Architectures and Applications for Wireless Sensor Networks ( ) Sensor Node Programming II (UART and Radio) Chaiporn Jaikaeo
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
HW2: Q&A Oct. 02, Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign.
CIS 798 Sensor Network Implementation. Goals Learning sensor network programming with Crossbow motes Implement reasonable sized sensor applications Develop.
Lab 3 Introduction to TinyOS and nesC How to debug programs at PC Examples –Blink Timer –Blink –Hellow World Reference: 1.x/doc/tutorial/lesson1.html.
Simulation of Distributed Application and Protocols using TOSSIM Valliappan Annamalai.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 TinyOS & NesC.
Part 2 TinyOS and nesC Programming Selected slides from:
Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)
Report of Internship Summer 2007 Boivineau Samuel Antonio Ruzzelli – Raja Jurdak Gregory O'Hare.
Overview A wireless sensor network (WSN) is a wireless network consisting of spatially distributed autonomous devices using sensors to cooperatively monitor.
TinyOS Applications Advanced Computer Networks. TinyOS Applications Outline  AntiTheft Example {done in gradual pieces} –LEDs, timer, booting  Sensing.
Main Issues Three major issues that we are concerned with in sensor networks are – Clustering Routing and Security To be considered against the backdrop.
Lecture 5 Sensing 石致豪. Introduction Sense application SenseAppC.nc configuration SenseAppC { } implementation { components SenseC, MainC, LedsC, new.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
Network Components David Blakeley LTEC HUB A common connection point for devices in a network. Hubs are commonly used to connect segments of a LAN.
Architectures and Applications for Wireless Sensor Networks ( ) Sensor Network Programming and MoteLib Simulator Chaiporn Jaikaeo
LoCal Embedded IPv6 Bootcamp Stephen Dawson-Haggerty September 9, 2010.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Lab1: LED Control ZigbeX mote has Red, Yellow, Green LED. This lab using LED control component provided by TinyOS.
Feb 2007WSN Training: XMesh Enabled Sensor App1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using.
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
Testing and Verifiation of Kmote using Tiny OS Manish Aggarwal Guide :- Proff Purushottam K.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
A Practical Introduction to Sensor Network Programming Wireless Communication and Networked Embedded Systems, VT 2011 Frederik Hermans, Communication Research,
Tinyos Introduction to Programming Pritee Parwekar.
Introduction to the FPGA and Labs
Chapter Objectives In this chapter, you will learn:
Simulation of Distributed Application and Protocols using TOSSIM
Peek into TinyOS Programs
Programming Assignment
Operating System for Sensor Network
Lecture Topics: 11/1 Processes Process Management
Safe TinyOS.
TinyOS: Radio, Concurrent Execution, and Power control
David Gay Intel Research Berkeley
University of California, Berkeley AIIT Summer Course - Tu1 TOS2
ECE 544 Group Project : Routing
An Introduction to nesC
Lecture Topics: 11/1 General Operating System Concepts Processes
Embedded Operating Systems
Last Class: Communication in Distributed Systems
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

Shanghai Jiao Tong University-October 2016 TinyOS 2.1 Yanan Xu Shanghai Jiao Tong University-October 2016 1 1

What is TinyOS, NesC, Telosb TinyOS is an operating system for low power, embedded, wireless device Provide multiple components for user Only install necessary components to chip NesC is a programming language used in TinyOS Define components Wire components Telosb is a typical device we used Provide radio, leds, sensors etc on chip 2 2 2

Telosb device Reset Button USB Connector Internal Antenna LEDs 3 3 3

Programming Environment Install VirtualBox Start VirtualBox File -> import Virtual Applicance -> choose the system image Start

Programming Environment This is a virtual machine with Ubuntu OS User name: wcu Pass word: nosecurity Tiny OS programming environment has been set up in this machine

How to copy files Connect one USB disk to your computer Devices-> USB->USB disk

How to copy files Connect one USB disk to your computer Devices-> USB->USB disk USB disk appears

Tiny OS Places->computer->Filesystem->opt->tinyos- 2.x examples document Interfaces and libs

Example 1: Apps/Blink Convention used in the TinyOS source tree Blink is composed of two components: a module, called "BlinkC.nc", and a configuration, called "BlinkAppC.nc". Convention used in the TinyOS source tree File Name File Type Foo.nc Interface Foo.h Header File FooC.nc Public Module FooP.nc Private Module FooAppC.nc Configuration

Run Blink Run Blink demo Connect a mote to your computer VirtualBox: Devices->USB-> Telos

Run Blink Run Blink demo Connect a mote to your computer VirtualBox: Devices->USB-> Telos Open a terminal, Change the shell working directory to /opt/tinyos-2.x/apps/Blink/ Check mote : motelist Install program: make telosb install /dev/ttyUSB0

BlinkC.nc: a module BlinkC.nc BlinkAppC.nc

BlinkC.nc: a module

BlinkC.nc: a module Commands Events We can call commands provided by existing modules But we need to write codes for the Events function Events Events are triggered by some events, e.g. package arrives, timeout

BlinkC.nc: a module What do we need for letting a led light blink several times? Program entrance Led light Timer

Component : Module Modules are components that have variables and executable code Modules use interfaces Modules provide interfaces (not shown in the example) Use interface rename Excutable code

BlinkAppC.nc: a configuration Configurations are components that wire (->) other components together Some components system defined, some user defined A.B->C.B means: component A uses interface B, component C provides interface B Component A can call command of interface B, but must implement event of B Interface B implement its commands, provide event (like interrupt) for component who use it A.B->C.B is equivalent to: A.B->C, A->C.B, C<-A.B, C.B<-A B.B is a terrible but correct format. Remember former B is component, latter B is interface

Component : configuration User defined component Configuration wires BlinkC with other components (TimerMilliC, MainC, LedsC) BlinkC.Timer0->Timer0.Timer0 is correct but confusing Terrible rename A.B->C.B BlinkC Leds provides uses Timer0 Boot MainC TimerMilliC (Timer0)m LedsCm

Singletons and Generics Singleton components are unique: they exist in a global namespace Generics are instantiated: each instantiation is a new, independent copy configuration BlinkC { … } implementation { components new TimerC(); components BlinkC; BlinkC.Timer -> TimerC; } 19 19 19

Interfaces details Collections of related functions Define how components connect Interfaces are bi-directional: for A->B Commands are from A to B (implemented by B) Events are from B to A (implemented by A) Can have parameters (types) interface Timer<tag> { command void startOneShot(uint32_t period); command void startPeriodic(uint32_t period); event void fired(); } 20 20 20

Implementation of BlinkC.nc Use Boot Implement event booted Use Timer Call command startPeriodic Implement event fired Use Leds Call command led0Toggle()

Example 2: Mote-mote radio communication create a simple application that increments a counter, displays the counter's three least significant bits on the three LEDs, sends a message with the counter value over the radio. 

Interfaces Boot: start the device Timer: for timing SplitControl: start the radio AMSend: send a packet Receive: receive a packet Package: store the data Leds: turn on the LEDs or turn off the LEDs

Mote-mote radio communication We implement this application with two steps Implement Blink application A timer changes count variable Turn on or turn off the LEDs according to the count variable Add Radio communication part A mote send packets, and put the value of count in the packets A mote receive packets, get the count value, and turn on or turn off the LEDs according to the count

Step 1: Reimplementing Blink Four files

Reimplementing Blink File: BlinkToRadioC.nc #include <Timer.h> #include "BlinkToRadio.h" module BlinkToRadioC { uses interface Boot; uses interface Leds; uses interface Timer<TMilli> as Timer0; }

Reimplementing Blink File: BlinkToRadioC.nc implementation { uint16_t counter = 0; event void Boot.booted() { call Timer0.startPeriodic(TIMER_PERIOD_MILLI); } event void Timer0.fired() { counter++; call Leds.set(counter);

Reimplementing Blink File: BlinkToRadioAppC.nc #include <Timer.h> #include "BlinkToRadio.h" configuration BlinkToRadioAppC { } implementation { components MainC; components LedsC; components BlinkToRadioC as App; components new TimerMilliC() as Timer0; App.Boot -> MainC; App.Leds -> LedsC; App.Timer0 -> Timer0;

Reimplementing Blink File: BlinkToRadio.h #ifndef BLINKTORADIO_H #define BLINKTORADIO_H enum { TIMER_PERIOD_MILLI = 250 }; #endif

Reimplementing Blink File: Makefile COMPONENT=BlinkToRadioAppC Make telosb install /dev/ttyUSB0 Result: telosb will set the LEDs to the counter COMPONENT=BlinkToRadioAppC include $(MAKERULES)

Step 2: add radio communication Procedure of Sending a message Start device Control.start() Check if start success Define a packet, get the pointer of its PayLoad Packet.getPayload(&packet, user_message_size) Fill the payload Send the packet AMSend.send(destination, &packet, size) Procedure of receiving a message Receive packets with Receive.receive event Get the payload of the packet Set the LEDs to the counter number just received with Leds.set

Add Radio communication part File: BlinkToRadio.h Comment out and add ... enum { AM_BLINKTORADIO = 6, TIMER_PERIOD_MILLI = 250 };

Add Radio communication part File: BlinkToRadioC.nc add module BlinkToRadioC { ... uses interface Packet; uses interface AMSend; uses interface SplitControl as AMControl; uses interface Receive; }

Add Radio communication part File: BlinkToRadioC.nc add implementation { bool busy = FALSE; message_t pkt; ... }

Add Radio communication part File: BlinkToRadioC.nc Comment out and add event void Boot.booted() { //call Timer0.startPeriodic(TIMER_PERIOD_MILLI); call AMControl.start(); }

Add Radio communication part File: BlinkToRadioC.nc Comment out and add event void AMControl.startDone(error_t err) { if (err == SUCCESS) { call Timer0.startPeriodic(TIMER_PERIOD_MILLI); } else { call AMControl.start(); event void AMControl.stopDone(error_t err) {}

Add Radio communication part File: BlinkToRadioC.nc Comment out and add event void Timer0.fired() { counter++; //call Leds.set(counter); if (!busy) { BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, sizeof (BlinkToRadioMsg))); btrpkt->nodeid = TOS_NODE_ID; btrpkt->counter = counter; if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(BlinkToRadioMsg)) == SUCCESS) { busy = TRUE; }

Add Radio communication part File: BlinkToRadioC.nc Comment out and add event void AMSend.sendDone(message_t* msg, error_t error) { if (&pkt == msg) { busy = FALSE; }

Add Radio communication part File: BlinkToRadioC.nc Comment out and add event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) { if (len == sizeof(BlinkToRadioMsg)) { BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload; call Leds.set(btrpkt->counter); } return msg;

Add Radio communication part File: BlinkToRadioAppC.nc Comment out and add implementation { ... components ActiveMessageC; components new AMSenderC(AM_BLINKTORADIO); components new AMReceiverC(AM_BLINKTORADIO); }

Add Radio communication part File: BlinkToRadioAppC.nc Comment out and add implementation { ... App.Packet -> AMSenderC; App.AMSend -> AMSenderC; App.AMControl -> ActiveMessageC; App.Receive -> AMReceiverC; }

Test the application! $ motelist $ make telosb install, 1 /dev/ttyUSB0 $ make telosb reinstall, 2 /dev/ttyUSB0

Assignment 2 Mote-mote radio communication One mote as master node, others as slave node Show how many motes communicate with the master node Use the LEDs to show the number of motes

Grading scheme Sensor nodes can communicate with each other. 20% When a node connect to the master node, LEDs should be set to old number plus one. 40% When a node is shut down, LEDs should be set to old number minus one. 40% Code quality. 10%

Submission Face to face demo Codes Report Deadline November 18, Friday

Reference http://tinyos.stanford.edu/tinyos- wiki/index.php/TinyOS_Tutorials https://people.eecs.berkeley.edu/~culler /papers/ai-tinyos.pdf

THE END