introduction to spot

Post on 25-May-2015

5.748 Views

Category:

Business

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Share is good. if youhave any question, feel free to ask me: pdeng -a- pgrad dot unimelb dot edu dot au.

TRANSCRIPT

Introduction to SPOT

Programming the Real-world

Peng Dengpdeng@students.csse.unimelb.edu.au

CSSE University of MelbourneLabSUM∑

2

Agenda• Introduction

– Sensor Architecture– WSN Characteristics– WSN Applications

• SPOT– What is SPOT– Microsoft vs. Sun

• Sun SPOT– Applications– Hardware features and code samples

• Conclusion

• Q&A and Demos

• Reference

3

Introduction: Sensor Networks• WSN (Wireless Sensor Network) is a wireless network consisting of

spatially distributed autonomous devices using sensors to cooperatively monitor physical or environmental conditions. [1]

4

CommunicationProcessing Element

Architecture of Sensor

Sensing Element

P S O U W PE PR L

Y

SENSORS

ADC MICRO

PROCESSOR

MEMORYRADIO

REAL TIME OS

ALGORITHMS

Limited Lifetime

Require Supervision Slow

Processing

Limited Memory

1 kbps – 1 Mbps, 3 – 100 m, Lossy

Transmission

[2]

5

Characteristics of WSN

• Small-scale sensor nodes• Limited power they can harvest

or store• Harsh environmental

conditions• Node failures• Mobility of nodes• Dynamic network topology• Communication failures• Heterogeneity of nodes• Large scale of deployment• Unattended operation

[1]

6

Application Domain

• Environmental monitoring

• Security

• Defence

• Bioinformatics and health

• Transportation management

• Chemical detection and emergency response

Pictures from [3]

[2]

7

Learn more about WSN…

• 433-654 Sensor Networks and Applications

• The subject is provided every semester 1

• Lecturer is Dr Egemen Tanin

8

SPOT

• What is SPOT?

– According to my understanding, SPOT is a technology that pushes popular desktop application frameworks and programming languages to embedded systems.

Small Programmable Object TechnologySun VersionSun Version

Smart Personal Objects TechnologyMicrosoft VersionMicrosoft Version

9

SPOT Cake

Advantages:1. Much more portable

code2. Easier to learn3. Free to use4. Rapid develop5. Safer

Disadvantages:1. Less flexibility2. More resource needed

• Memory• CPU• Battery

3. Slower execution speed

Microsoft .Net Micro FrameworkSun Java Squawk Virtual Machine

Freescale chips

TI chips

ARMchips

Applications

…Different hardware

platforms

OS

10

.Net Micro Framework [4]

11

.Net Micro Framework

Signed application Public- private key pairXTEA Symmetric keyRSA

SecuritySecurity

USB or SerialCommunicationCommunication

1MBMinimum FlashMinimum Flash

300KBMinimum RAMMinimum RAM

ARM7 and ARM9PlatformPlatform

Metadata Processor reduces size of assembliesMetadataExecutable fileExecutable file

Not known for sensor environmentYesEmulationEmulation

NoRealReal--timetime

Without XAMLFor Windows Sidebar

WPFUser interfaceUser interface

Work with or without OSYesBootableBootable

Express Edition is not availableVisual Studio 2005IDEIDE

C#LanguageLanguage

http://msdn2.microsoft.com/en-us/embedded/bb404168.aspxOpen to partners onlyOpen sourceOpen source

First release2.0 BETAVersionVersion

[4]

12

Squawk Virtual Machine

A Java Virtual Machine written in Java!Extended from J2ME

[5]

13

Squawk Virtual Machine

Signed application, RSASecuritySecurity

USB or SerialCommunicationCommunication

380KBMinimum FlashMinimum Flash

80KBMinimum RAMMinimum RAM

ARM7 and ARM9PlatformPlatform

Support process migration 35% - 45% size of equivalent J2ME class filesMultiple applications run concurrently

Optimized bytecode.suit

Executable fileExecutable file

NoEmulationEmulation

NoRealReal--timetime

NoUser interfaceUser interface

Work with or without OSYesBootableBootable

Companion with NetBeans moduleFree

NetBeans 5.0IDEIDE

JavaLanguageLanguage

Open source in futureSource code available in SDKOpen sourceOpen source

Second release (CLDC 1.1-compatible)Codename: Orange, PurpleVersionVersion

[6] [7]

14

Sun SPOT

• 3-axis accelerometer• Temperature sensor• Light sensor• LEDs• Analog inputs• Switches• General purpose I/O

Embedded sensorsEmbedded sensors

2.4 GHz IEEE 802.15.4 radiowith integrated antenna

RadioRadio

512K RAM/4M FlashMemoryMemory

180 MHz 32 bit ARM920TCPUCPU

32 uADeep sleepDeep sleep

720 mAh lithium-ion batteryBattery capacityBattery capacity

Sun SPOTPlatformPlatform

NetBeans 5.0IDEIDE

JavaProgramming LanguageProgramming Language

Sun Java Squawk VMFrameworkFramework

[7] [8]

15

Crossbow Imote2

Daughter board:IIB2400 – Imote2 InterfaceITS400 sensor board• 3-Axis Accelerometer• Temperature, Humidity, • and Light Sensors• Analog Input

Embedded sensorsEmbedded sensors

Integrated 802.15.4 RadioRadioRadio

256kB SRAM, 32MB FLASH, 32MB SDRAM

MemoryMemory

PXA271 XScale® Processor at 13–416MHz

CPUCPU

390 uADeep sleepDeep sleep

N/ABattery capacityBattery capacity

Imote2PlatformPlatform

Visual Studio 2005IDEIDE

C#Programming LanguageProgramming Language

Microsoft .Net Micro Framework

FrameworkFramework

[9] [10]

16

Sun SPOT

17

Sun SPOT Applications [7]

18

Sun SPOT Hardware

Antenna

2.4 GHz IEEE 802.15.4 Radio Module

180 MHz 32 bit

ARM920T core512K RAM4M Flash

Daughter board connector

Power Switch

USB interface with mini-B connector

[7] [11]

19

Sun SPOT Hardware8 3-colors LEDs Push Buttons

Light Sensor 3-D

Accelerometer

Analog in 4-5

Push ButtonsReplicated here

"High" current output 0-3Digital I/O 4

Digital I/O 0-3 Analog in 0-3

Temperature sensor andA/D Converter

[7] [11]

20

Time Issues

• Timer and Counter– Chip: AT91 Timer/Counter * 2 on ARM920T @ Processor Board– 6 Timer Counter Channel = 4 available + 2 system use– 2 modes: Capture & Waveform– Functions: frequency measurement, event counting, interval measurement, pulse generation,

delay timing and pulse width modulation. – Interface defined at com.sun.spot.peripheral.TimerCounterBits.java

• Time Synchronization– Affect security if the time difference is more than 3 minutes– 3 minutes off after 104 days– Synchronize time when connect SPOT to Host using USB

[19] [14]

21

Time issues: Example 1

• Measuring a Time Interval

import com.sun.spot.peripheral.*;import com.sun.spot.util.*;

public class TimerCounterSample implements TimerCounterBits {public double measureInterval() {IAT91_TC timer = Spot.getInstance().getAT91_TC(0); // Get a Timer Countertimer.configure(TC_CAPT | TC_CLKS_MCK32); // Use fast clock speedtimer.enableAndReset(); // Start counting... ... interval to measure interval to measure ......int cntr = timer.counter(); // Get number of elapsed clock tickstimer.disable(); // Turn off the counterdouble interval = cntr * 0.5342; // Convert to time in microsecondsreturn interval;}

}

22

Time issues: Example 2

• Perform a Periodic Taskimport com.sun.spot.peripheral.*;import com.sun.spot.util.*;

public void periodicTask() {IAT91_TC timer = Spot.getInstance().getAT91_TC(0); // Get a Timer Counterint cnt = (int)(25000 / 0.5342); // number of clock counts for 25 msecstimer.configure(TC_CAPT | TC_CPCTRG | TC_CLKS_MCK32); // enable RC comparetimer.setRegC(cnt);timer.enableAndReset();

while (true) { // Start periodic task looptimer.enableIrq(TC_CPCS); // Enable RC Compare interrupttimer.waitForIrq(); // Wait for interrupttimer.status(); // Clear interrupt pending flagdoTask(); // Method will be called every 25 msecs

}}

23

Memory

• Spansion S71PL032J40

• 512K RAM– Garbage Collector in VM– 0x20000000 to 0x20080000

• 4M Flash– 0x10000000 to 0x10400000

Available for data storage2Mb0x10200000

Application slot 2384Kb0x101A0000

Your application is deployed here. Error throws if application too big.

Application slot 1384Kb0x10140000

Large compare to TinyOSSquawk VM executable256Kb0x10010000

RemarksUseSizeStart Address

24

Memory: Access to Flash

• Record Management System1. RecordStore rms = RecordStore.openRecordStore("TEST", true);2. byte[] inputData = new byte[]{12,13,14,15,16};3. int recordId = rms.addRecord(inputData, 0, inputData.length);4. byte[] outputData = rms.getRecord(recordId);5. rms.closeRecordStore();

• IFlashMemoryDevice (low level)1. /* use stream to read and write is safer. */2. IFlashMemoryDevice mem = Spot.getInstance().getFlashMemoryDevice();3. IFlashMemoryDevice mem = Spot.getInstance().getFlashMemoryDevice();4. int startSector = mem.getFirstAvailableSector();5. DataOutputStream dos = new DataOutputStream(mem.getOutputStream(startSector, 2));6. dos.writeUTF("hello there");7. dos.flush();8. DataInputStream dis = new DataInputStream(mem.getInputStream(startSector, 2));9. String s = dis.readUTF();

25

Radio

• ChipCon CC2420

• PAN (802.15.4) – ISM band 2.4GHz– Zigbee is not implemented yet, but you can built it by yourself

• Address– IEEE extended MAC Address– 64 bit, like 0014.4F01.0000.026A0000.026A

• Ports– 0~255– 0~31 are reserved for system use

26

Radio

• Radio Stream– Stream-based– Reliable (acknowledgement)– Buffered– P2P

• Radiogram– Datagram-based– No guarantees about delivery or ordering– Broadcast supported– C/S– Stream like but limit in size

27

Radio Stream

• Radio Stream

1. RadiostreamConnection conn = (RadiostreamConnection) Connector.open("radio://0014.4F01.0000.0006:100");

2. DataInputStream dis = conn.openDataInputStream(); 3. DataOutputStream dos = conn.openDataOutputStream(); 4. try { 5. dos.writeUTF("Hello up there"); 6. dos.flush(); // send over the air7. System.out.println ("Answer was: " + dis.readUTF()); 8. } catch (NoRouteException e) { 9. System.out.println ("No route to 0014.4F01.0000.0006"); 10. } finally { 11. dis.close(); 12. dos.close(); 13. conn.close(); 14. }

28

Radiogram

• Client

1. RadiogramConnection conn = RadiogramConnection)Connector.open("radiogram://0014.4F01.0000.0006:100");

2. Datagram dg = conn.newDatagram(conn.getMaximumLength()); 3. try { 4. dg.writeUTF("Hello up there"); 5. conn.send(dg); 6. conn.receive(dg); 7. System.out.println ("Received: " + dg.readUTF()); 8. } catch (NoRouteException e) { 9. System.out.println ("No route to 0014.4F01.0000.0006"); 10. } finally { 11. conn.close(); 12. }

29

Radiogram

• Server

1. RadiogramConnection conn = (RadiogramConnection) Connector.open("radiogram://:100"); 2. Datagram dg = conn.newDatagram(conn.getMaximumLength()); 3. Datagram dgreply = conn.newDatagram(conn.getMaximumLength()); 4. try { 5. conn.receive(dg); 6. String question = dg.readUTF(); 7. dgreply.reset(); // reset stream pointer 8. dgreply.setAddress(dg); // copy reply address from input 9. if (question.equals("Hello up there")) { 10. dgreply.writeUTF("Hello down there"); 11. } else { 12. dgreply.writeUTF("What???"); 13. } 14. conn.send(dgreply); 15. } catch (NoRouteException e) { System.out.println ("No route to " +

dgreply.getAddress()); } finally { 16. conn.close(); 17. }

30

Radiogram

• Broadcast– Transmitted over two hops by default

– Not reliable– Drop duplicated message

1. DatagramConnection conn = DatagramConnection)Connector.open("radiogram://broadcast:<portnum>");

2. ((RadiogramConnection)conn).setMaxBroadcastHops(3);

31

Sensors

• 2G/6G 3-axis accelerometer • Temperature sensor • Light sensor • 8 tri-color LEDs• 2 momentary switches• 6 analog inputs• 5 general purpose I/O pins and 4 high

current output pins

32

3-axis Accelerometer

General purpose. Depends on developers’ implementation

Carefully tuned to optimize performance in determining hand and arm motion

PurposePurpose

250~30050Acceleration Noise DensityAcceleration Noise Density

850 uA @ 3.3 VSleep mode support

300 uA @ ~3VPower consumptionPower consumption

+/- 2G (600 mv/g)+/- 6G (200 mV/g)

+/- 3 G (300 mv/g)Range & SensitivityRange & Sensitivity

USD $10.82USD $8.97PricePrice

ST Microsystems LIS3L02AQAnalog Devices ADXL330 ChipChip

Sun SPOT [18]Wii Remote Controller [17]

Hzg /µ Hzg /µ

33

3-axis Accelerometer

1. import com.sun.spot.sensorboard.EDemoBoard;2. import com.sun.spot.sensorboard.peripheral.IAccelerometer3D;

3. private IAccelerometer3D accel = EDemoBoard.getInstance().getAccelerometer();

4. int tiltX = (int)Math.toDegrees(accel.getTiltX()); // returns [-90, +90]5. double GForceX = accel.getAccelX();

34

Temperature sensor

• Analog Devices ADT7411

• -40℃ to +125 ℃• Accuracy±0.5 ℃

• Actually, it is reading the temperature of this chip

• Warmer when you connect to USB• Connect a external thermistor to A/D to get more

accurate reading

35

Temperature sensor

1. import com.sun.spot.sensorboard.EDemoBoard;2. import com.sun.spot.sensorboard.io.ITemperatureInput;

3. private ITemperatureInput tempSensor = EDemoBoard.getInstance().getADCTemperature();

4. double tempF = tempSensor.getFahrenheit(); // The value converted to Farenheight5. double tempC = tempSensor.getCelsius(); // The value converted to Celcius

• The API will change to getADCTemperaturegetADCTemperature()().

36

Light sensor

• Toshiba TPS851• Peak sensitivity wavelength is 600nm

• Too sensitive, flickering• Take off “sun roof” to get more accurate

reading

37

Light sensor

1. import com.sun.spot.sensorboard.EDemoBoard;2. import com.sun.spot.sensorboard.peripheral.ILightSensor;

3. private ILightSensor lightSensor = EDemoBoard.getInstance().getLightSensor();

4. int lightLevel = lightSensor.getValue();

38

8 tri-color LEDs1. /* i is the index of each LED, from 0 to 7. */

2. import com.sun.spot.sensorboard.EDemoBoard;3. import com.sun.spot.sensorboard.peripheral.ITriColorLED;4. import com.sun.spot.sensorboard.peripheral.LEDColor;

5. private ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();

6. leds[i].setOff(); // turn off LED

7. leds[i].setRGB(int red, int green, int blue ); // set color8. leds[i].setColor(LEDColor.MAGENTA); 9. leds[i].setOn(); // turn on LED

39

2 Momentary Switches 1. import com.sun.spot.sensorboard.EDemoBoard;2. import com.sun.spot.sensorboard.peripheral.ISwitch;

3. private ISwitch sw1; 4. sw1 = EDemoBoard.getInstance().getSwitches()[0]; 5. startSW1WatchThread();

6. public void startSW1WatchThread(){7. Runnable r = new Runnable(){8. public void run(){9. while(true){10. sw1.waitForChange();11. if(sw1.isClosed()){12. System.out.println("Switch 1 closed.");13. } else {14. System.out.println("Switch 1 opened.");15. }16. }17. }18. };19. (new Thread(r)).start();20. }

In next major update, the switch API will change to buttonListener like.

40

Networking

• Using basestation

• Mesh routing– Act as a mesh router, forwarding packets to other SPOTs– Enabled when you start radio connection

• Trace route– Act as a trace route server– Participate in route tracing request

• Logging– Diagnostic use– Display all network route discovery and route management activity

• You can implement algorithms by your hand

HostSun SPOT

(“base station mode”)Sun SPOT

(“target”)USB

802.15.4 radio

Over the Air deploy

[11]

41

Battery

• The most important property in WSN!– Radio communication is very hungry– Multi-hop communication is desired

• 3.7V 720 mAh lithium-ion battery

3 hoursShallow sleep, 8 LEDs on, no radio

7 hoursCPU busy, radio on

8.5 hoursCPU busy, no radio

15 hours15 hoursShallow sleep, radio onShallow sleep, radio on

23 hoursShallow sleep, no radio

909 daysDeep sleep

Battery life estimateSun SPOT State

[12]

42

Battery1. IPowerController ipc = Spot.getInstance().getPowerController();

2. ipc.getVbatt(); // The reply is in millivolts and is nominally inthe range 2700- 47003. ipc.getIdischarge(); // current being drawn from the battery in mA4. ipc.getIcharge(); // charging current in mA5. ipc.getIMax(); // maximum current drawn from the battery since last time this was called

• One solution to short battery: – Attach SUN SPOT to a USB charger on the wall, tradeoff is

mobility.

[20]

43

SDK and develop steps

1. Install JDK, Neteans, Sun SPOT SDK and drivers

2. Create Sun SPOT project or Sun SPOT Host project

3. Compose your application

4. Connect, compile and deploy application to SPOT

5. Working!

Get more information on http://www.sunspotworld.com/

44

Conclusion

• Suitable:– Rapid prototype development– Experiment– Education

• Not ready to commercial solution– Lacks support– Constraints

• Future development– Open source– Get support from sensor providers like J2ME supported by

mobile phone Companies– …

Q & A

46

Demos

Pictures from [15] [16]

47

Appreciate

• Dr. Lars Kulik (http://www.csse.unimelb.edu.au/~lars/)

• Dr. Egemen Tanin (http://www.csse.unimelb.edu.au/~egemen/)

• All members in SUM Research Lab (http://www.sumlab.net/)

48

Reference1. Wireless sensor network. (2007, July 25). In Wikipedia, The Free Encyclopedia. Retrieved 08:10, July 28, 2007, from

http://en.wikipedia.org/w/index.php?title=Wireless_sensor_network&oldid=146970785

2. Digest from Egemen’s slides in 433-654, http://www.cs.mu.oz.au/654/, et_week1a.ppt

3. David E. Culler and Hans Mulder (2004, June). Smart Sensor to Network the World. Scientific American, 85-91.

4. Microsoft .NET Micro Framework White Paper. Retrieved 08:30, July 28, 2007, from http://download.microsoft.com/download/a/9/c/a9cb2192-8429-474a-aa56-534fffb5f0f1/.net%20micro%20framework%20white%20paper.doc

5. SquawkVM, Retrieved 08:40, July 28, 2007, from http://research.sun.com/projects/squawk/figures/SquawkVM.jpg

6. Squawk homepage, Retrieved 08:50, July 28, 2007, from http://research.sun.com/projects/squawk/

7. projectsunspot, Retrieved 08:55, July 28, 2007, from http://www.flickr.com/photos/projectsunspot/

8. Project Sun SPOT Product, Retrieved 09:00, July 28, 2007, from http://www.sunspotworld.com/products/

9. WSN .Imote2 Builder, Retrived 09:10, July 28,2007, from http://www.xbow.com/Products/Product_images/Wireless_images/Imote2_Kit.jpg10. IPR2400 Datasheet, Retrived 09:13, July 28, 2007, from http://www.xbow.com/Products/Product_pdf_files/Wireless_pdf/Imote2_Datasheet.pdf

11. Sun SPOT SDK Version Orange, Developers’ Guide

12. Sun SPOT SDK Version Orange, Owners Manual

13. Sun SPOT SDK Version Orange, CodeSamples

14. Synchronizing time between spot and host, Retrieved 12:00, July 28, 2007, from http://www.sunspotworld.com/forums/viewtopic.php?t=557&start=0&postdays=0&postorder=asc&highlight=

15. Balance.org, shotsbig_01.jpg, Retrieved 13:09, July 30, 2007 from http://www.ballance.org/ImagesX/shots/shotsbig_01.jpg

16. Robert Kooima, screen-5.jpg, Retrieved 13:11, July 30, 2007 from http://offload2.icculus.org/neverball/screen-5.jpg

17. ADXL330 Small, Low Power, 3-Axis ±3g iMEMS® Accelerometer, Analog Device Inc. Retrived 10:28, 8 Aguuest, 2007, from http://www.analog.com/en/prod/0,2877,ADXL330,00.html

18. LIS3L02AQ3 DataSheet, ST Microsystems Inc. Retrived 10:30, 8 Aguuest, 2007, from http://www.st.com/stonline/products/literature/ds/11020/lis3l02aq3.pdf

19. Using the AT91 Timer/Counter, Ron Goldman, Sun Labs, Retrived 21:52, 8 March, 2008 from https://www.sunspotworld.com/docs/AppNotes/TimerCounterAppNote.pdf

20. black.jpg, http://www.trekstor.de/, Retrieved 22:18, 8 March, 2008 from http://www.trekstor.de/dyn_files/products/usb-charger_em/detail/black.jpg

49

Peng DengMEDC Student

SUM Research LabCSSE University of Melbourne

pdeng@students.csse.unimelb.edu.au

Thank you

50

Revision History

Added: Timer and CounterModified: Battery

8 March 2008

Initial Version8 Aug 2007

top related