Documente Academic
Documente Profesional
Documente Cultură
!epartment of Computer Science Aalborg "niversit# Se(ma )arger(*&s +e, %00 -220 a(.org /hone -0 %$ 10 10 2a3 -0 %$ -# -1 http455""".cs.aau.6!
Abstract: 7o" 6a8s, the rapi6 progress o& techno(og8 are .ecoming it increasing(8 a&&or6a.(e an6 the8 are no" present in man8 p(aces o& our 6iar8 (i&e. One e3amp(e o& that is !no"n as Homeautomation 9a(so ca((e6 Domotics:. The computationa( po"er o& home app(iances is constant(8 increasing, an6 the "ire(ess net"or!s are a(rea68 present in man8 homes. (( this a((o"s home sensors an6 6e;ices to "or! in an autonomous(8 an6 inte((igent "a8, in or6er to ma!e the home more com&orta.(e, secure an6 a.(e to sa;e the ma3imum energ8 than e;er "as possi.(e. The <ome/ort pro,ect is a co((a.oration .et"een =entre &or Em.e66e6 So&t"are S8stems 9=>SS: at a(.org uni;ersit8 an6 =entre &or So&t"are >nno;ation 9=S>: at arhus uni;ersit8. >t is an on-going research pro,ect that &ocus on esta.(ishing interopera.i(it8 .et"een e3isting 6omotic 6e;ices &rom 6ierent ;en6ors. >n this report > 6e;e(op a mo.i(e app(ication "hich is a.(e to manage a .ui(6ing e?uippe6 "ith a <ome/ort ser;er. This ;ersion can interact remote(8 "ith the home 6e;ices an6 ma!e the house .eha;es in the "a8 the user "ish accor6ing to the e;ents that "ere happen on itse(&.
Period: SSE4, Spring semester 2011 Author: Mario Muoz Sanz Supervisor: rne S!o"
Circulation: 4 Number of pages: #$ Number of Appendixes: % inished on: 14th o& 'une, 2011
The contents of this report is freely available, however, publication (with source of reference) is only allowed in agreement with the authors.
Preface
This report has .een "ritten .8 Mario Muoz Sanz, guest stu6ent in the 4 th semester o& So&t"are S8stem Engineering in a(.org @ni;ersit8. This report is a66resse6 to other stu6ents, super;isors an6 an8one e(se "ho might .e intereste6 in the su.,ect. To rea6 an6 un6erstan6 the report correct(8,. >t is necessar8 to ha;e .asic !no"(e6ge a.out computer re(ate6 terms. The "ho(e report is "ritten in Eng(ish. ..re;iations an6 acron8ms "i(( at &irst appearance .e "ritten in parenthesis, to a;oi6 .rea!ing the rea6ing stream. Ae&erences to sources are mar!e6 .8 BCD, "here C re&ers to the re(ate6 (iterature in the .i.(iograph8 at the en6 o& the report. >t has .een "ritten in OpenO&&ice.org Eriter an6 consists o& si3 chapters an6 % appen6i3es "hich can .e &oun6 in the (ast chapter o& the report. The Ec(ipse >DE has .een use6 to 6e;e(op the source co6e o& a(( the pro,ect. "e. a66ress is pro;i6e6 as support materia( inc(u6ing the source co6e o& the "ho(e Ec(ipse pro,ect4 http4556(.6rop.o3.com5u5%2-1-015DomoticsF20On-The-GoF202.0.rar
Contents
1Introduction........................................................................................................................................9 1.1Motivation ................................................................................................................................10 1.2Problem statement.....................................................................................................................13 1.3Report structure.........................................................................................................................13 2Bac !round.......................................................................................................................................14 2.1"ommunication protocols.........................................................................................................14 2.1.1#$10...................................................................................................................................14 2.1.2"$Bus.................................................................................................................................15 2.1.3%$&ave..............................................................................................................................1' 2.1.4%i!Bee...............................................................................................................................1( 2.1.5I) *omecontrol................................................................................................................19 2.1.6+,#..................................................................................................................................19 2.2*omePort..................................................................................................................................20 2.2.1-evice .a/er.....................................................................................................................21 2.2.2Brid!e la/er.......................................................................................................................22 2.2.30ervice .a/er....................................................................................................................22 2.2.4"omposition .a/er............................................................................................................23 2.2.512ample.............................................................................................................................23 33nal/sis............................................................................................................................................25 3.13pplication re4uirements..........................................................................................................25 3.2Plat5orm ...................................................................................................................................26 3.2.1i)0 versus 3ndroid...........................................................................................................2' 3.2.23ndroid.............................................................................................................................2' 3.2.2.13rc6itecture...............................................................................................................2( 3.2.2.23ctivit/ li5e c/cle......................................................................................................29 3.2.2.30ervices.....................................................................................................................30 3.2.2.43ndroid desi!n in7uences.........................................................................................31 3.2.2.5Persistence.................................................................................................................32 3.3R108 arc6itecture.....................................................................................................................32 3.40ecurit/.....................................................................................................................................33 0ecure 0oc et .a/er..................................................................................................................34 3.5-evice access............................................................................................................................35 3.60cenarios considered.................................................................................................................36 3.6.1&6en it is 9ind/...............................................................................................................3' 3.6.2&6en it is rain/.................................................................................................................3' 3.6.3-ependin! on t6e presence...............................................................................................3' 3.6.4-ependin! on t6e outdoor li!6t.........................................................................................3' 3.6.5Indoor li!6t level mana!ement..........................................................................................3( 3.6.68emperature mana!ement.................................................................................................3( 4-esi!n...............................................................................................................................................39 4.1-evice list parsin!....................................................................................................................39 4.2-evice interaction.....................................................................................................................40 4.2.1-evice access....................................................................................................................41 4.3:ser inter5ace............................................................................................................................42 4.3.1Main screen.......................................................................................................................42 4.3.20ettin! screen....................................................................................................................42 4.3.3"onnect screen..................................................................................................................43 4.3.4Pro5ile screens...................................................................................................................45
4.40ecurit/.....................................................................................................................................46 4.5"ommunication mana!er..........................................................................................................4' 4.6Persistence mana!er..................................................................................................................4' 4.'3utomation service...................................................................................................................4( 4.(0ummar/...................................................................................................................................4( 5Implementation.................................................................................................................................49 5.1Main 3ctivit/............................................................................................................................49 5.2;:I...........................................................................................................................................50 5.3Pro5Man....................................................................................................................................59 5.4*ttp"lient .................................................................................................................................60 5.5"ontrol service..........................................................................................................................61 5.6Implementation tests.................................................................................................................63 6"onclusions......................................................................................................................................66 6.1<uture 9or ...............................................................................................................................66 3ppendi2 3= ,et9or #M. description............................................................................................6( 3ppendi2 B= 04lPro5iles.>ava.............................................................................................................'1 3ppendi2 "= M/*ttp"lient.>ava.........................................................................................................'2
$ %ntroduction
7o" a 6a8s the techno(og8 impro;es an6 e;o(;es &aster than e;er. The num.ers o& transistors that can &it a s?uare inch, or the amount of information capable of being stored by an electronic memory increases each 8ear an6 hence e(ectronic 6e;ices get sma((er an6 sma((er. This 6e;e(opment is o& great importance &or sensor no6es since their actua( size can 6etermine i& the8 can .e app(ie6 in a speciHc conte3t. n e3amp(e cou(6 .e a natura( ha.itat, "here the miniaturization o& the sensor no6es a((o" us to co((ect 6ata in a non intrusi;e "a8. >n this scenario tin8, a(most in;isi.(e sensors .ecome essentia( in terms o& getting accurate 6ata "ithout inter&ering "ith the norma( (i&e o& the anima(s or po((uting the area. Ioth sensor net"or!s "ire6 or "ire(ess, are increasing(8 present in our homes un6er the name o& <ome utomation 9a(so ca((e6 6omotics:. The computationa( po"er o& home app(iances is increasing, an6 the a6option o& "ire(ess net"or!s is "i6esprea6 in man8 homes. This tren6 is gro"ing an6 opens a potentia( to ha;e other"ise iso(ate6 home app(iances communicate an6 co((a.orate in a semi-inte((igent "a8, here.8 a66ing com&ort, sa&et8 an6 resource optimization to our homes. >n 1-00 'im Suther(an6, an engineer "or!ing &or Eestinghouse E(ectric, 6e;e(ope6 a home automation s8stem ca((e6 JE=<O >+JK this "as a pri;ate pro,ect an6 ne;er commercia(ize6. Eith the in;ention o& the micro-contro((er, the cost o& e(ectronic contro( &e(( rapi6(8. Aemote an6 inte((igent contro( techno(ogies "ere a6opte6 .8 the .ui(6ing ser;ices in6ustr8 an6 app(iance manu&acturers "or(6"i6e. The &irst con;incing e3amp(e o& a home automation s8stem "as create6 in 1--$ .8 Ii(( Gates - the &oun6er o& Microso&t. >n 1--$, this "as a ;er8 e3pensi;e insta((ation (imite6 to ;er8 &e" peop(e. (ot has change6 since 1--$ in terms o& computing po"er, an6 size o& computer 6e;ices. The technica( e;o(ution in the e(ectronic in6ustr8 together "ith an increasing 6eman6 &rom the consumer mar!e6 has (ea6 to &aster, sma((er an6 cheaper computers. To6a8, "e &in6 man8 sma(( computers seam(ess(8 em.e66e6 into man8 o& our common househo(6 app(iances. Their programma.(e micro-contro((ers has t8pica((8 rep(ace6 their mechanica( counterpart as contro( 6e;ices, here.8 pro;i6ing more a6;ance6, L&(e3i.(e an6 user&rien6(8 contro( s8stems. The &act o& .e a.(e to ha;e (ots o& cheap computers em.e66e6 insi6e o& man8 6e;ices that "e use 6uring our 6ai(8 (i&e in our homes, suppose a per&ect .ase &or the home automation. <o"e;er, 6ue to this recent(8 eas8 access to 6omotic, mu(tip(e communication stan6ar6s use6 insi6e pri;ate homes ha;e emerge6. Si3 6ierent communication s8stems are current(8 popu(ar on the mar!et, name(8 M10, =-.us, NigIee, N-"a;e, >O <ome =ontro( or O7M 9this (ast one is appro;e6 as the on(8 open stan6ar6 &or <ome an6 Iui(6ing =ontro(, internationa((8, in Europe an6 =hina: B11D. >t shou(6 a(so .e note6, that 6i&&erent s8stems supporting these 6i&&erent communication stan6ar6s are not a.(e to co((a.orate un6er norma( circumstances. The interopera.i(it8
.et"een the 6ierent protoco(s pre;ents optima( uti(ization o& 6i&&erent ;en6or speciHc s8stems. +arious ;en6ors ha;e ma6e 6ierent home automation s8stems "hich &ocus on one o& the communication protoco(. The &irm <omes8stem B1%D pro;i6es a housecontro((er pac!et "hich is a comp(ete s8stem "ith a contro((er, a "eather station an6 a termina(. nother pro;i6er is TE)ET SO 6omotics B24D "hich a(so se((s a pac!et so(ution. >n6igo B1$D pro;i6es an app(ication &or Pan8 Mac-.ase6 M10 setupP. @n&ortunate(8, neither o& them supports mu(tip(e communication protoco(s. comp(ete so(ution "i(( inc(u6e registration o& e(ectricit8 an6 heat consume6 an6 "i(( .e a.(e to contro( access, 6oors, "in6o"s, in6oor c(imate an6 entertainment 6e;ices as "e(( as a6ministrating a(arms reporte6. The <ome/ort pro,ect is a co((a.oration .et"een =enter &or Em.e66e6 So&t"are S8stems 9=>SS: at a(.org uni;ersit8, =enter &or So&t"are >nno;ation 9=S>: an6 arhus uni;ersit8. mong the in6ustr8 partners are Ser;o6an, Se(u3>T an6 De;e(co B0D B1#D. The purpose o& this pro,ect is to create so(utions that can ease the a6ministration o& home automation e?uipment an6 ensure interopera.i(it8 .et"een 6i&&erent protoco(s an6 as a conse?uence achie;e important energ8 an6 en;ironmenta( a6;antages. B10D
1.1 Motivation
The "a8 "e percei;e the concept o& computing is constant(8 changing o;er time. >n the past, computing "as on(8 associate6 "ith .ig 6ata processing centers, an6 computers "ere enormous an6 e3treme(8 e3pensi;e machines "hich "ere on(8 use6 .8 armies an6 a &e" in;estigation centers. To6a8, this has change6 in such a "a8 that computers are part o& our 6ai(8 (i&e. (most e;er8.o68 uses a computer 6uring their "or! 6a8 an6 is ;er8 common to &in6 one or more 6es!top or (aptop computer in each house in e;er8 6e;e(ope6 countries. 7o" "e can &in6 ourse(;es sitting in &ront o& our persona( 6es!top computers so(;ing e.i "or! re(ate6 tas!s, gaming or "ith the entr8 o& the internet communicating seam(ess(8 "ith &rien6s an6 &ami(8, ma!ing the shopping o& the month or .oo!ing a ho(i6a8 trip. specia( !in6 o& computer, pro6uct o& this e;o(ution, are the smart-phones. smart-phone is a mo.i(e phone that o&&ers more a6;ance6 computing a.i(it8 an6 connecti;it8 than a contemporar8 &eature phone. Smart-phones an6 &eature phones ma8 .e thought o& as han6-he(6 computers integrate6 "ith a mo.i(e te(ephone, .ut "hi(e most &eature phones are a.(e to run app(ications .ase6 on p(at&orms such as 'a;a ME, a smart-phone a((o"s the user to run an6 preempti;e(8 mu(titas! app(ications that are nati;e to the un6er(8ing har6"are.
10
The &irst smart-phone "as the >IM Simon. >t "as 6esigne6 in 1--2 an6 sho"n as a concept pro6uct. Iesi6es .eing a mo.i(e phone, it a(so containe6 other &eatures such a ca(en6ar, an a66ress .oo! or e-mai(. >t ha6 no ph8sica( .uttons to 6ia( "ith. >nstea6 customers use6 a touchscreen to se(ect te(ephone num.ers "ith a &inger B21D. 2our 8ears (ater, in 1--0, the the 7o!ia =ommunicator (ine "as (unche6 "ith the &irst 7o!ia smart-phone 7o!ia -000. This 6istincti;e pa(mtop computer st8(e smart-phone "as the resu(t o& a co((a.orati;e e&&ort o& an ear(8 success&u( an6 cost(8 persona( 6igita( assistant 9/D : .8 <e"(ett-/ac!ar6 com.ine6 "ith 7o!iaQs .estse((ing phone aroun6 that time, an6 ear(8 protot8pe mo6e(s ha6 the t"o 6e;ices &i3e6 ;ia a hinge. Then other 7o!ia 6e;ices "ere (unche6 "ith ne" &eatures (i!e an open operating s8stem 97o!ia -210:, co(or screen, EiH connection or G/S antenna. n6 &ina((8, in 1--# Ericsson re(ease6 the concept phone GS11, the &irst 6e;ice (a.e(e6 as QsmartphoneQ. [31] 2our 8ears (ater, /a(m, >nc. intro6uce6 the &irst smart-phone to .e 6ep(o8e6 in "i6esprea6 use in the @nite6 States, an6 Microso&t announce6 its Ein6o"s =E /oc!et /= OS that "ou(6 .e o&&ere6 as RMicroso&t Ein6o"s /o"ere6 Smartphone 2002P. A>M a(so re(ease6 the &irst I(ac!.err8 one 8ear a&ter, "hich "as the &irst smart-phone optimize6 &or "ire(ess emai( use an6 ha6 achie;e6 a tota( customer .ase o& %2 mi((ion su.scri.ers .8 Decem.er 200-. B1D The mar!et o& the smart-phones "as increasing in an e3traor6inar8 "a8 unti( the (aunch o& the &irst pp(e smart-phone4 the i/hone. This re(ease re;o(utionize6 the the smart-phone mar!et, 6oing this !in6 o& 6e;ices rea((8 interesting &or the nonpro&essiona( users. >t "as the &irst mo.i(e phone to use a mu(ti-touch inter&ace, an6 it &eature6 a "e. .ro"ser that Ars Technica then 6escri.e6 as J&ar superiorJ to an8thing o&&ere6 .8 that o& its competitors. B#D On(8 one 8ear a&ter the i/hone re(ease, "hich (ater "i(( .e its .iggest competitor "as re(ease64 the n6roi6 operating s8stem. n6roi6 is an open source p(at&orm .ac!e6 .8 Goog(e, a(ong "ith ma,or har6"are an6 so&t"are 6e;e(opers 9such as >nte(, <T=, AM, Motoro(a an6 Samsung, to name a &e":, that &orm the Open <an6set &otr ((iance B2%D. The &irst phone to use n6roi6 "as the <T= Dream. The so&t"are suite inc(u6e6 on the phone consists o& integration "ith Goog(eQs proprietar8 app(ications, such as Maps, =a(en6ar, an6 Gmai(, an6 a &u(( <TM) "e. .ro"ser. 7o" a 6a8s, the popu(arit8 o& mo.i(e phones 91.$-0.102,4 thousan6s o& units so(6 6uring 2010: B12D an6 o;era((, the a6;ent o& the smart-phones 9sa(es gre" #2 percent in 2010: B12D intro6uces a para6igm shi&t that again "i(( change ho" "e percei;e computing. The smart-phone .rings three &un6amenta( changes that sets it apart &rom ho" "e ha;e per&orme6 computation in the past. The smart-phone is a("a8s turne6 on, it is a("a8s connecte6 an6 it is a("a8s "ith 8ou "here;er 8ou go B%-D. >n a66ition to this, the smart-phone is PsmarterP, that is4 trough G/S, acce(erometers an6 compass it is a"are o& its (ocation, an6 ho" the 6e;ice is .eing he(6. Due to a(( these a6;antages that smart-phones are contri.uting to our 6ai(8 (i&e, a66e6 to the a&orementione6 tren6 o& integrating (o" cost microcomputers in home app(iances to &aci(itate 6omotics to enter common house ho(6ings, ma!e o& these !in6
11
o& 6e;ices the per&ect a((ies to manage our home in a com&orta.(e an6 eas8 "a8. There are se;era( a6;antages gaine6 .8 uti(izing the smart-phones in e3tension to a 6omotic s8stem. Comfort & Mobilit#: The greatest user ;a(ue is generate6 trough the com&ort o& mo.i(it8. The user e3perience is no (onger (imite6 to operate the 6omotic s8stem trough &i3e6 termina(s or "or!stations. The 6omotic s8stem can .e monitore6 an6 contro((e6 .8 a smart-phone &rom an8 (ocation "here internet connecti;it8 is possi.(e e.g. &rom an internet ca&S in =hina 9EiH: or "hi(e ri6ing the .us 9%G:. 'nerg# savings: Energ8 sa;ings is a "e(( !no"n argument in &a;or &or 6omotic s8stems .ut it is not a 6irect conse?uence o& intro6ucing the smart-phones as contro( 6e;ices. The smart-phone 6oes ho"e;er impro;e the uti(ization o& resources "ithin the home e.g. in 6omotic s8stems that contro( heating, ;enti(ating, an6 air con6itioning 9<+ =:. <+ = s8stems are ru(e .ase6, using sensor8 6ata as input to its 6ecision ma!ing. G/S in&ormation &rom the smartphone "i(( a((o" the 6omotic s8stem to ma!e more ?ua(iHe6 6ecision ma!ing in terms o& resource uti(ization. s the smart-phone is RconsciousP o& its geographica( (ocation trough G/S, the smart-phone can act as a sensor itse(& an6 supp(8 the 6omotic s8stem "ith in&ormation a.out the (ocation o& its user. This "i(( a((o" the 6omotic s8stem to (o"er temperatures "hen it can sense that no users are insi6e the house. Securit#: I8 using the smart-phone as a contro( an6 monitoring 6e;ice, "e can .e presente6 ;arious in&ormation a.out our home "hi(e "e are on-the-go. E;ents such as intrusion 6etection, accompanie6 "ith (i;e ;i6eo &ee6s "i(( ensure that it "i(( not come as a surprise to user i& the home is compromise6. Ehen accessing the home the smart-phone can impro;e securit8 "hen rep(acing the tra6itiona( !e8. Ehere access to the tra6itiona( home on(8 re?uires a !e8, access using the smart-phone can .e conHgure6 such that access "i(( re?uire .oth the ph8sica( 6e;ice .ut a(so a co6e com.ination. This ma!es the smart-phones a ;er8 interesting 6e;ice &or contro((ing 6omotics. I8 e3ten6ing the <ome/ort s8stem "ith a remote contro( an6 monitoring app(ication, "e can enhance the usa.i(it8 an6 pro;i6e a66itiona( com&ort to the s8stem. Iut this cou(6 increase the uti(it8 o& the s8stem e;en more than the remote increase6 the p(easure o& using the te(e;ision, .ecause "e can use the smart-phone (i!e a part o& the home sensors net, or to set up 6i&&erent pro&i(es, "hich "ou(6 ma!e o& the mo.i(e phone an e3tension o& the home .rain that "e can carr8 in our poc!et. Suita.(e 6e;ices &or such contro((er cou(6 contain a touch screen imp(8ing !e8.oar6 an6 mouse can .e omitte6. Ta.(et computers an6 smart-phones comes into min6. Ioth are "i6e(8 use6, an6 sur;e8s sho" that #0F o& mo.i(e phones so(6 to6a8 are smart-phones B%2D. This tren6 is positi;e as it entai(s potentia( o"ners o& <ome/ort "i(( ha;e a smart-phone an6 thus .e intereste6 in using it as a remote. >n this report, > &ocus on enhance the e3isting smart-phone app(ication Domotics On-The-Go, "hich acts as a .asic remote monitor o& the <ome/ort s8stem, .ecoming it in an e3tension o& the main home management s8stem. > mean, current(8 Domotics On-The-Go is an app(ication a.(e to connect to a <ome/ort ser;er using the secure protoco(s re?uire6, represent a(( the 6i&&erent net"or!s manage6 .8 the ser;er,
12
inc(u6ing their (ocations an6 the actuators p(ace6 at each (ocation. Moreo;er it can sho" the current state o& e;er8 6e;ice 9actuators:. M8 "or! in this issue is &ocuse6 on trans&orm this .asic app(ication in one a.(e to change the state o& each actuators as a &unction o& the measure an6 state o& the sensors connecte6 to the ser;er, as"e(( other ;aria.(es pro;i6e6 .8 the mo.i(e phone. Iesi6es those &unctions responsi.(e &or changing the state o& the home 6e;ices, "i(( .e presente6 to the user as pro&i(es that ma8 create an6 con&igure to (i!ing, so their setup "i(( .e an eas8 tas!.
13
( )ac*ground
This chapter contains pre re?uire6 in&ormation necessar8 &or this pro,ect. >n the &irst part > ma!e a 6escription o& the most common(8 use6 protoco(s "ithin 6omotic in or6er to sho" the 6i&&erences e3isting .et"een each o& them. Su.se?uent(8 a 6etai(e6 e3p(anation o& <ome/ort "i(( .e gi;en, sho"ing a(so a (itt(e e3amp(e o& the e;ent &(o" through the <ome/ort s8stem.
2.1.1 X-10
The M10 protoco( uti(izes e3isting po"er (ines to sen6 its messages. Iecause this protoco( e3p(oits the po"er (ines, this protoco( is cheap to app(8, since no a66itiona( "iring is nee6e6. <o"e;er, the po"er (ines a(so .ecome a 6o"nsi6e since the protoco( are 6epen6ent on them, compare6 to "ire(ess protoco(s (i!e NigIee an6 N-"a;e. >t shou(6 .e note6 that M10 .ri6ge units e3ist so a message can .e change6 an6 transmitte6 "ire(ess(8. nother 6o"nsi6es to the M10 protoco( is the nature o& the communication. >n this protoco(, on(8 one comman6 can .e transmitte6 at the time. This means that &irst, a message to the inten6e6 recei;er is transmitte6. Secon6(8, the action is transmitte6, "here a&ter the recei;ing 6e;ice per&orms it. These signa(s can inter(ea;e or co((i6e (ea6ing to comman6s that either cannot .e interprete6, or in "orst case trigger incorrect actions. 2ina((8, the stan6ar6 M10 po"er (ines (ac! support &or encr8ption. T8pica( M10 app(iances consist o& either a M10 s"itch or some !in6 o& 6e;ice, "hich re(a8s on s"itches or triggere6 e;ents. >n other "or6s - 6e;ices "ith an interaction "hich 6oes not re?uires a (ot o& message passing. E3amp(es on such 6e;ices cou(6 .e (amps, (ight 6immers, sensors an6 sur;ei((ance cameras. M10 message contains three partsK a house co6e, an unit co6e an6 an operation co6e. Since the house co6e part is 4 .it (ong, it has ha;e a tota( o& 10 uni?ue house co6es. The8 are 6enote6 .8 (etters through /. The same app(ies &or the unit co6e, a(though instea6 o& (etters, it is 6enote6 .8 num.ers 1 through 10. )ast(8, a 4 .it operation message "hich 6enotes "hich o& the 10 6ierent comman6s the 6e;ice shou(6 6o. These messages are transmitte6 o;er the po"er (ine in 120 !<z .ursts to separate them &rom the norma( signa(.
14
n e3amp(e o& a message that the protoco( ma8 sen6 is Rse(ect co6e %P &o((o"e6 .8 Rturn onP, "hich sa8s to unit R %P to turn on its 6e;ice. (so is possi.(e that mu(tip(e units are a66resse6 .e&ore sen6 the comman6 co6e, "hich means that the gi;en comman6 "i(( .e e3ecute6 .8 each units ca((e6 pre;ious(8. The &o((o"ing &igure sho"s the appearance that a message o& this t8pe cou(6 ha;e4
1$
O4
0010
2.1.2 C-Bus
=-Ius is a microprocessor-.ase6 contro( an6 management s8stem &or homes an6 .ui(6ings. This mean that each =-Ius 6e;ice has its o"n in-.ui(t microprocessor an6 Rinte((igenceP, a((o"ing units to .e in6i;i6ua((8 programme6. This ma!es =-I@S communication ;er8 re(ia.(e an6 ro.ust compare6 to M10. (so, as =-Ius uses point to mu(ti-point communication, e;er8 6e;ice on a =-Ius 7et"or! issues an6 respon6s to comman6s 6irect(8 &rom the 7et"or!, rather than re?uiring a centra( computer or contro((er. Each 6e;ice is a((ocate6 a speci&ic &rame o& time an6 each o& them are initia(ize6 in6i;i6ua((8. Then the 6e;ices .roa6cast its status, s8nchronize6 .8 a se(&generate6 s8stem c(oc! pu(se. >n this "a8, a (arge amount o& 6ata is a((o"e6 to .e transmitte6 in a ;er8 sma(( time &rame, e&&ecti;e(8 an6 re(ia.(8 on the net"or!, (ea6ing to (o" processing o;erhea6s an6 (o" .an6"i6th re?uirements. On the other han6, =-I@S is more e3pensi;e than M-10 6ue to is nee6e6 a communication "iring &or the s8stem. This "iring consist o& an unshie(6e6 t"iste6 pair ca.(e, "hich is the =-I@S 7et"or! Ius. The =-Ius 7et"or! is e(ectrica((8 iso(ate6 &rom the mains po"er, an6 operates at sa&e e3tra (o" ;o(tage (e;e(s 9%0 + 6c:. (( input or output 6e;ices can .e connecte6 to an8 point o& the =-I@S 7et"or! .8 a t"iste6 pair ca.(e, through "hich a(( the communication &(o"s o;er. n8"a8, a =-I@S gate"a8 e3ist so .oth "ire an6 "ire(ess communication are a;ai(a.(e. The topo(og8 o& the net"or! is &ree, "hich gi;es &(e3i.i(it8, since ne" 6e;ices can .e a66e6 to a su.s8stem at an8 time "ithout the nee6 to reconHgure an8thing. During commissioning, the s8stem is programme6 so that speci&ic comman6s trigger speci&ic responses in one 9or more: 6e;ices on the 7et"or!. t an8 time the comman6s can .e re-programme6, an6 =-Ius units can a(so .e a66e6, remo;e6 or mo;e6.
15
The size o& the net"or! is (imite6 to the num.er o& >/ a66resses. @sua((8 the net"or! is 6i;i6e6 in su.-net"or!s o& 100 =-I@S @nits, "hich 6i;i6e the s8stem into managea.(e sections, simp(i&8ing the topo(og8 6esign, (imiting possi.(e propagation &au(ts an6 ai6ing in trou.(eshooting. Ie(o", a simp(e e3amp(e o& ho" the =-I@S protoco( "or!s "i(( .e gi;enB%1D4
>n the .oar6room there is a =-I@S input s"itch that is programe6 "ith the a66ress group name RIoar6room main (ightsP. Ehen this input s"itch is presse6, it sen6 an O7 comman6 through the =-I@S to the RIoar6room main (ightP a66ress group.
This signa( "i(( .e recei;e6 .8 e;er8 6e;ices connecte6 to the =-I@S 7et"or!, .ut on(8 6e;ices that are a(so programe6 as .e(onging to the RIoar6room main (ightP "i(( interpret this comman6. The other 6e;ices that are not in this group "i(( ignore this comman6.
16
2.1.3 Z-Wave
N-"a;e is a "ire(ess communication protoco( 6e;e(ope6 .8 the 6anish &irm Nens8s B24D. To create a N-"a;e net"or!, a sing(e contro((a.(e 6e;ice "ith appertaining contro((er is nee6e6. simp(e net"or! can then easi(8 .e e3ten6e6 .8 a66ing more 6e;ices 5 contro((ers to it. This is 6one .8 a process ca((e6 pairing. I8 pressing a speciHc se?uence o& .uttons on the contro((er, the 6e;ice "i(( .e a66e6 an6 a("a8s recognize6 .8 the contro((er. This straight up approach re?uires (itt(e to no computer e3perience an6 thus a((o"s ine3perience6 computer users to create a home automation s8stem "ithout 6ea(ing "ith the hea;8 technica( part. Eithin the 6omain o& home automation N-"a;e .ecomes a great a(ternati;e to M10 &or users "hich either nee6 the mo.i(it8 o& "ire(ess communication or (i;e in o(6er houses (ac!ing the neutra( "ire. (so, compare6 to the =-Ius an6 M10, the N-"a;e protoco( is create6 &or "ire(ess purposes thus ha;e .ui(6-in securit8 at its core. This comes in han6, i& the user nee6s to uti(ize remote contro( 5 monitoring o& the house. N-"a;e is a (o"-po"ere6 "ire(ess protoco(, "hich uti(izes the -00 M<z >SM .an6, ma!ing it (ess suscepti.(e to inter&erences other"ise generate6 .8 the more common an6 cro"6e6 2.4 G<z .an6. The a;erage re(ia.(e communication range is 100 &eet in open areas, "hi(e the range "i(( .e re6uce6 insi6e 6epen6ing on ;arious con6itions such as .ui(6ing materia(s, p(acement etc. The protoco( is 6eHne6 to transmit sma(( messages, thus a (o" &re?uenc8 ra6io is per&ect "ith a .an6"i6th o& either -.0 or 40 !.its5s. >n Europe, the -00 >SM .an6 has a 1F 6ut8 c8c(e (imitation. This mean that a N-"a;e 6e;ice can on(8 transmit 1F o& the time, "herea&ter the 6e;ice resi6es in stan6.8 the rest o& the time "hich re6uce its po"er consumption signi&icant(8. The short ra6io range insi6e .ui(6ings 6oes not hin6er the e&&ecti;eness o& the protoco(, .ecause the net"or! is constructe6 using source route6 mesh net"or!ing. This approach ena.(es 6e;ices to re(a8 messages through interme6iate no6es, here.8 e3ten6ing the range o& the net"or!. The N-Ea;e protoco( has 2 .asic !in6s o& 6e;icesK contro((ing 6e;ices an6 s(a;e no6es. contro((er is a N-Ea;e 6e;ice that has a &u(( routing ta.(e an6 is there&ore a.(e to communicate "ith a(( no6es in the N-Ea;e net"or!. The &unctiona(it8 a;ai(a.(e in a contro((er 6epen6s on "hen it entere6 the N-Ea;e net"or!. >n case the contro((er is use6 to create a ne" N-Ea;e net"or! it automatica((8 .ecome the primar8 contro((er. The primar8 contro((er is the RmasterP contro((er in the N-Ea;e net"or! an6 there can on(8 .e one in each net"or!. On(8 primar8 contro((ers ha;e the capa.i(it8 to inc(u6e5e3c(u6e no6es in the net"or! an6 there&ore a("a8s ha;e the (atest net"or! topo(og8. The rest o& contro((ers a66e6 to the net"or! using the primar8 contro((er 9secon6ar8 contro((ers: 6onQt ha;e a((o"e6 to a66 or remo;e 6e;ices &rom the net"or!.
1'
The other !in6 o& 6e;ices in a N-Ea;e net"or! are the s(a;es. s(a;e no6es are no6es that recei;es comman6s an6 per&orms an action .ase6 on the comman6. S(a;e no6es are una.(e to sen6 in&ormation 6irect(8 to other s(a;es or contro((ers un(ess the8 are re?ueste6 to 6o so in a comman6. (ight 6immer cou(6 .e an e3amp(e o& an s(a;e 6e;ice.
2.1.4 ZigBee
NigIee is the name o& a speciHcation o& a set o& high-(e;e( protoco(s &or "ire(ess communication to .e use6 "ith (o"-po"ere6 ra6io .roa6casting, .ase6 in the >EE 102.1$.4 stan6ar6 o& "ire(ess persona( area net"or!s 9E/ 7:. >t is aime6 at app(ications that re?uire secure communication "ith (o" 6ata transmission rate an6 ma3imization o& the (i&e o& their .atteries, .eing home-automation a per&ect e3amp(e o& this !in6 o& app(ications. s "ith N-"a;e, NigIee is app(ie6 "ithin a ;ast o& 6ierent 6omains ranging &rom in6ustria( contro(, securit8 an6 smo!e 6etection to me6ica( 6ata co((ection an6 home automation. NigIee a((o" three net"or! topo(ogies4 start topo(og8, "here the coor6inator is p(ace6 in the center, tree topo(og8, "here the coor6inator "i(( .e the root o& the tree, an6 &ina((8 mesh topo(og8, in "hich at (east one o& the no6es "i(( ha;e more than t"o (in!s. This (ast topo(og8 is the one that ma!e this techno(og8 more interesting. The mesh topo(og8 a.(e manage a possi.(e 6amage o& a no6e &rom the "a8 !eeping the communication .et"een the remaining no6es "ithout an8 interruption, .eing this a
1(
coor6inator tas!. Three 6i&&erent NegIee 6e;ices can .e 6e&ine6 accor6ing to their ro(e in the net"or!4 ig!ee "oordinator, N=4 This is the most comp(ete 6e;ice. There must .e one into each net"or!. >ts tas! is to contro( the net"or! an6 the path to .e &o((o"e6 .8 6e;ices to connect to each. ig!ee #outer, NA4 The8 interconnect 6e;ices separate6 in the mesh topo(og8, moreo;er that o&&er an app(ication (e;e( &or running user source. ig!ee $nd Device, NED4 >t has the &unctiona(it8 nee6e6 to communicate "ith its &ather no6e 9the coor6inator or the router:, .ut is not a.(e to transmit in&ormation a((ocate6 to other 6e;ices. >n this "a8, this t8pe o& no6es can .e s(eeping a(most a(( the time.
The NigIee net"or!s ha;e .een 6esigne6 to sa;e the po"er o& the Rs(a;eP no6es. ccor6ing to this strateg8, a Rs(a;eP no6e spen6s a (ot o& time in Rs(eepP mo6e, in such a "a8 that on(8 is R"o!enP &or a &raction o& secon6 to pro;e that is Ra(i;eP into the 6e;ice net"or! in "hich is mem.er. Iecause o& that reason is "h8 this !in6 o& net"or!s are a.(e to sa;e a great amount o& energ8.
2.1.5 IO Homecontrol
>s a(so a "ire(ess protoco( "hich han6(es ra6io communications at a &re?uenc8 .et"een 101 an6 1#0 M<z. This ena.(es each pro6uct at a(( times to se(ect the &re?uenc8 &or transmitting the comman6 .eing sent. Turn this ena.(es each pro6uct to sta8 connecte6 in6epen6ent(8 o& ra6io inter&erence. The protoco( comp(ies "ith the E7 %00-220 stan6ar6 &or (o"-po"er ra6io app(ications. s "e(( as NigIee, a >O <omecontro( s8stem is upgra6a.(e. This means that it imme6iate(8 recognizes ne" pro6ucts an6 integrates them into the contro( unit automatica((8. Aegar6ing sa&et8, the communication .et"een the contro( unit an6 6e;ices is secure6 "ith a uni?ue, ran6om 121-.it !e8 encr8pte6 message use6 to authenticate the origin o& each comman6, as "e(( as 6o .an!s an6 cash machines.
2.1. !"X
O7M is a stan6ar6ize6, OS>-.ase6 net"or! communications protoco( &or inte((igent .ui(6ings. O7M is the successor to, an6 con;ergence o&, three pre;ious stan6ar6s4 the European <ome S8stems /rotoco( 9E<S:, IatiI@S, an6 the European
19
>nsta((ation Ius 9E>I or >nsta.us:. >n this case, O7M is a.(e to use se;era( communication me6ias4 T"iste6 pair "iring /o"er (ine net"or!ing 9simi(ar to M10: Aa6io >n&rare6 Ethernet
Iesi6es the great ;ariet8 o& me6ias that can .e use6 9t"iste6 pair me6ium is the most common use6:, O7M is 6esigne6 to .e in6epen6ent o& an8 particu(ar har6"are p(at&orm. This means that a O7M De;ice 7et"or! can .e contro((e6 .8 an8thing &rom an 1-.it micro-contro((er to a /=, accor6ing to the nee6s o& a particu(ar imp(ementation.
2.2 HomePort
>n the (ast section > ha;e ,ust 6one a 6escription o& si3 o& the protoco(s most use6 "ithin home-automation in or6er to i((ustrate the 6i;ersit8 o& imp(ementation an6 interopera.i(it8 among them. Once .een 6escri.e6 the 6i&&erent communication t8pes, > continue e3p(aining the structure o& the <ome/ort s8stem. (( the in&ormation in this section is .ase6 upon B1#D. The core 6e;e(opment o& <ome/ort ta!es p(ace at the =enter &or So&t"are >nno;ation 9=S>: in Soen6er.org, Denmar! "here a <ome/ort protot8pe s8stem ca((e6 P)i;ing )a.P is conHgure6. The goa( o& the <ome/ort s8stem is to create interopera.i(it8 .et"een mu(tip(e ;en6or speciHc communication protoco(s. This is 6one .8 creating a generic &rame"or! &or 6omotics. To achie;e common un6erstan6ing .et"een the 6ierent communication protoco(s, a common ser;ice (a8er is create6 to pro;i6e access to 6e;ice &unctiona(it8. This common ser;ice (a8er is contro((e6 .8 ser;ice composites that 6eHne the interaction .et"een 6e;ices, thus ena.(ing a NigIee s"itch to turn on a N-"a;e (amp. The <ome/ort s8stem architecture i((ustrate6 in 2igure %, is 6i;i6e6 into &our 6i&&erent parts4 "omposition %ayer, &ervice %ayer, !ridge %ayer an6 Device %ayer.
20
Composition $ayer Service $ayer ridging $ayer %evice $ayer Figure (: %ome&ort la)ered structure
Then > pass to 6escri.e each (a8er separate(8 an6 at the en6 > summarize "ith an e3amp(e.
Subsystem
(!"#ave)
i p
ridge
22
< device name ="Light sensor" id="lux - sensor" ip="192.168.1.225" port ="1 location ="!edroom" t"pe ="#$## %2 1" uid =" %"& < devicein'o (& < service value)url =" http*((+++.cs.au.d,(dithus(services(light-sensor(" t"pe ="int" id="sl2-" unit ="lux" name ="light-sensed"(& <( device &
2"
2.2.5 )*am(le
To get a .etter o;er;ie" o& the &unctiona(it8 o& the 6ierent (a8ers, an e3amp(e is presente6 in 2igure 0. >n the e3amp(e, a <ome/ort s8stem has t"o su.s8stems running in a home.
23
Composition Service
X
Figure /: .vent Flow
&
Su.s8stem is using the M10 protoco( an6 contains s"itch M an6 su.s8stem I is using N-"a;e an6 contains (amp N. Ehen s"itch M is togg(e6 an e;ent is generate6. The e;ent tra;e(s "ithin the su.s8stem M10 net"or!, an6 is trans(ate6 ;ia =7 > to an >/ .roa6cast "ithin the .ri6ge (a8er o& s8stem . The ser;ice (a8er registers the e;ent an6 i6entiHes the source o& the e;ent .8 the source >/- an6 port a66ress. /re6eHne6 composition (a8er (ogic associates the e;ent o& s"itch M, to togg(e the (ight state o& (amp N. The ser;ice (a8er has the (ocation @A) o& a(( 6e;ices in its registr8, an6 to mo6i&8 the state o& (amp N it in;o!es a <TT/ /@T re?uest to the @A) o& (amp N containing the ne" state ;a(ue. The <TT/ re?uest is han6(e6 .8 the .ri6ge in su.s8stem I "here it i6entiHes the target 6e;ice "ithin the su.s8stem, an6 through =7 > &or"ar6s the re?uest into the ;en6or speciHc su.s8stem protoco( N-"a;e, "hich su.se?uent(8 togg(es the state o& the (amp.
24
, Anal#sis
>n this chapter > gi;e more 6etai(s on the core components nee6e6 to create m8 app(ication. >n the &irst p(ace > 6escri.e the app(ication re?uirements. Then, > continue .8 in;estigating the most suita.(e p(at&orm "herein imp(ement m8 app(ication, inc(u6ing a 6etai(e6 6escription a.out the chosen p(at&orm. Ie(o", in the section ca((e6 /ersistence, > e3p(ain ho" the 6ata re?uire6 .8 the app(ication is store6 an6 manage6 in the smartphone. &ter that, &o((o" a section a.out the AEST architecture "hich sho" ho" 6e;ices are manipu(ate6 in <ome/ort. (most at the en6, a section regar6ing issues "ith "ire(ess contro( is gi;en an6 &ina((8 a part "here > e3p(ain "hat house management scenarios shou(6 .e consi6ere6 to imp(ement an6 "h8.
25
6e;ices. That means .eing a.(e to change the 6e;ice status or rea6 the sensor status, (i!e turn o&& a (amp or !no" i& a room is occupie6. $. To interact "ith the 6e;ices on the <ome/ort ser;er, the app(ication must use the AEST architecture an6 use the <TT/ GET an6 /@T message t8pes.
3.2 Platform
>n or6er to choose the most suita.(e p(at&orm it is necessar8 to ta!e a (oo! o;er the current most use6 t8pes o& operating s8stems &or smartphones. The most important criteria that shou(6 .e consi6ere6 are num.er o& users an6 ease o& 6e;e(opment. Iecause o& that in this section > (oo! to mar!et shares as an in6icator o& num.er or potentia( users, an6 to technica( speci&ication to !no" "hich o& them pro;i6es more &aci(ities to 6e;e(opers. s 8ou can see in 2igure #, "here is compare6 the sa(es o& smartphone 6uring the (ast ?uarter o& 8ears 200- an6 2010, or6er .8 operating s8stem, Goog(eQs n6roi6 has .ecome the (ea6ing p(at&orm. Shipments o& n6roi6-.ase6 smartphones reache6 %2.- mi((ion, "hi(e 6e;ices running 7o!iaUs S8m.ian p(at&orm trai(e6 s(ight(8 at %1.0 mi((ion "or(6"i6e. >& "e ta!e in account that not a(( 6e;ices running S8m.ian can .e consi6ere6 as Smartphones, the &o((o"ing most popu(ar p(at&orms are pp(eQs iOS, 6espite ha;ing (ost 0.%F o& share, an6 A>MQs OS 9I(ac!.err8 OS:, &o((o"e6 &rom &ar .8 Microso&t Ein6o"s /hone B%%D.
26
Then, > can conc(u6e that the i/hone OS an6 n6roi6 are the t"o 6ominating OSUs &or smartphones "or(6"i6e. Ee there&ore choose to &ocus on the strengths an6 "ea!ness o& these t"o p(at&orms. One o& the main reasons &or the n6roi6 success is the re(ati;e(8 (o" price o& the han6set an6 the "i6e range o& n6roi6 .ase6 han6sets a;ai(a.(e. There are current(8 more than 111 2 smartphones .ase6 on n6roi6, compare6 to iOS, that on(8 ,ust reache6 t"o han6sets this inc(u6ing the recent a66ition o& the i/hone 4 B21D.
n6roi6 is the &astest gro"ing p(at&orm &or smartphones. The p(at&orm is open source. n6roi6 app(ication 6e;e(opment is "ritten entire(8 in 'a;a, a "e(( esta.(ishe6 p(at&orm in6epen6ent (anguage. The o(6 ;ersion o& DOTG is running in he(p&u( an6 eas8 to reuse some parts. n6roi6 p(at&orms there&ore it "i(( .e
3.2.2 +n&roi&
The n6roi6 OS "as a pro6uct o& a compan8 ca((e6 n6roi6 >nc. "hich in 200$ "as purchase6 .8 Goog(e >nc. to ma!e &rom this operating s8stem their main .et &or mo.i(e 6e;ices mar!et. n6roi6 app(ications are usua((8 6e;e(ope6 in the 'a;a (anguage using the n6roi6 So&t"are De;e(opment Oit, .ut other 6e;e(opment too(s are a;ai(a.(e, inc(u6ing a 7ati;e De;e(opment Oit &or app(ications or e3tensions in = or =VV, an6
2 6ttp=??999.andro$p6ones.com?2011$android$p6ones.p6p
2'
Goog(e pp >n;entor, a ;isua( en;ironment &or no;ice programmers. That is .ecause there is no ,a;a .8te co6e or 'a;a ;irtua( machine running on the n6roi6 6e;ice. 'a;a is compi(e6 into Da(;i! E3ecuta.(e, an6 is interprete6 .8 the Da(;i! +irtua( Machine. Da(;i! is targete6 at the mo.i(e 6e;ices, an6 is optimize6 &or 6e;ices "ith (imite6 memor8 an6 =/@. The ;irtua( machine a((o"s mu(tip(e instances o& itse(& to run at once an6 ta!es a6;antage o& the un6er(8ing operating s8stem 9)inu3: &or process iso(ation an6 securit8 B2#D.
,+(+(+$
Architecture
The n6roi6 architecture consist o& &our 6ierent (a8ers "hich is i((ustrate6 in 2igure 1%. >n the .ottom (a8er a )inu3 !erne( ;ersion 2.0 runs the core s8stem ser;ices B2#D. This entai(s process an6 memor8 management, net"or!ing, 6ri;er mo6e(s an6 securit8. This (a8er a(so ser;es as an a.straction (a8er .et"een the un6er(8ing har6"are an6 the rest o& the so&t"are stac! B-D.
2(
On top o& the )inu3 core resi6e the nati;e (i.raries. (( (i.raries are "ritten in = or =VV an6 compi(e6 &or the particu(ar har6"are architecture use6 .8 the phone an6 pre insta((e6 .8 the phone ;en6or. (( o& these (i.raries are "ritten "ith &ocus on &ast an6 simp(e e3ecution, so (o" energ8 usage is assure6. .o;e the (i.raries is the app(ication &rame"or!. This (a8er pro;i6es high-en6 .ui(6ing .(oc!s to the 6e;e(oper. >t shou(6 .e note6 that the cti;it8 Manager, "hich p(a8s a !e8 ro(e in n6roi6 s8stem resi6es in this (e;e( B-D. The importance o& the cti;it8 Manager is 6iscusse6 in the &o((o"ing su.section. 2ina((8, the highest (e;e( o& the n6roi6 architecture is the app(ications. Most n6roi6 users "i(( on(8 see this (e;e(.
,+(+(+(
n instance o& the cti;it8 c(ass is an o.,ect that represent a sing(e o.,ect or action that a user can 6o e.g. choose menu item, enter settings or rea6 Pa.outP 6ia(ogue. >n an6roi6 cti;ities are o&ten associate6 "ith a graphica( +ie" that a((o"s user interaction. One cti;it8 is acti;e(8 running at a time, an6 mu(tip(e cti;ities are organize6 in an acti;it8 stac! structure. On(8 the top cti;it8 e(ement o& its stac! is running acti;e(8 B-DB2#D. cti;ities can .e in 6ierent states accor6ing to their ;isi.i(it8 an6 &ocus. The (i&e-c8c(e o& an cti;it8 is i((ustrate6 in 2igure -4. >n 2igure - the states o& the acti;ities are represente6 as a !in6 o& co(ore6 o;a(s, an6 the gra8 rectang(es in6icate the name o& the metho6s that are in;o!e6 upon a state change. >n the "hite rectang(es are sho"n "hat user or OS action causes the in;ocation o& these metho6s. Iecause o& the scare resources a;ai(a.(e on a mo.i(e phone, an6 the continuous urge to !eep .atter8 usage as (o" as possi.(e, management o& concurrent(8 running app(ication is nee6e6. Ehen an app(ication is starte6 n6roi6 .rings it to the &oregroun6. 2rom that app(ication, the user might in;o!e another app(ication an6 so &orth. (( these screens are store6 in the app(ication stac! .8 the s8stems cti;it8 Manager B2#D. Eith this stac!, the user can .ac!trac! the 6ierent screens - (i!e the histor8 in a "e. .ro"ser. >n n6roi6, each screen is represente6 .8 an cti;it8 c(ass an6 has its o"n (i&e c8c(e. This means that )inu3 encapsu(ate each app(ication as one or more acti;ities. <o"e;er, the (i&e c8c(e o& the acti;ities are not connecte6 to the encapsu(ating process, "hich can .e seen as a 6isposa.(e container &or acti;ities. Ehen a ne" app(ication is in;o!e6 an6 presente6 in the &oregroun6, the )inu3 process that "as running the pre;ious cti;it8 is !i((e6. The states o& the pre;ious cti;it8 are store6 an6 the ne" app(ication is opene6. On a (ater time, the user might return to the store6 acti;it8, "here it "i(( .e restarte6 an6 the states "i(( .e (oa6e6. This .eha;ior
4 Picture 5rom 6ttp=??developer.android.com?ima!es?activit/@li5ec/cle.pn!
29
&orces a specia( 6esign choice "hich "i(( .e 6iscusse6 in the &o((o"ing su.section.
service is a component that runs in the .ac!groun6 to per&orm (ong-running operations or to per&orm "or! &or remote processes. ser;ice 6oes not pro;i6e a user inter&ace. 2or e3amp(e, a ser;ice might p(a8 music in the .ac!groun6 "hi(e the user is in a 6i&&erent app(ication, or it might &etch 6ata o;er the net"or! "ithout .(oc!ing user interaction "ith an acti;it8. nother component, such as an acti;it8, can start the ser;ice an6 (et it run or .in6 to it in or6er to interact "ith it. )i!e acti;ities, ser;ices ha;e a c8c(e (i&e, "hich "i(( 6epen6 on ho" it is use6. >t can .e starte6 an6 a((o"e6 to run unti( someone stops it or it stops itse(&, or it can .e operate6 programmatica((8 using an inter&ace that it 6e&ines an6 e3ports. =(ients
30
esta.(ish a connection to the Ser;ice o.,ect an6 use that connection to ca(( into the ser;ice. The 6iagram in 2igure 10$ i((ustrates the ca((.ac! metho6s &or a ser;ice. (though it separates ser;ices that are create6 .8 the &irst metho6 &rom those create6 .8 the secon6 one, !eep in min6 that an8 ser;ice, no matter ho" itQs starte6, can potentia((8 a((o" c(ients to .in6 to it, so an8 ser;ice ma8 recei;e onIin69: an6 on@n.in69: ca((s.
,+(+(+0Android design in1uences The "a8 that "e 6e;e(op an6 6esign the n6roi6 app(ications is a&&ecte6 .8 ho" n6roi6 han6(es acti;ities. >n tra6itiona( 'a;a programing "e o&ten use the Sing(eton 6esign pattern "hen some in&ormation or &unctiona(it8 is accesse6 across mu(tip(e c(asses. <o"e;er, "e can not use the Sing(eton 6esign pattern "hen "e are 6e;e(oping on n6roi6 p(at&orm. O.,ects 6oes not persist .8 6e&au(t. >n &act, the s8stem ma8 choose an app(ications that appear .eing running to !i(( its un6er(8ing process an6 (ater restart it again. This (ea6s to the 6ata persistence is re?uire6, so it
5 Picture 5rom 6ttp=??999.cintervie9s.com?2009?11?service$li5ec/cle$in$android.6tml
31
gets store as a state. >n n6roi6 "e can imp(ement the 6ata as a g(o.a( ser;ice to 6o it. The 6ata must .e store6 as a state .ecause the ser;ice "i(( .e a;ai(a.(e to a(( app(ications. The other option is to store the 6ata using an SW)ite 6ata.ase or some other "a8 o& 6ata storage.
,+(+(+2 Persistence
The n6roi6 p(at&orm pro;i6es t"o main too(s to storage an6 retrie;a( o& structure6 6ata4 SW)ite Data Iases =ontent /ro;i6ers
SW)ite co;ers e;er8 tas! re(ate6 to o"n 6ata storage o& the app(ication. The secon6 too(, the =ontent /ro;i6ers, ease the tas! o& ma!e ;isi.(e these 6ata to other app(ications an6 a(so a((o" our app(ication retrie;e 6ata pu.(ishe6 .8 a thir6 app(ication B%D. The SW)ite is a ;er8 popu(ar 6ata.ase engine no" a 6a8s .ecause o& pro;i6e &eatures so interesting as its (itt(e size, not to nee6 a ser;er, re?uire (itt(e con&iguration, to .e transactiona( an6, o& course, to .e open source. @n(i!e the c(ient-ser;er 6ata.ase management s8stems, the SW)ite engine is not an in6epen6ent process "ith "hich the main program communicates. >nstea6, the SW)ite (i.rar8 is (in!e6 "ith the program .ecoming an integrate6 part thereo&. The main program uses the &unctiona(it8 o& SW)ite through simp(e ca((s to su.routines an6 &unctions. That re6uces the (atenc8 in the access to the 6ata.ase, 6ue to &unction ca((s are more e&&icient than communication .et"een process. The entire 6ata.ase 96e&initions, ta.(es, in6e3es an6 the 6ata itse(&:, are store6 as a sing(e stan6ar6 &i(e in the host machine. This simp(e 6esign is achie;e6 .8 (oc!ing the 6ata.ase "ho(e &i(e at the .eginning o& e;er8 transaction B4D.
32
E;er8 6e;ice are mo6e(e6 as a resource, so the8 a(( can .e in;o!e6 using the <TT/ metho6s GET an6 /@T B1-D. <a;ing a AEST .ase6 ser;ice oriente6 architecture ensures that 6e;ice &unctiona(ities can .e compose6 across su.s8stem an6 o"nership 6omains. The interaction "ith a 6e;ice at the Jser;ice-(a8erJ is transparent, regar6(ess o& the "ire(ess net"or! to it is connecte6 B1#D. The imp(ementation can .e &oun6 in a(most a(( p(at&orms .ecause the <TT/ is a (ight-"eight protoco(. Moreo;er, it is possi.(e to use an8 stan6ar6 .ro"ser to a66ress the resources, "hich means an8 thir6 program is not nee6e6. >n the &o((o"ing section > a66ress issues o& securit8 originate6 .8 the &act o& e3ten6 the <ome/ort s8stem "ith a smartphone app(ication.
,+0 Securit#
The &act o& a((o" e;er8 6e;ices an6 sensors o& a house .e a.(e o& .eing han6(e6 &rom a remote s8stem (i!e a mo.i(e phone or a "e. .ro"ser imp(ies a (ot o& ris!s. securit8 .reach ma8 in;o(;e high-cost conse?uences, so, in or6er to not compromise 6omotic s8stem some securit8 measures must .e ta!en. O& course these securit8 measures are re?uire6 in a(( (a8ers o& the <ome/ort architecture, .ut > "i(( a66ress issues re(ate6 to connecting the s8stem &rom a mo.i(e 6e;ice. There are three securit8 re?uirements "hich are nee6e6 consi6er "hen connecting a remote 6e;ice4 user authentication, message con'dentiality an6 message integrity . "ser Authentication: is re?uire6 to ensure that "e !no" in e;er8 moment une?ui;oca((8 the parts engage6 in the communication process. Message Confidentialit#: "arrant that i& the sen6er J J sen6s a message &or the recei;er JIJ, an8 thir6 (istener R=P hi6e6 in an8 mi6point o& path, is a.(e to rea6 these message an6 !no" some in&ormation a.out the house state. Eithout con&i6entia(it8, &oreign agents ma8 gather ;ita( in&ormation such as !no" i& the a(arm s8stem is ena.(e6 or i& some e3it 6oor is un(oc!e6, c(ear(8 en6angering the securit8 o& the house an6 its inha.itants. Message %ntegrit#: as "e(( as can not .e a((o" an8one a(ien access to a message in&ormation, a(so can not a((o" an8 thir6 agent mo6i&ies the message content. 2urthermore, i& this happens, the correct recei;er must .e a.(e to 6etect that the message has .een a(tere6.
The so(ution to these three issues that <ome/ort cre" proposes is an encr8ption protoco( ca((e6 Secure Soc!et )a8er 9SS):.
33
Secure Soc*et .a#er This protoco( is ;er8 "e(( !no"n "ithin the .an! an6 on(ine pa8ment "or(6, "here the securit8 is paramount. >n 1--0, 7etscape pu.(ishe6 the SS) ;ersion %.0, "hich "as 6e;e(ope6 .8 them, an6 (ater it "as accepte6 as an stan6ar6K in &act, +isa, Master=ar6, merican E3press an6 man8 others o& the main &inancia( institutions ha;e appro;e6 SS) to the internet commerce B%4DB22D. The SS) connection pro;i6es the e(ements o& authentication, message conH6entia(it8 an6 message integrit8. To access to the <ome/ort )i;ing )a. is necessar8 use a secure soc!et (a8er connection. >n the &o((o"ing e3amp(e > "i(( i((ustrate the princip(es .ehin6 SS) communication. >n 2igure 11 the c(ient is going to esta.(ish an SS) connection to the ser;er. 2irst o& a((, .oth parts must agree, at the .eginning o& the connection esta.(ishment, on the ;ersion o& SS) protoco( an6 the cipher encr8ption the8 "ant to use B%0D.
SS$ Client
SS$ Server
1, 2, 3, 4, 5, , -, ., /, 10, 11,
Server 'ello Server Certificate
Client 'ello
Server Certificate re(uest Server 'ello %one Client Certificate Client )ey *+c,ange C,ange Cip,er Spec [ Client -inis,ed ] C,ange Cip,er Spec [ Serve -inis,ed ]
34
uthorities 9=as:.
$. Then, the ser;er sen6s a RSer;er <e((o 6oneP "hich means that a(( re?uest are &inishe6. 0. Ie(o", the re?uire6 certi&icate is sen6 .8 the c(ient to the ser;er. #. @sing the ran6om ;a(ue recei;e6 &rom the ser;er, an6 the c(ients o"n ran6om ;a(ue, itse(& "i(( compute a pre-master secret. &ter that, the c(ient sen6s a R=(ientOe8E3changeP message to the ser;er in "hich the pre-master secret is encr8pte6 using the ser;erQs pu.(ic !e8. The c(ient an6 ser;er .oth compute a master secret &rom the pre-master secret (oca((8. The session !e8 use6 &or s8mmetric encr8ption is 6eri;e6 &rom this master !e8. Ee "i(( ha;e ensure6 that the ser;er is the on(8 one "hich can 6ecr8pt messages &rom the c(ient i& this ser;er is a.(e to 6ecr8pt the R=(ientOe8E3changeP message an6 procee6 "ith the protoco( negotiation. 1. The c(ient con&irm the &o((o"ing messages "i(( .e encr8pte6 .8 sen6ing a R=hange =ipher SpecP message. -. The P=(ient 2inishe6P message is encr8pte6 "ith the session !e8, containing a(so a hash o& the entire negotiation. 10. s "e(( as the c(ient 6i6, the ser;er sen6s a RSer;er =ipher SpecP message "hich in6icate the &o((o"ing messages "i(( .e encr8pte6.
11. 2ina((8, the ser;er sen6s a RSer;er 2inishe6P message encr8pte6 an6 containing a hash o& the negotiation unti( this point. >& the c(ient can 6ecr8pt this message an6 ;a(i6ate the hash, the SS) han6sha!e "as success&u(.
35
app(ication remains a("a8s iso(ate6 in a secure zone "here it "onQt .e a.(e to cause an8 un6esire6 .eha;ior unhan6e6 .8 the composition (a8er 6e&ine6 in the connecte6 <ome/ort s8stem. Generate a (ist that inc(u6e6 6e;ices "hich 6e;ices can .e accesse6 an6 han6(e6 .8 the remote app(ication cou(6 .e a thir6 approach. 7e;erthe(ess, <ome/ort 6oes not imp(ement an8 access po(ic8 a(though it is consi6ere6 as a &uture "or! B1#D. Moreo;er, the composition o& this (ist "ou(6 .e a te6ious "or! &or a(most e;er8 en6 users an6 it cou(6 (ea6 to errors
Magnitude/Actuators Dimmers Blinds Switches Outdoor Switches Doors Windows Heaters Wind Rain Presence Outdoor Light Indoor Light Tem erature 2able 1: 6cenarios
X X X X X X X X
X X X
36
3. .1 W0en it is 1in&%
>n or6er to a;oi6 (itt(e acci6ent insi6e the house, (i!e 6oor s(am or &a((ing o.,ects 6ue to the air currents, the app(ication shou(6 a((o" to c(ose a(( "in6o"s an6 e3it 6oors in the house "hen the 6a8 is "in68. Moreo;er, the "in6 spee6 "hich it shou(6 c(ose "in6o"s an6 6oors shou(6 .e chosen .8 the user. To achie;e this it "i(( .e necessar8 at (east one out6oor "in6 sensor. Due to this isnQt ;er8 common it is possi.(e that this scenario ma8 not .e in e;er8 .ui(6ing. O& course it "i(( necessar8 opera.(e 6oors an6 "in6o"s, .ut > "i(( assume it &rom no" on.
3. .2 W0en it is rain%
s in the pre;ious scenario, it "i(( .e necessar8 that the app(ication c(ose a(( e3it 6oors an6 "in6o"s "hen it is raining, to pre;ent the "ater &rom entering the house an6 can 6amage the &(oor, "a((s, etc. >n this case a(so "i(( .e necessar8 to ha;e a rain sensor "hich in6icate "hen the this scenario is happening.
3'
minimum (ight (e;e( nee6e6 to s"itch on the street (ights shou(6 .e se(ecte6 .8 the user.
3. . 2em(erature management
The purpose o& this scenario is simp(e. The intention is to ma!e the app(ication a.(e to contro( the in6oor temperature. >t cou(6 (oo! too simp(e using on(8 the thermostat o& the house, .ut the i6ea a(so to use the "in6o"s to manage the temperature, opening the8 "hen "e "ant to re&rigerate the house an6 (o"er the house. O& course it "i(( .e necessar8 a temperature sensor outsi6e the house to in6icate i& the temperature outsi6e is (o"er an6 it is use&u( opening the "in6o"s.
3(
0 !esign
>n this chapter > 6escri.e the main 6i&&erent 6esign 6ecisions ma6e to accommo6ate those re?uirements an6 other ana(8sis issues a66resse6 in the (ast chapter. s "e can see in 2igure 12, the so&t"are structure is organize6 in three (a8ers. The &irst one represent the G@> "hose operation is 6etai(e6 in section 4.%. mong other things, "e can &in6 the pro&i(e settings inter&ace, "hich is one o& the main ne" &eatures. Moreo;er, in the (ogic (a8er "e can see the /ro&i(e manager an6 the automation ser;ice, .oth o& them ne" &eatures in this ;ersion too, an6 e3p(aine6 6etai(e6 in sections 4.0 an6 4.# respecti;e(8. 2ina((8, "e ha;e the 6ata (a8er in "hich is inc(u6e6 the 6ata .ase, hoste6 on the mo.i(e phone an6 "here the pro&i(e settings "i(( .e sa;e6. >n this (a8er is a(so inc(u6e6 the remote <ome/ort ser;er that is the inter&ace to "hich the app(ication has to interact.
2urthermore, a short 6escription o& the re(ationships .et"een each component is gi;en in the 2igure 12. These re(ationships are a(so a66resse6 in the &o((o"ing sections.
39
in&ormation a.out ho" to access to each 6e;ice, "hat !in6 o& 6e;ice it is, etc. e3amp(e o& this &i(e can .e seen in the ppen6i3 4 7et"or! MM) 6escription
7o" a 6a8, in a(most e;er8 common 6e;e(opment p(at&orms there are se;era( "a8s to rea6 an6 "rite 6ata in MM) &ormat. The most "i6esprea6 are S M 9 &imple A() for *+%: an6 DOM 9Document ,b-ect +odel:. Su.se?uent(8, other "a8s ha;e .een appearing, among "hich stan6 out St M 9S treaming A() for *+%:. O.;ious(8, n6roi6 a(so inc(u6e this three main mo6e(s &or the MM) han6(ing, .eing in the (ast case an ana(og ;ersion 9*ml(ull: B%$D. O& course, a(( o& them a((o" to 6o the same things a(though not in the same "a8. The S M parser is on(8 a simp(e /> "hich "or!s as an stream parser "ith an e;ent-6ri;en />. The a6;antage o& this approach is that use the memor8 in an e&&icient "a8. >t "i(( not .e re?uire6 the ma3imum 6epth o& the MM) 6ocument in memor8 in a(most a(( cases. 2o((o"ing a(most the same "or!ing metho6, *ml(ull a(so is .ase6 on 6e&ining actions to .e 6one &or each e;ents generate6 6uring the se?uence6 rea6ing o& the 6ocument. Ehi(e "ith S M "e 6onQt ha;e the contro( the rea6ing once starte6, "ith *ml(ull "e can 6eman6 the rea6ing o& the ne3t MM) e(ement, ans"ering "ith the appropriate action. >n the other han6, DOM parser stores the "ho(e MM) &i(e in the memor8, "hi(e it .ui(6s the tree structure. E;en though this approach uses much more memor8 resources, it pro;i6es an imp(icit 6e;ice o.,ect representation an6 e(egant 6ata tra;ersa(, "hich ma8 .e a .ig a6;antage 6uring the imp(ementation tas!. >n the (ast ;ersion o& DOTG "as use6 the DOM metho6 .ecause the .ene&its "ere more than the 6ra".ac!s o& the a66itiona( memor8. >t shou(6 .e notice6 that the memor8 size is .ecoming (ess o& a pro.(em 6ue to the increase o& the capacities, an6 a(so e;en i& "e "or! "ith a huge net"or! &u(( o& 6e;ices, the storage o& the net"or! MM) 6ocument "ou(6 .e much (ess than a simp(e ;i6eo game. Iecause o& a(( this, an6 in or6er to .e a.(e to reuse some co6e > a(so use6 this parse metho6. Once the net"or! MM) 6ocument is parse6, each 6e;ice "i(( .e c(assi&ie6 accor6ing to its net"or!-tag, "hich in6icates "hat house it .e(ongs 9"e ma8 manage our o&&ice an6 our house "ith the same <ome/ort ser;er:. Then, a(( 6e;ices "i(( .e groupe6 insi6e each net"or! accor6ing to its (ocation-tag. That means, a(( 6e;ices (ocate6 in the !itchen "i(( .e &oun6 un6er the categor8 Oitchen. 7e;erthe(ess, "e ha;e to .ear in min6 that the (ocation-tag is not man6ator8, there&ore a(( 6e;ices "ithout this tag "i(( .e groupe6 as @n!no"n.
40
interact "ith this 6e;ices. >n the pre;ious ;ersion o& DOTG "e on(8 cou(6 interact "ith a sing(e 6e;ice at a one time. This time, "e "i(( .e a.(e to access to se;era( 6e;ices at the same time to get an automatic .eha;ior, an6 to a((o" to change the state o& some 6e;ices 6epen6ing on the state o& some others. O& course it is a(so possi.(e access to an in6i;i6ua( 6e;ice an the &unctiona(it8 "i(( 6epen6 on the t8pe o& 6e;ice accesse6. To get a(( this, a coup(e o& issues must .e consi6ere6. 2irst, ho" to set up the automatic .eha;iors, an6 then, ho" to 6isp(a8 this con&igurations an6 the in6i;i6ua( 6e;ices in an intuiti;e an6 &rien6(8 "a8.
.ttp*((<ip-address&*<port&(services(<id&(<name&
>n the (ast ;ersion, each time a (ist o& 6e;ices "as create6 <ome/ort "as as!e6 a.out the status o& each 6e;ice, so the (ist "as up6ate6. This means that it ma8 .e inconsistencies .et"een the status recor6e6 in the app(ication an6 the rea( state o& a 6e;ice. 2or e3amp(e, i& the user o& the smartphone create the (ist an6 gets the status o& a gi;en 6e;ice, an6 (ater a resi6ent interacts ph8sica((8 "ith the 6e;ice. >n this case the 6e;ice status !no"n .8 the smartphone user "ou(6 .e "rong. To &i3 this pro.(em, in this ;ersion the automatic .eha;ior "i(( .e the on(8 one "ho nee6 to !no" &re?uent(8 the 6e;ice status. This "i(( .e a tas! o& an an6roi6 ser;ice responsi.(e &or the automation "hich "i(( chec! the 6e;ice status .e&ore re?uest an8 change 9See section 4.#:.
41
Settings
About
*+it
42
ma8 .e ,ust .e(o". This user name "i(( .e use6 to 6istinguish the t8pe o& user that is connecte6 to the house. <a;ing this in&ormation the app(ication cou(6 use 6i&&erent settings &or a parent or a teenager. > mean, i& the user is arri;ing at home, the app(ication ma8 turn on the co&&ee machine, i& he "as (ogge6 as Da6. <o"e;er, i& the user "as (ogge6 as a chi(6, the app(ication cou(6 start to "arm his room instea6 o& turn on the co&&ee machine. >& there is a username &ie(6, a pass4ord &ie(6 shou(6nUt miss. This is .ecause the app(ication has to .e as secure as possi.(e. n6 &ina((8, i& > "ish to support se;era( languages, there shou(6 .e a 6rop 6o"n menu "here the user "i(( .e a.(e to choice his pre&erre6. >n the 2igure 14 8ou can see a s!etch o& the settings screen.
Username
password
Select $anguage
43
menu gi;es the user the option to app(8 a con&iguration pro&i(e to the pre;ious(8 se(ecte6 net"or!, or the option to set up an e3isting or ne" pro&i(e 9See 2igure 10:. Ehen the user is on the screen o& 6e;ices, he can c(ic! on an8 o& them to see their status an6 interact "ith them. The app(ication sho"s a pop-up .o3 "ith a .ar "hich "i(( represent the state o& the 6e;ice. >n the 2igure 1# > gi;e t"o e3amp(e o& this pop-up .o3es. The &irst one is &or sca(a.(e 6e;ices 9Thermostat, 6immers, etc:, an6 the secon6 one is &or t"o-state 6e;ices 9S"itches, T+, etc:.
%evices location X icon icon %evice name1 %escription %evice name 2 %escription
/et0or1 n
icon
Figure 1-: 6#etch of the networ#s list7 and the available devices list in a location
Select profile
3rofile settings
44
4emerature5 226
min ma+
4urned 7/
7-7/
Figure 10: &op!up boxes with the device status and controller
The secon6 screen re?uire6 is one "here the user is a.(e to set up each pro&i(e, or ma!e some ne". 2irst(8, the screen must ha;e a 6rop-6o"n (ist "here the user can se(ect the pro&i(e that "ants to set up. The state o& the rest o& contro((ers in the screen "i(( ;ar8 6epen6ing on "hat pro&i(e is se(ecte6 in this (ist. >& the user se(ect Rne"P in this (ist, a te3t &ie(6 "i(( appear ,ust un6er the profiles list, "hich the user can &i((
45
"ith the ne4 profile name. Ie((o", "e nee6 a s(i6e .ar "hich represent the 6esire6 (ight level insi6e the house measure6 in (u3es. (so "e nee6 other s(i6e .ar to represent the 6esire6 temperature. 2urthermore, "e nee6 to sa8 to the app(ication "hen it shou(6 close the 4indo4s. To 6o this, there are a (ist "ith the &our 6i&&erent options a;ai(a.(e. The user "i(( ha;e to choose one .et"een them4 0hen rain, 0hen wind, Always an6 1ever. 2ina((8, on the .ottom o& the screen "e nee6 a s(i6e .ar "hich represent the outside light level re?uire6 to s"itch on the outsi6e (ights, &o((o"e6 .8 a save .utton to sa;e a(( the changes 6one. (( the in&ormation co((ecte6 .8 this contro((ers is re?uire6 in or6er to a((o" the app(ication automate the possi.(e scenarios presente6 in section %.0. s!etch o& the pro&i(e settings screen is gi;en in 2igure 1-.
3rofile 2
New profile (optional)
4emperature5 226
Close 0indo0s
#,en raining #,en 0ind Al0ays /ever
0+0 Securit#
s > sai6 in =hapter %, "hen using a remote app(ications, securit8 .ecomes in one o& the most important e(ements. >n our case, <ome/ort a(so re?uire some secure metho6s to access to it. >n particu(ar the8 on(8 accept a SS) communication to .e
46
accesse6. 2urthermore, the8 re?uest a signe6 certi&icate. >n or6er to a((o" the connection to the ser;er, the <ome/ort 6e;e(opment cre" pro;i6e6 a ser;er certi&icate an6 pu.(ic !e8 &or the &irst ;ersion o& DOTG, "hich > "i(( use &or this ;ersion. This .oth &i(es "ere enco6e6 in a 6i&&erent &ormat 9/EM: to that use6 .8 ,a;a 9DEA:. This pro.(em can .e &i3e6 .8 using the too( openssl "hich can con;ert .oth &i(es &rom one &ormat to the other.
Moreo;er this c(ass pre;ents changes in re?uirements &or access to <ome/ort a&&ecting the app(ication &unctiona(it8 in a serious "a8. >n case o& this happens, it "ou(6 on(8 .e necessar8 to change this c(ass .8 another, or simp(8 change it. Iesi6es i& in some moment "e "ant to a6apt DOTG to other t8pe o& 6omotic ser;er, it "ou(6 .e a(so possi.(e changing on(8 the communication manager.
Once more, as in =ommMan case, this c(ass pre;ents changes in the 6ata.ase, such as more 6etai(e6 pro&i(es, a&&ecting the "ho(e app(ication &unctiona(it8. >& that happens, it is on(8 necessar8 changes in this c(ass.
4'
0+6 Summar#
>n this =hapter > ha;e e3p(aine6 ho" the (ist o& 6e;ices ha;e to .e parse6 &rom the MM) net"or! 6ocument "hich resi6es in the <ome/ort ser;er, ta!ing in account a(( too(s that n6roi6 pro;i6es. Then > ha;e a66resse6 issues regar6ing manipu(ation o& the 6e;ices an6 a(( trou.(es that in;o(;e6. 2urthermore > ha;e s!etche6 the G@> o& the app(ication, e3p(aining thorough(8 the most &unctiona( screens. &ter that > ha;e ha6 a (oo! o;er securit8 through SS), &o((o"e6 .8 a 6escription o& the =ommunication Manager an6 the /ersistence Manager an6 their &unctions. 2ina((8, > ha;e sho"n ho" "or!s the .ac!groun6 ser;ice responsi.(e &or ma!e &rom DOTG a rea( automatic remote contro((er o& the house.
4(
2 %mplementation
>n this chapter > e3p(ain the main issues regar6ing the imp(ementation, 6escri.e6 in more 6etai( the c(asses that > consi6er more interesting an6 no;e(t8 in this ;ersion o& DOTG.
... public class HomePort extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState) setContent!ie"(#.layout.main) $$ Setu% ClickListener !ie" connectButton & 'ind!ie"ById(#.id.connect_button) connectButton.setOnClickListener(this) ...
public void onClick(!ie" v) { switch (v.)etId()) { case #.id.connect_button* Intent i & new Intent(this+ ListL!L,.class) startActivity(i) break ... ( ( (
49
metho6 find2iew!y)d() "hich recei;es as a parameter the the >D num.er o& the .utton, an6 rep(ies "ith the o"n .utton. This .utton nee6s a han6(er "hich rep(8 to the e;ents generate6 "hen c(ic!ing the .utton. That is a tas! o& the c(ass itse(& that "i(( catch a(( c(ic! e;ents generate6 .8 the .utton, "hich "e ha;e to in6icate "ho is going to .e its R(istenerP. This is 6one through the metho6 3button4.set,n"lic5%istener(this) an6 gi;ing as a parameter the o"n c(ass. The e;ents generate6 .8 a(( .uttons in the ;ie" are caught .8 the c(ass metho6 on"lic5() "hich imp(ements a s"itch-case structure to 6i&&erentiate the .utton presse6, gi;en as a parameter. >n this case, once the R=onnectP .utton is c(ic!e6, a ne" >ntent is create6 "ith the current an6 ne3t acti;it8 an6 then it is passe6 to the startActivity() metho6.
-LinearLayout .mlns*android&"http://schemas.android.com/apk/res/android" android*orientation&"vertical" android*layout/"idt0&"fill_parent" android*layout/0ei)0t&"fill_parent" android*1ack)round&"@drawable/my_background"2 -3e.t!ie" android*id&"@+id/main_title" android*layout/0ei)0t&"wrap_content" android*te.t&"@string_/main_title" android*layout/)ravity&"center_horizontal" android*layout/"idt0&"wrap_content" android*te.tSi4e&" p!" android*layout/mar)in&" "p!"2 -$3e.t!ie"2 -Button android*id&"@+id/connect_button" android*layout/"idt0&"fill_parent" android*layout/0ei)0t&"wrap_content" android*te.t&"@string/connect_label" $2 ... -$LinearLayout2
2+( 7"%
s > sai6 in the pre;ious section, the "ho(e G@> is ma6e in MM). >n or6er to e3p(ain ho" (oo!s the representation o& a MM) 6ocument > "i(( itemize the 6i&&erent properties use6 an6 a(so gi;e the &ina( screen achie;e6.
50
The secon6 (ine o& the )isting % 6escri.es the orientation propert8 o& the (a8out "hich 6etermine i& the e(ements are going to .e situate6 ne3t to each other or one .e(o" the other. The t"o ne3t attri.utes sa8 i& the size is going to match the content or the container, an6 the (ast one regar6s the picture, store6 on the 6ra"a.(e resource &o(6er, use6 to the .ac!groun6. &ter that, a ne" te3t &ie(6 is create6 to contain the main tit(e. The &irst attri.ute o& this e(ement pre&i3e6 .8 RXi6P in6icates the name through "hich the &ie(6 is re&erence6 in the auto-generate6 resource &i(e R. Then &urther 6i&&erent settings are 6e&ine6, such as the content o& the &ie(6 an6 the &ormat. &ter that, &our .uttons are a(so 6e&ine6, e;en on(8 one has .een inc(u6e6 in the e3amp(e. The graphic resu(t o& this MM) 6ocument is gi;en in 2igure 20., as "e(( as the RSettingsP an6 R .outP screens 92igure 21 an6 22:, .oth create6 in a simi(ar "a8.
Ehen the R=onnectP .utton is c(ic!e6, the e;ent is caught .8 the main acti;it8 "hich in;o!es the metho6 on"lic5(). Then, the s"itch-case structure recognizes the i6 o& the .utton an6 creates a ne" >ntent "ith the )ist)+1.c(ass to (ater start that acti;it8 9see )isting %:. This ne" acti;it8 has three main tas!s. 2irst o& a((, it is the responsi.(e o& sho" to the user the a;ai(a.(e net"or!s in the ser;er so it "i(( start the parse o& the net"or! MM) .8 creating a =ommMan o.,ect. The acti;it8 "i(( ca(( the metho6 get1etwor5s() an6 "i(( sho" the resu(t (i!e a (ist o& net"or!s, as sho"n in 2igure 2%. Ee can see ho" is it 6one in the &irst ha(& o& )isting 4.
Moreo;er, this c(ass as "e(( as the R<ome/ortP c(ass 6oes, imp(ements the R(istenerP &or the e(ements o& the (ist o& net"or!s. Ehen a net"or! is se(ecte6, the metho6 on)tem"lic5() i6enti&ies the presse6 net"or!, an6 create the ne" >ntent &or the ne" acti;it8 "ith the )ist)+2.c(ass. Thir6(8, this acti;it8 is the responsi.(e o& start the .ac!groun6 ser;ice "hich "i(( contro( e;er8 changes in the house sensors, an6 "i(( manipu(ate a(( the 6e;ices accor6ing to the pro&i(es settings. >n the secon6 ha(& o& )isting 4 "e can see ho" the ser;ice is starte6 "ithin a tr8-catch structure. The "a8 o& 6o it is ;er8 simi(ar to the "a8 o& start a ne" acti;it8. 2irst(8, the .eginning o& the ser;ice is recor6e6 on the (og &i(e. &ter that, it creates a ne" >ntent "ith the =ontro(Ser;ice.c(ass, "hich imp(ements a(( the &unctiona(it8 o& the ser;ice. 2ina((8, the ser;ice is starte6 .8 ca((ing the metho6 start&ervice() an6 gi;ing the create6 >ntent as a parameter. Ehen this happens, a noti&ication appears in the an6roi6 noti&ication .ar 9see 2igure 2%:. <o" this noti&ication is (aunche6 an6 the "ho(e &unctiona(it8 o& the .ac!groun6 ser;ice is 6iscusse6 in section $.$
52
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle) setContent!ie"(#.layout.device_list) lv,&(List!ie")'ind!ie"ById(#.id.#y$ist"%) )et5indo"().setBack)round6ra"a1le#esource(#.dra"a1le.my_background) cm & new Comm7an() $$ 8etc0 6ata 'rom 9#L myList & cm.)et:et"orks() lv,.setAda%ter( new ArrayAda%ter(this+ #.layout.list_item+ myList) ) lv,.setOnItemClickListener(this) $$ Start o' t0e control service try{ Lo).i()etClass().)etSim%le:ame()+ ;Startin) service...;) Intent intent & new Intent(this+ ControlService.class) startService(intent) (catch(<.ce%tion e){ 3oast toast & 3oast.make&e!t(this+ e.)et7essa)e()+ 3oast.$'()&*_+*,-&) toast.s0o"() ( (
53
@Override public boolean onCreateO%tions7enu(7enu menu){ 7enuIn'later in'later & )et7enuIn'later() in'later.in'late(#.menu.menu_house_selected+ menu) return true ( @Override public boolean onO%tionsItemSelected(7enuItem item) { $$ Handle item selection int Id & item.)etItemId() case R.id.boton1: Alert6ialo).Builder 1uilder & new Alert6ialo).Builder(this) ... Alert6ialo) alert & 1uilder.create() alert.s0o"() ( return true; case #.id.boton * Intent i & new Intent(this+ Pro'ile/settin)s.class) startActivity(i) return true default* ... return super.onO%tionsItemSelected(item) ( (
54
Then > e3p(ain in 6etai( the most important parts o& the /ro&i(eGsettings.c(ass. s "e can see in )isting 0, at the .eginning "e associate the acti;it8 "ith its G@> .8 using the metho6 set"ontent2iew(). Then a(( the contro(s o& the screen must .e a(so associate6 "ith their ;ie" in the G@>. >n this (isting > on(8 sho" one contro( o& each t8pe .8 the "ho(e (ist is o.;ious(8 (onger.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState) setContent!ie"(#.layout.profile_settings) seek1ar/li)0t & (SeekBar) 'ind!ie"ById(#.id.seek.ar_light_level) seek1ar/li)0t.setOnSeekBarC0an)eListener(this) li)0t/level & (3e.t!ie") 'ind!ie"ById(#.id.te!t_light_level) radio=rou%/close/" & (#adio=rou%)'ind!ie"ById(#. id.radio)roup_close_w) c0eckBo./outside & (C0eckBo.)'ind!ie"ById(#.id.check.o!_outside) s, & (S%inner)'ind!ie"ById(#.id.profile_list) ...
56
( while (c.move3o:e.t()) ada%ter8orS%inner.add(;:e";) ( s,.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(Ada%ter!ie"-?2 %arent+ !ie" vie"+ int %osition+ long id) { ... ( public void on:ot0in)Selected(Ada%ter!ie"-?2 %arent) { ... ( () ...
T"o more e(ements o& the screen must .e manipu(ate6 "ithin the metho6 on"reate() o& this c(ass. The "a8 in it is 6one is sho"n in )isting 1. The &irst one is the chec! .o3 that a((o" to sa8 to the app(ication that ne;er has to s"itch on the outsi6e (ight. This chec! .o3 has to 6isa.(e the see!-.ar that in6icate the outsi6e (ight (e;e( re?uire6. To 6o it "e ha;e to ca(( the metho6 set,n"hec5ed"hanged() .8 gi;ing it as parameter a ne" (istener &or this e;ent. This (istener "i(( 6isa.(e the see5bar.outside "hen the .o3 is chec!e6, an6 ena.(e it i& other"ise. >n )isting 1 "e a(so can see the imp(ementation o& the &unctiona(it8 o& the sa;e .utton. s "e(( as e;er8 .utton "e ha;e to imp(ement a ne" on"lic5%istener. This (istener creates a "ontent2alue o.,ect "here is store6 e;er8 ;a(ue that ha;e to .e up6ate6 in the 6ata .ase. Then "e put the progress o& each see!-.ar in the container an6 the correspon6ing ;a(ue o& the se(ecte6 ra6io .utton .8 using a s"itch-case structure. >n the concrete case o& the see5bar.outisde "e a(so ha;e to chec! i& the .ar is 6isa.(e. >& this happens, the ;a(ue store6 is zero. Once "e ha;e the container &i((e6, "e create a ne" pro&i(e manager an6 in;o!e its metho6 set&ettings() gi;ing the container as parameter. To en6 the process a message is 6isp(a8e6 to sa8 that the ne" settings "ere sa;e6.
5'
( ()
valores.%ut(;tem%erature;+ seek1ar/tem%erature.)etPro)ress()) switch (radio=rou%/close/".)etC0ecked#adioButtonId()) { case #.id.radio_close_w"* valores.%ut(;close/"indo"s;+ >) break ... ( if (c0eckBo./outside.isC0ecked()) { valores.%ut(;outside;+ >) ( else { valores.%ut(;outside;+ seek1ar/outside.)etPro)ress()) ( Pro'7an man & new Pro'7an()etA%%licationConte.t()) man.setSettin)s(valores+ Strin).value,f(s,.)etSelectedItemPosition() @ ,)) s0o"3oast(;:e" settin) saved;)
Iesi6es on"rete(), this c(ass has a(so a ;er8 important metho6 ca((e6 show(rofile&ettings(). This metho6 is sho"n in )isting -. 2irst o& a((, a pro&i(e manager is create6. This manager is use6 to get the pro&i(e ;a(ues .8 ca((ing its get&ettings() metho6 an6 gi;ing it the pro&i(e co6e, "hich "as recei;e6 as a parameter. Ehen "e ha;e the ;a(ues, "e ha;e to in;o!e the set(rogres() o& e;er8 see!-.ar "ith the ;a(ue store6 in the cursor as parameter. &ter that, through a s"itch-case structure, "e chec! the appropriate ra6io .utton accor6ing to the ;a(ue in the cursor. n6 &ina((8, i& the progress o& the (ast see!-.ar is zero, the outsi6e (ight chec! .o3 is chec!e6 an6 the .ar is 6isa.(e6.
5(
2+, ProfMan
>n or6er to encapsu(ate the &unctiona(it8 regar6ing management o& the pro&i(es store6 in the S?)ite 6ata .ase, > create the c(ass R/ro&ManP, &o((o"ing the st8(e o& R=ommManP &rom the pre;ious ;ersion o& DOTG. This c(ass is the responsi.(e o& access to the 6ata .ase to retrie;e 6ata o& the pro&i(e settings an6 o& the associate6 pro&i(e to each net"or!. The c(ass is a(so responsi.(e o& sa;e an8 change in the pro&i(e settings an6 association .et"een net"or!s an6 pro&i(es. This c(ass has &our pu.(ic metho6s4 get7ames9:4 =ursor getSettings9String pro&i(e:4 =ursor setSettings9=ontent+a(ues ;a(ues, String pro&i(e:4 ;oi6 get7et"or!Settings9:4 =ursor
)isting 10 sho"s an e3amp(e each !in6 o& metho6 imp(emente6 in this c(ass. Iut .e&ore this, the creation metho6 is 6e;e(ope6. s "e can see, the metho6 create a &6l(rofile o.,ect, "hich is an e3tension o& the c(ass &7%ite,penHelper. This (ast c(ass is the responsi.(e o& gi;e access to the 6ata .ase an6 create it "ith the pre6e&ine6 pro&i(es i& it is open &or the &irst time 9see ppen6i3 I4 S?(/ro&i(es.,a;a to "atch the source co6e o& this c(ass:. Then, a "rita.(e 6ata.ase is create6 .8 using this (ast o.,ect. &ter the creation, "e can see the get&ettings() metho6. 2irst o& a(( t"o arra8s o& strings are create6 to content the name o& the co(umns 6esire6 an6 the ;a(ue o& the R"hereP c(ause. Ie(o", "e ma!e the ?uer8 to the 6ata .ase through the metho6 6uery(). This metho6 nee6s se;en arguments to .e in;o!e6. The &irst one is the name o& the in;o(;e6 ta.(e, &o((o"e6 .8 the arra8 o& co(umns, the R"hereP c(auses an6 the arra8 "ith the ;a(ues o& this c(auses. The (ast three parameters represent the RgroupI8P, Rha;ingP an6 Ror6erI8P c(auses respecti;e(8.
59
( ... (
s e3amp(e o& a metho6 to "rite in the 6ata .ase "e a(so ha;e the set&ettings() in the )isting 10. This metho6 recei;e as parameter the ;a(ues that has to store, an6 the co6e o& the pro&i(e in ?uestion. The "e on(8 ha;e to put the pro&i(e co6e in an arra8 o& strings an6 ca(( the update() metho6 o& the 6ata .ase o.,ect, "hich re?uires &our parameters4 the name o& the ta.(e, the ;a(ues, the R"hereP c(ause an6 the ;a(ue to this c(ause.
2+0 8ttpClient
The http c(ient c(ass is the comp(ementar8 c(ass o& the =ommunication Manager 6e;e(ope6 in the pre;ious ;ersion o& DOTG. The responsi.i(it8 o& this c(ass is to sen6 to the <ome/ort ser;er the /@T an6 GET ?uer8 "hich a(ter or rea6 the status o& the sensors an6 the actuators "ithin the contro((e6 houses. This c(ass is use6 .8 the contro( ser;ice e;er8 time that it nee6 to manipu(ate an actuator or it nee6 to !no" the current state o& the house. s "e(( as its comp(ementar8 c(ass R=ommManP encapsu(ates the &unctiona(it8 regar6ing the net"or! structure, this c(ass a(so 6oes the same "ith the access to 6e;ices. >& .ecause some reason the "a8 to manipu(ate is change6 in the &uture, than!s to the R<ttp=(ientP c(ass the app(ication "ou(6 .e a&&ecte6 s(ight(8. This c(ass imp(ements three main metho6s. The &irst o& them is se t&tate(), "hich nee6 as parameters the i6 o& the 6e;ices to .e manipu(ate6, an6 ;a(ue "hich represent the 6esire6 state. The secon6 metho6 is get&tate(). >n this case, it recei;es the i6 o& the 6e;ice an6 return an string "ith the current state o& the 6e;ice. This t"o metho6s use the thir6 o& them "hich is ca((e6 e8ecuteHttp9et(). s its name sa8s, it is the responsi.(e o& e3ecute the re?uest gi;en as a parameter .8 the the other t"o metho6s. Then, .8 using a .u&&ere6 rea6er, it store the ser;er response an6 return it as a string. 9See appen6i3 = to "atch the source co6e o& this c(ass:. Moreo;er, this c(ass shou(6 a(so .e the responsi.(e o& the securit8 6uring the communication process using the SS) metho6 re?uire6 .8 the <ome/ort 6e;e(opment team. >n the pre;ious ;ersion o& DOTG cou(6nQt 6e;e(op this !in6 o& securit8 6ue to some incompati.i(ities .et"een the &ormat use6 .8 the ,a;a truststore, "here the certi&icate an6 pri;ate !e8 must .e store6, an6 the &ormat o& the pri;ate !e8 pro;i6e6 .8 the <ome/ort cre". @n&ortunate(8 this pro.(em ha;e not .een a.(e to .e &i3e6 in the current ;ersion 6ue to time constraints. <o"e;er a simu(ation o& a <ome/ort ser;er, "ithout an8 re?uirement a.out the SS) securit8, "as 6e;e(ope6 .8 /eter 2in6erup, "ho is one o& the t"o 6e;e(opers o& the (ast ;ersion. This simu(ation can .e chec!e6 out in """.homeport.6!. >n this "e. site "e a(so can see a(( the .eha;iora( o& this app(ication in a graphica( an6 intuiti;e "a8.
60
>n )isting 11 "e can see ho" it is necessar8 to o;erri6e three metho6s that are not 6e&ine6 in the pre6ecessor c(ass. The &irst o& this metho6 is on"reate() "hich on(8 store in a (ist o& (ists, ca((e6 1etDev, the net"or!s an6 the 6e;ices a;ai(a.(e "ithin them. This (ist is o.taine6 as resu(t o& in;o!e the metho6 get1etwor5Devices(). Su.se?uent(8 the metho6 on&tart"ommand() is o;erri6e, "hich is in;o!e6 "hen the metho6 start&ervice() is ca((e6. 2irst(8, "e create a timer an6 then "e assign it a tas! an6 a time perio6 o& 1 minute to "ait unti( repeat this tas!. s "e can see, the responsi.i(it8 o& this timer is to e3ecute the metho6 "hich "i(( chec! a(( measurements
61
o& the sensors on each net"or! an6 "i(( manipu(ate the 6e;ices as appropriate. &ter the timer, a status .ar noti&ication is create6 an6 6isp(a8e6 to "arn the user that the contro( ser;ice is running in .ac!groun6. t the en6, "e return a constant ca((e6 &TA#T.&T)":; "hich in6icate that the ser;ice "i(( .e e3p(icit(8 starte6 an6 stoppe6 to run &or ar.itrar8 perio6s o& time. 2ina((8 "e o;erri6e the metho6 onDestroy() that stops the timer .8 ca((ing its metho6 cancel(), an6 6isp(a8s a message "arning the user a.out the en6 o& the ser;ice. /re;ious(8 > ha;e ta(!e6 a.out a metho6 responsi.(e o& coor6inate the manipu(ation o& the house 6e;ices accor6ing to the sensors 6e;ices an6 the pro&i(e settings. This metho6 is chec5AndAd-ust(). The &irst thing that the metho6 6o is to create a cursor "ith a(( the settings o& e;er8 net"or! through a pro&i(e manager. This cursor inc(u6es the i6 o& each net"or! "ith the settings o& the pro&i(e it has associate6. Then, at the same time that the cursor mo;es &or"ar6, "e in;o!e a set o& metho6s. Each o& them is specia(ize6 in a 6i&&erent t8pe o& 6e;ices an6 recei;es as parameters the 6ata regar6ing this t8pe. Ie(o" "e can see in )isting 12 the source co6e o& this metho6.
Since the co6e o& these metho6s are te6ious .ut not too con;o(ute6, > "i(( e3p(ain ho" "or!s each o& them .ut "ithout sho"ing an8 co6e &ragment. The &irst that appears in )isting 12 is manage%ights() an6 as "e can see it recei;e t"o parameters. The &irst one is the (ight (e;e( 6esire6 .8 the user insi6e the house, an6 the secon6 one, "hich is common to a(( this metho6s, is the net"or! i6. This metho6 chec!s the presence sensors to !no" i& someone is in the house. >& that is true, it turns on s"itches an6 a6,usts 6immers to achie;e the re?uire6 (ight (e;e(. >n case o& no one is in the house, it s"itches o&& e;er8 (ights to sa;e energ8. The secon6(8 metho6 ca((e6 is mangeTemperature(). This metho6 re?uires the 6esire6 temperature (e;e( as parameter .esi6es the i6 o& the net"or!. Once the 6esire6 temperature is !no"n, it is compare6 "ith the rea( temperature insi6e the house measure6 .8 the thermostats. Then a(( the ra6iators an6 heaters are turne6 up
62
or 6o"n accor6ing to this comparison. Moreo;er, i& the temperature insi6e the house is more than %Y higher than the 6esire6, the "in6o"s are opene6 .8 1$F in or6er to re&rigerate the house. This (ast, is on(8 6one i& the "in6o"s are not a(rea68 open an6 it is not raining outsi6e. This metho6 a(so consi6er the presence sensors, so i& no.o68 is in the house, it "i(( turn e;er8 ra6iator an6 heater to 10Y to sa;e energ8. Then it is in;o!e6 the manage0indows() metho6, gi;ing it as parameter the ;a(ue "hich sa8s "hen the "in6o"s must .e c(ose6. The &unctiona(it8 o& this metho6 is ?uite simp(e. 2or e3amp(e4 i& the user se(ecte6 the option R"hen rainP, it "i(( chec! the rain sensor an6 "i(( c(ose the "in6o"s i& it is raining in that moment. >& that is not true, it "onQt 6o an8thing. This .eha;ior is the same i& the option se(ecte6 "as REhen "in6P "ith the 6i&&erence that the sensor chec!e6 is the "in6 sensor. 2urthermore, i& the user chose thir6 option, R ("a8sP, the metho6 "i(( 6o the same than .e&ore, .ut chec!ing .oth sensor an6 c(osing a(( "in6o"s i& one o& them is 6etecting something. 2ina((8, "hen the option Rne;erP "as chosen, the metho6 6oes not chec! an8 sensor an6 ne;er c(oses an8 "in6o". The (ast metho6 in;o!e6 is manage,utdoor%ights(). >t recei;es as parameters the (imit (ight (e;e( nee6e6 outsi6e to maintain s"itche6 o&& the out6oor (ights an6 (ampposts. Ehen this metho6, .8 chec!ing the outsi6e (ight sensor, 6etect that it is 6ar!est than 6esire6, it turns on a(( the out6oor (ights.
63
>n a66ition to the 6e;ice emu(ator, the n6roi6 SDO a(so pro;i6es some other too(s "hich "ere ;er8 use&u( 6uring the imp(ementation process. On the o& them is the Da(;i! De.ug Monitor Ser;er 9DDMS:. This too( pro;i6es a &i(e .ro"ser &or the 6e;ice5emu(ator memor8 content, port-&or"ar6ing ser;ices, screen capture on the 6e;ice, threa6 an6 heap in&ormation on the 6e;ice, (ocation 6ata spoo&ing, among other &eatures.
Other too( ;er8 use&u( pro;i6e6 .8 the SDO is the n6roi6 De.ug Iri6ge 9 DI:. This is a comman6 (ine too( that (ets 8ou communicate "ith an emu(ator instance or connecte6 n6roi6-po"ere6 6e;ice. >t is a c(ient-ser;er program that inc(u6es three components4 a c(ient "hich runs on 8our 6e;e(opment machine, a ser;er that runs as a .ac!groun6 process on the 6e;e(opment machine an6 a 6aemon, "hich a(so runs as a .ac!groun6 process on each emu(ator or 6e;ice instance. DI a((o" 8ou to issue a &e" 6i&&erent comman6s &rom a comman6 (ine on the 6e;e(opment computer, .eing the comman6 shell the most use6 6uring the 6e;e(opment o& DOTG. This comman6 Starts a remote she(( in the target emu(ator56e;ice instance gi;ing 8ou access as i& it "as a common (inu3 machine. Than!s to this she(( an6 the s?(ite% comman6, "e are a.(e to ?uer8 an8 in&ormation &rom the app(ication 6ata .ase as is 6one in an8 other SW) 6ata.ase.
2ina((8, as > a(rea68 remar!e6 in section $.4, some thing essentia( to test the imp(ementation "as the "e. site """.homeport.6! a(so 6e;e(ope6 .8 an a(.org @ni;ersit8 stu6ent. This "e.site simu(ates a <ome/ort ser;er a((o"ing to .e han6(e6 .8 <ttp GET an6 /@T ?ueries. 2urthermore it preten6 to .e as contro((ing a rea( house "ith 6i&&erent !in6 o& t8pica( (ocations "ithin a house an6 "ith 6e;ices o& 6i&&erent t8pes insta((e6 in these (ocations. >n )isting 1% > sho" an e3amp(e o& a http ?uer8 use6 to manipu(ate a ra6iator insta((e6 in the !itchen.
Htt%*$$""".0ome%ort.dk$ont0e)o.%0%?id&kitcrr,Lstate&AB
The &irst part o& the @A> a66ress regar6s the "e.site. Then "e can see that "e ca(( to a &i(e ca((e6 onthego.php "hich is the responsi.(e o& respon6 to our re?uest as i& it "as a <ome/ort ser;er. Then "e gi;e as parameters the i6 o& the 6e;ice in ?uestion, an6 the ne" ;a(ue &or its status. The e&&ect o& this ?uer8 can .e appreciate6 (ater i& "e .ro"se in the "e. site to the !itchen 6e;ices page. >n case "e on(8 gi;e it the &irst parameter, the ser;er "i(( rep(8 us "ith a simp(e string in6icating the state o& the 6e;ice.
65
3 Conclusions
&ter a stu68 comparing the sa(es in the smartphone mar!et > i6enti&ie6 the n6roi6 OS as the mo.i(e p(at&orm "ith more gro"th e3pectations, an6 as "hich contains a greater num.er o& potentia( users o& Domotics On-The-Go. > ha;e 6e;e(ope6 a mo.i(e app(ication .8 &o((o"ing the re?uirement e3pose6 in the ana(8sis section an6 achie;ing a(most a(( o& them. This app(ications, .ase6 on a pre;ious simp(e ;ersion, is a.(e to connect to a remote ser;er an6 interact "ith it .8 using the http re?uest. Moreo;er it is a.(e to retrie;e a(( the in&ormation a.out ho" are 6istri.ute6 the home 6e;ices .8 parsing its 6escription &i(e 3m(, an6 represent this structure in a &rien6(8 an6 use&u( "a8. 2urthermore, Domotics On-The-Go a(so a((o" the user to create an6 manage con&iguration pro&i(es in or6er to change the 6e;ice status an6 the house .eha;ior ?uic!(8 an6 easi(8. @n&ortunate(8, 6ue to time constraints, the re?uirement regar6ing the securit8 connection using the SS) protoco( cou(6 not .e reache6. 7e;erthe(ess the imp(ementation cou(6 .e teste6 "ithout this &eature than!s to the e3istence o& a ser;er simu(ation, a(so 6e;e(ope6 as a @ stu6ent pro,ect. Moreo;er, this (ast re?uirement "i(( .e easi(8 a66resse6 in a &uture "or! than!s to the 6e;e(ope6 c(ass Http"lient, "hich encapsu(ates a(( the responsi.i(it8 o& sen6 an6 recei;e a(( the re?uest to the remote ser;er. This c(ass can .e su.stitute6 "ith no ma,or changes to the rest o& the architecture. Iecause o& that, the app(ication can .e a(so easi(8 a6apte6 to an8 other s8stem re?uiring an8 other !in6 o& communication protoco(. s "e(( as the (ast c(ass, the /ro&Man encapsu(ates the &unctiona(it8 to manage the pro&i(es. Than!s to this, the app(ication cou(6 .e impro;e6 in the &uture a66ing more 6etai(s to the pro&i(es or sa;ing it in the c(ou6, "ithout serious(8 a&&ecting to "ho(e app(ication. 2ina((8 > succee6e6 to imp(ement a(( the contro( scenarios propose6 6uring the ana(8sis chapter .8 creating the =ontro( Ser;ice. This ser;ice runs in .ac!groun6 an6 ta!es care o& e;er8 6e;ices in the house are set accor6ing to the pro&i(e se(ecte6 an6 the house measurements pro;i6e6 .8 the a;ai(a.(e sensors.
66
more e&&icient .eha;ior o& the manage6 house. Ie(o" > propose some e3amp(e o& &uture "or! ta!ing into account these issues4 /oice recognition More an6 more mo.i(e app(ications are integrating this &eature "hich a((o" a &ree han6 interaction "ith the mo.i(e phone. >n the case o& Domotics On-The-Go, this &eature "ou(6 gi;e the user the possi.i(it8 o& interact "ith their house ta(!ing to the phone. 2or e3amp(e, the user cou(6 change the current pro&i(e, or acti;ate the securit8 s8stem "hi(e he is 6ri;ing using the &ree han6 6e;ice. .ocation commands s "e(( as the ;oice recognition, this &eature is present in e;er more smartphone app(ications. Than!s to this, the app(ication ma8 c(ose the 6oors an6 "in6o"s "hen the user is going a"a8 &rom the house or start to heat the house "hen the app(ication 6etects that he is going .ac!. /ariet# of platforms (though n6roi6 p(at&orm "as recognize6 as .eing "hich has more potentia( c(ients, other p(at&orm (i!e pp(e iOS or I(ac!.err8 OS a(so ha;e a ;er8 important presence in the smartphone mar!et. Iecause o& that, is necessar8 a("a8s consi6er the possi.i(it8 o& 6e;e(op other ;ersions o& this app(ication to .e e3ecute in other p(at&orms.
6'
6(
Z5parameters] Z5ser;ice] Z56e;ice] Z6e;ice ui6\JE400000D00I=1$00J ip\J1-2.101.1.22$ J i6\J!itccmJ (ocation\J!itchenJ t8pe\J# 021 2104010-00010100000%0004000$000000020#0 000-00010004J port\J10002J 6esc\Jco&&ee machineJ] Zser;ice ;a(ueGur(\Jhttp455room.rige$.410105ser;ices5=0 101-1=0 101E12#125some-i64J i6\Jsome-i64J 6esc\JAegu(a.(e "in6o"J] Zparameters] Zparameter min\J0J ma3\J100J step\J1J t8pe\JintJ i6\J1J unit\Jpercentage opene6J5] Z5parameters] Z5ser;ice] Z56e;ice] Z6e;ice ui6\J1#1#010000I=1$00J ip\J1-2.101.1.22$J i6\J!itcts1J (ocation\J!itchenJ t8pe\J# 02102204010#01010%00000%000004010 00J port\J10002J 6esc\Jtemperature sensorJ] Zin&o5] Zser;ice ;a(ueGur(\Jhttp455room.rige$.410105ser;ices5=0 101-1=0 101E12#1%5somei60J i6\Jsomei60J 6esc\Jtemperature sensorJ] Zparameters] Zparameter t8pe\JstringJ ;a(ues\JOn, O&&J i6\J1J5] Z5parameters] Z5ser;ice] Z56e;ice] Z6e;ice ui6\J1#1#010000I=1$00J ip\J1-2.101.1.22$J i6\J.e6r(p1J (ocation\J.e6roomJ t8pe\J# 02102204010#01010%00000%000004010 00J port\J10002J 6esc\J(ampJ] Zin&o5] Zser;ice ;a(ueGur(\Jhttp455room.rige$.410105ser;ices5=0 101-1=0 101E12#1%5somei60J i6\Jsomei60J 6esc\J(ampJ] Zparameters] Zparameter t8pe\JstringJ ;a(ues\JOn, O&&J i6\J1J5] Z5parameters] Z5ser;ice] Z56e;ice] Z6e;ice ui6\J1#1#010000I=1$00J ip\J1-2.101.1.22$J i6\J.e6r"61J (ocation\J.e6roomJ t8pe\J# 02102204010#01010%00000%000004010 00J port\J10002J 6esc\J"in6o"J] Zin&o5] Zser;ice ;a(ueGur(\Jhttp455room.rige$.410105ser;ices5=0 101-1=0 101E12#1%5somei60J i6\Jsomei60J 6esc\J(ight s"itchJ] Zparameters] Zparameter t8pe\JstringJ ;a(ues\JOn, O&&J i6\J1J5] Z5parameters] Z5ser;ice] Z56e;ice] Z5net"or!]
69
Znet"or! name\Jo&&iceJ] Z5net"or!] Znet"or! name\Jsummer resi6enceJ] Z6e;ice ui6\JE400000D00I=1$00J ip\J1-2.101.1.22$J i6\JmarioooooooJ (ocation\J.e6roomJ t8pe\J# 021 2104010-00010100000%0004000$000000020#0 000-00010004J port\J10002J 6esc\JDe;e(co Nig.ee (ight s"itch 6e;ice J] Zser;ice ;a(ueGur(\Jhttp455room.rige$.410105ser;ices5=0 101-1=0 101E12#125some-i61J i6\Jsome-i61J 6esc\JOn5O&& s"itchJ] Zparameters] Zparameter t8pe\JstringJ ;a(ues\JOn, O&&J i6\J1J5] Z5parameters] Z5ser;ice] Zser;ice ;a(ueGur(\Jhttp455room.rige$.410105ser;ices5=0 101-1=0 101E12#125some-i6%J i6\Jsome-i6%J 6esc\Je(ectrica( Energ8 counterJ] Zparameters] Zparameter min\J0J ma3\J2114#4-#0#100$$J step\J1J t8pe\JintJ i6\J1J unit\J"atthourJ5] Z5parameters] Z5ser;ice] Z56e;ice] Z5net"or!] Z5m8net"or!s] Z56e;ice(ist]
'0
Appendix ): S-lProfiles+:ava
public class SDlPro'iles extends SELiteO%enHel%er { Strin) sDlCreate & ;C#<A3< 3ABL< Pro'iles (codi)o I:3<=<#+ nom1re 3<M3+ li)0tLevel I:3<=<#+ tem%erature I:3<=<#+ close/"indo"s I:3<=<#+ outside I:3<=<#); Strin) sDlCreateA & ;C#<A3< 3ABL< :et"ork (name S3#I:=+ currentPro'ile I:3<=<#); public SDlPro'iles(Conte.t conte.to+ Strin) nom1re+ Cursor8actory 'actory+ int version) { super(conte.to+ nom1re+ 'actory+ version) ( @Override public void onCreate(SELite6ata1ase d1) { d1.e.ecSEL(sDlCreate) Content!alues nuevo#e)istro & new Content!alues() nuevo#e)istro.%ut(;codi)o;+ ,) nuevo#e)istro.%ut(;nom1re;+;Per'il ,;) nuevo#e)istro.%ut(;li)0tLevel;+ K>) nuevo#e)istro.%ut(;tem%erature;+ ,N) nuevo#e)istro.%ut(;close/"indo"s;+ ,) nuevo#e)istro.%ut(;outside;+ ,>>) d1.insert(;Pro'iles;+ null+ nuevo#e)istro) nuevo#e)istro.clear() nuevo#e)istro.%ut(;codi)o;+ A) nuevo#e)istro.%ut(;nom1re;+;Per'il A;) nuevo#e)istro.%ut(;li)0tLevel;+ A>) nuevo#e)istro.%ut(;tem%erature;+ A>) nuevo#e)istro.%ut(;close/"indo"s;+ A) nuevo#e)istro.%ut(;outside;+ ,>) d1.insert(;Pro'iles;+ null+ nuevo#e)istro) d1.e.ecSEL(sDlCreateA) nuevo#e)istro.clear() nuevo#e)istro.%ut(;name;+ ;0ome;) nuevo#e)istro.%ut(;currentPro'ile;+ ,) d1.insert(;:et"ork;+ null+ nuevo#e)istro) nuevo#e)istro.clear() nuevo#e)istro.%ut(;name;+ ;o''ice;) nuevo#e)istro.%ut(;currentPro'ile;+ A) d1.insert(;:et"ork;+ null+ nuevo#e)istro) nuevo#e)istro.clear() nuevo#e)istro.%ut(;name;+ ;summer residence;) nuevo#e)istro.%ut(;currentPro'ile;+ A) d1.insert(;:et"ork;+ null+ nuevo#e)istro) ( @Override public void on9%)rade(SELite6ata1ase d1+ int versionAnterior+ int version:ueva) { d1.e.ecSEL(;6#OP 3ABL< I8 <MIS3S Pro'iles;) d1.e.ecSEL(sDlCreate) (
'1
Appendix C: M#8ttpClient+:ava
public class 7yH33PClient { private Conte.t conte.t public 7yH33PClient(Conte.t cnt.t) { conte.t & cnt.t ( public Strin) )etCurrentState(Strin) device) { SDl6evices devd10 & new SDl6evices(conte.t+ ;6B6evices;+ null+ ,) SELite6ata1ase d1 & devd10.)et#eada1le6ata1ase() Strin)FG cam%os & new Strin)FG { ;id;+ ;name;+ ;status;+ ;location;+ ;ty%e; ( Strin)FG ar)s & new Strin)FG { device ( Cursor c & d1.Duery(;6evices;+ cam%os+ ;id&?;+ ar)s+ null+ null+ null) int nameColumnInde. & c.)etColumnInde.Or30ro"(;status;) Strin) status & ;; if (c.move3o8irst()) { do { status & c.)etStrin)(nameColumnInde.) ( while (c.move3o:e.t()) if (d1 O& null) { d1.close() ( ( return status ( public Strin) setState(Strin) device+ int value) { Strin) tem% & ;; try { tem% & e.ecuteHtt%=et(device+ ;0tt%*$$""".0ome%ort.dk$ont0e)o.%0%?id&;@ device @;Lstate&;@ value ) ( catch( <.ce%tion e ){( return tem% ( public Strin) setSensor(Strin) device+ int value) { SDlPro'iles usd10A & new SDlPro'iles(conte.t+ ;6BPro'iles;+null+ ,) SELite6ata1ase d1 & usd10A.)et5rita1le6ata1ase() Content!alues values & new Content!alues() values.%ut(;status;+ value) Strin) ar)FG & {device( d1.u%date(;6evices;+ values+ ;id&?;+ ar)) return device ( public Strin) )etState( Strin) device ){ Strin) tem% & ;; try { tem% & e.ecuteHtt%=et(device+ ;0tt%*$$""".0ome%ort.dk$ont0e)o.%0%?id&; @ device) tem% & tem%.re%lace(;Pn;+ ;;) ( catch( <.ce%tion e ){( return tem% ( public Strin) e.ecuteHtt%=et(Strin) deviceI6+ Strin) DueryStrin)) throws <.ce%tion { Bu''ered#eader in & null Strin) %a)e & ;;
'2
( (
try { Htt%Client client & new 6e'aultHtt%Client() Htt%=et reDuest & new Htt%=et() reDuest.set9#I(new 9#I( DueryStrin) )) Htt%#es%onse res%onse & client.e.ecute(reDuest) in & new Bu''ered#eader(new In%utStream#eader(res%onse.)et<ntity().)etContent())) Strin)Bu''er s1 & new Strin)Bu''er(;;) Strin) line & ;; Strin) :L & System.get6roperty(;line.se%arator;) while ((line & in.readLine()) O& null) { s1.a%%end(line @ :L) ( in.close() %a)e & s1.toStrin)() ( finally { if (in O& null) { try { in.close() ( catch (IO<.ce%tion e) { e.%rintStack3race() ( ( return %a)e (
'3
Bi6liogra(0%
1= 3droid -evelopersC Plat5orm DersionsC 2011C 6ttp=??developer.android.com?resources?das6board?plat5orm$versions.6tml 2= 3ndroid -evelopersC 0creen 0iEes and -ensitesC 2011C 6ttp=??developer.android.com?resources?das6board?screens.6tml 3= 3ndroid.comC -ata 0tora!eC C 6ttp=??developer.android.com?!uide?topics?data?data$stora!e.6tml 4= 3ndroid.comC pac a!e android.database.s4liteC C pac a!eandroid.database.s4lite 5= 3ppleC -eveloper ios dev centerC C 6ttp=??developer.apple.com?ip6one? 6= 3rne 0 ouC *omeport 6ome pa!eC C 6ttp=??999.ener!/bo2.d ?en?partners? '= 3rs 8ec6nicaC iP6one in dept6= t6e 3rs revie9C C 6ttp=??arstec6nica.com?apple?revie9s?200'?0'?ip6one$revie9.ars?6 (= "R,C Blac Berr/ :sers "all <or RIM 8o Ret6in 0erviceC C 6ttp=??999.crn.com?ne9s?client$ devices?2220025('?blac berr/$users$call$5or$rim$to$ret6in $service.6tm 9= 1d BurnetteC *elloC 3ndroidC 10= 1ner!/bo2.d C *omeportC C 6ttp=??999.ener!/bo2.d ?en?6ome.6tm 11= ;artnerC ;artner sa/s 9orld9ide pc s6ipments !re9 '.6 percent in t6ird 4uarter o5 2010C C 6ttp=??999.!artner.com?it?pa!e.>spFidG1451'42 12= ;artnerC Inc.C &orld9ide Mobile -evice 0ales to 1nd :sers Reac6edC C 6ttp=??999.!artner.com?it?pa!e.>spFidG1543014 13= I-"C ;lobal pc mar et maintains double$di!it !ro9t6 in t6ird 4uarter despite 9ea results in somese!mentsC accordin! to idc.C C 6ttp=??999.idc.com?about?vie9pressrelease.>spF containerIdGpr:022531110HsectionIdGnullHelementIdGnullHpa!e8/peG0I,)P0I0 14= Indi!oC Perceptive 3utomation. 3utomate /our 6ome 9it6 Indi!oC C 6ttp=??999.perceptiveautomation.com?indi!o?inde2.6tml 15= I) 6omecontrolC *o9 does it 9or C C 6ttp=??999.io$6omecontrol.com?en?pros$area?6o9$does$it$ 9or .6tml 16= Jeppe BrKnstedC Per PrintE MadsenC 3rne 0 ouC Rune 8orbesenC 86e *omePort 0/stemC 1'= +,# 3ssociationC &6at is +,#FC C 6ttp=??999. n2.or!? n2?96at$is$ n2? 1(= .eonard Ric6ardsonC 0am Rub/C R1085ul &eb 0ervicesC 2005 19= M. 0ipserC Introduction to t6e 86eor/ o5 "omputationC 1996 20= ,eil Mc3llisterC 0-+ s6oot$out= 3ndroid vs. iP6one $ 3pple and ;oo!le di55er alon! 5amiliar lines 9it6 t6eir smartp6one development itsC 200(C 6ttp=??999.in5o9orld.com?d?developer$ 9orld?sd $s6oot$out$android$vs$ip6one$0'4 21= ,etscape "omunicationsC 86e 00. Protocol Dersion 3.0C C 6ttp=??999.moEilla.or!?pro>ects?securit/?p i?nss?ssl?dra5t302.t2t 22= )pen *andset 3lianceC 3liance MembersC C 6ttp=??999.open6andsetalliance.com?o6a@members.6tml 23= Perceptive 3utomationC domotics $ control at /our Ln!ertipsC C 6ttp=??999.domotics.u .com? 24= Pico 1lectronicsC #10 Aindustr/ standardBC C 6ttp=??en.9i ipedia.or!?9i i?#10@Aindustr/@standardB 25= R. <ieldin!C J. ;ett/sC J. Mo!ulC *. <r/st/ C .. MasinterC P. .eac6C and 8. Berners$.eeC */perte2t trans5er protocolC 1999C 6ttp=999.iet5.or!?r5c?r5c2616.t2t 26= Reto MeierC Pro5essional 3ndroid 2 3pplication -evelopmentC 2010 2'= retrocom.comC Bell0out6 $ 0imonC C 6ttp=??999.retrocom.com?bellsout6@ibm@simon.6tm 2(= Ro/ 86omas <ieldin!C 3rc6itectural st/les and t6e desi!n o5 net9or $based so5t9are arc6itecturesC 2000 29= 0.3. 86omasC 00. H 8.0 essentialsC 2000 '4
30= 0toc 6omsmartp6oneC *istor/C C 6ttp=??999.stoc 6olmsmartp6one.or!?6istor/? 31= 8eliaC 0al! a5 smartp6ones i danmar .C C 6ttp=??999.mobilsiden.d ?n/6eder?boom$i$sal!et$a5$ smartp6ones$i$danmar Clid.12139? 32= 86e Mobile BeatC ;oo!leMs 3ndroid becomes t6e 9orldMs leadin! smart p6one plat5ormC 2011C 6ttp=??999.t6emobilebeat.com?arc6ives?43(4 33= Derisi!nC "entro de in5ormaciNn sobre 00. / credibilidad en lOneaC C 6ttp=??999.verisi!n.es?ssl?ssl$in5ormation$center?inde2.6tml 34= 2mlpull.or!C Puic Introduction to #mlPullC C 6ttp=??999.2mlpull.or!?v1?do9nload?unpac ed?doc?4uic @intro.6tml 35= %ens/sC %$9ave speciLcationC 36= %i!Bee 3llianceC %i!bee speciLcationsC C 6ttp=??999.Ei!bee.or!?Mar ets?%i!Bee0mart1ner!/?0peciLcation.asp2 3'= ".IP03. inte!rated s/stemsC "$bus speciLcationsC C 6ttp=??999.cbus$enabled.com 3(= 0imon 0ilvesterC Mobile Mania= a manual 5or t6e second internet revolution.C 2010C 6ttp=??pubs.9underman.com?mobilemania?
'5