TELKOM NIKA Indonesia n  Journal of  Electrical En gineering   Vol.12, No.6, Jun e  201 4, pp. 4802 ~ 4 8 0 7   DOI: 10.115 9 1 /telkomni ka. v 12i6.552 5          4802     Re cei v ed  De cem ber 3 0 , 2013; Re vi sed  March 12, 20 14; Accepted  March 28, 20 14   Deployment of TinyOS for Online Water Sensing      Xin Wang*, Pan Xu  Ke y   Lab orator y of Advance d  Process Co ntrol  fo r Light Ind u str y  (Min i str y  of  Educati on),   Jian gna n Un iv ersit y , W u xi 2 1 412 2, PR Chi n *Corres p o ndi n g  author, e-ma i l w a ng xin@ jia ngn an.e du.cn       A b st r a ct   Current  qua lity  assess me nt meth ods  of w a ter par a m eters   are mai n ly la boratory bas ed requir e   fresh supp lies  of che m ica l s, train ed staff an d are time  con s umin g. Senso r  netw o r ks are great alter nativ es   for such requ ir ements. W e  present a pr actic a l ap plic at io n o f  w i reless netw o rks: a  remote water m o nitoring  system  r u nning TinyOS. The contents of several c h em icals in the water  are sensed and trans m i tted.  The  sensor  d a ta  are co llecte d   an d trans mitted v i a Z i gBee   a n d   GPRS. Instead  of foc u sin g   on  theor etic  issu e s   such as r outi n g al gorith m s, n e tw ork lifetime  and s o  o n w e  inv e stigat e s peci a l tech ni qu es inv o lve d  i n   the  imple m entati o n  of the system w h ile e m p l oyi n TinyOS and i t s special pr ogr amming l a n g u age.     Ke y w ords : Tin y OS, hierarchi c al netw o rk, emb e d ded  oper ating syste m , w a ter sensing       1. Introduc tion  TinyOS is a n  op en  so urce, BSD-li c e n se d o perating  system  d e sig ned  for l o w-po we wirel e ss d e vice s, su ch a s   those u s e d  in  sen s o r  networks, ubi quito us  comp uting ,  personal a r ea  netwo rks,  sm art b u ilding s ,  and  smart   meters. To  confront  the  water p o llutio n , vario u s water  monitori ng systems ba se d on cellul a r mobile net work have b een develo p ed [1, 2]. T hese  sy st em s may  assi st  env ir o n ment al  p r ote c tion ag en cie s  in providing  continu o u s   water m onito ring   with mi nimu m interactio n  of ma n i n terferen ce. B u t, with  su ch sy stem s, t he  rare  ch a nnel  resou r ces  an d ha rd ware a r e g r eatly wa sted  whe n  th e monito ring  node s a r distributed i n  hig her  den sity. The  hiera r chi c al  o r gani zatio n  [3 ], grou ping  of the m onitori ng n ode bef ore t r an sferri ng  the se nsor  data to hig h e r level s , is one of  th e  mechani sm s p r op osed  to deal  with  that  extravagan ce  and is  co mm only refe rre to as  cluste ri ng [4]. This p aper i s  to  sho w  a hie r a r chi c al  architectu re,  whi c h i s  lo w i n  cost, ea sy t o  cons t r u c t, less de pen de nt upon  net work infra s truct u re,  is  im pleme n ted  by empl o y ing  ZigBe e  and GPRS d e vice s, an esp e ci ally wit h  TinyOS  as the  sen s o r  net w o rk s’ ope rat i n g  sy st em.       2. Rese arch  Metho d   Stru cture a nd Co mposition of the Sy stem  TinyOS is de sign ed to run  on sm all, wireless  sen s o r s.  Net w orks of  these sen s ors have  the pote n tial  to revolutio n ize  a  wid e   rang e of  disciplin es, fiel d s , an d te chn o logie s Re cent  example u s e s  of the s e d e v ices i n cl ude  Golde n  Gate  Bridge  safety, volcani c mo n i toring a nd d a t a   cente r  provisi oning.   The  hierarchi c al  network i s  m ade  up  of  one  Ba se St ation a nd  so me mo nitorin g  no de s,  as is sho w n i n  Figure 1. T hese monitori ng node are  resp on sible for sa mpling t he wate r, sin g le- hoppi ng the data to the base stati on  by ZigBee chann el, while  the Base Station is set for  coo r din a tion  betwe en the  node s, se ndi ng the sen s o r   data which is coll ecte d from the nod e s  to   the remote m anag ement pl atform.  The Ba se St ation is com posed of  onli ne mo nitorin g  device, G P RS (G ene ral pa cket  radio  se rvice) DT U and  Zig B ee Mod u le (worke d a s  a  coo r din a tor,  FFD), as i s   shown in Fig u re 2.  The  o n line monitori ng  d e vice whi c h use s  CP1 H  PLC  ma de b y   OMRO N a s   the co ntroll er  i s   respon sibl e f o r te sting  the   con c e n tration  of  NO 3 - , PO 43- an d P H  v a lue. GP RS  DTU impl eme n ts  the tran smission of the rem o te sign als by  GPRS netwo rk.    GPRS i s  a  pa cket o r i ented  mobil e  dat a  serv ice  on th 2G a nd  3G  cell ular  comm uni cati on sy stem' s   global  syste m  for mo bile  comm uni cati ons  (GSM while ZigBe e  i s  ne w   spe c ification  for a  suite of  high level  communi catio n  proto c ol s u s ed to  creat e perso nal a r ea   netwo rks built  from small, l o w-po we r dig i tal radio s   Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOM NIKA   ISSN:  2302-4 046     Depl oym ent of TinyOS for On line Water Sensing  (Xin  Wang 4803 M a n agem e n t   Pl a t f o r m Da t a C ent e r Mo n i t o r C ent e r S Q L Q uer y In te r n e t GP R S   Figure 1. Top o logy of the Network and  Remote  M a n ageme n t Platform. The Di sc Stand s for  Base Station,  Circl e  for Mo nitoring  Nod e s       ZigBee mo du le is m ade u p  of MSP430  cont rolle r an d CC24 20  RF chi p . It is use d  to   read th e data  of the wate r in PLC, colle cts the  data  of water i n  th e other m onit o ring  nod es  and  excha nge s th e data  with th e re mote m a nagem ent pl a tform. Differe nt from th e B a se  Station, the  monitori ng n ode, on the o t her ha nd, do es not in clud e GPRS DT U, and its Zi gBee mod u le  is a   Red u ced Fun c tion Device (RFD).       GPR S  DTU Z i gB ee M o dule On li ne   M easuring I/ O A/D Seri al Ca b l e PLC Se ri al Cable TinyOS MC U DT U Re l a y s Sensors     Figure 2. Co mpone nts of the Ha rd wa re  of the Base Station      3. Zigbee Mo dule  Both FFD  an d RF D a r e b u ilt with Tiny OS ope rating  system. Ti n y OS is an  e m bedd ed  system fo wirel e ss n e twork, with  a  set of  co m pone nts that  are in clu d e d  as-ne ede d  in   appli c ation s  [5].        D T U A ct i v e M es sageC D T U A c t i v eM ess ageC Wa t e r M o n i t o r C Ma i n C T i m e r M i lli C P L C A c t i v eM es s ageC C C 2 420A c t i v eM es s ageC P L C A M S end- > A M S e n d P L C R e c e i v e- > R e c ei v e C C 2 420A M S e nd- >A M S end C C 2 420 R e cei v e - >R ecei ve     Figure 3. Co mpone nts u s ed for FF D a nd RF D.  A so lid box is for a singl eton compon ent, a  dashed b o x for a gen eri c  compon ent, while dou ble-li ne box is only  used in FF D.  An arro w is a n   interface      At a high l e vel, TinyOS p r ovides th re e t h in g s  to ma ke writing  syst ems  and  appl ication s   easi e r: (1 ) A comp one nt model, whi c h d e fines h o w yo u write  small,  reu s abl e pie c e s  of co de a n d   comp ose the m  into larger abst r actio n s;  (2) A  co ncurrent exe c utio n model,  whi c h d e fine s h o comp one nts  interleave th eir comp utations  as  well  as h o w i n terrupt an d no n-inte rru pt cod e   intera ct; (3)  Applicatio n p r og rammi ng i n terfaces  (A PIs), se rvice s , com pone n t  librarie s  an d an   overall comp onent st ructu r e that simplify  writing ne w a pplication s  an d servi c e s Evaluation Warning : The document was created with Spire.PDF for Python.
                               ISSN: 23 02-4 046                     TELKOM NI KA  Vol. 12, No. 6, June 20 14:  4802 – 4 807   4804 As is illustrat ed in Figure. 3, WaterM oni torC  i s  com p osed of five components of  which,  MainC impl e m ents the  b oot sequ en ce of a  no de  and  p r ovide s  the  Boot i n terface  so  that  Wate rMonito rC can b e  n o tified wh en a  n ode h a s fully  booted. In o u r  ap plicatio n,  Wate rMonito rC   need s to  sa m p le pe rio d ical ly, so we  can  use sta r tPeri odic(60 000 comman d , whi c will  sign al  fired event  once a min u te. It's worth mentioni n g  that there  are thre e ActiveMessa geC  components whi c h l o ok similar  but have entirely different  re sponsibilities.  For instance,  PLCActiveMe s sage C is u s ed for le arning the  sta t es of auxiliary relay s  in  PLC and the   con c e n tration  of NO3-, P O 43-  and P H  value. Com m unication b e twee n FFD  and RFDs is the  duty of  CC24 20ActiveMe s sag e C.  DT UActiveMessa geC, used   on ly  in FF D,  se nds data  p a ckets  to remote ma nagem ent pla tform by GRP S  chann el.    3.1. RFD  RFD  ha s two  main fun c tio n s: 1. Re ad t he concentration of NO 3-,  PO43-  and P H  value  (as Sen s o r   Data) in  PLC;  2. Send Se n s or Data to t he FF D. Th e  Sensor  Data  is  rea d  thro ugh   HOSTLI NK in stru ction.  HO STLINK  is O m ron' propri e tary p r oto c ol , by whi c h th e  external  devi c can  comm uni cate with  Om ron PL C thro ugh serial  po rt. By HOSTLINK proto c o l , RFD can visit  DM (Data Me mory) an d ot her regi sters in PLC [6].  In  our sy stem, the Sensor  Data, starting f r om  0012  unit, is  stored in the  DM area of P L C, ea ch bei ng represent ed by an  8-byte ASCII. In order  to read th e Senso r  Data, TinyOS sen d the  HOS T LINK in stru ction " @ 00 RD00 120 0065 3* ",   and th en PL sen d s ba ck a  HOSTLINK instructio as  re spo n se  whi c co ntain s  Se nso r   Dat a . It  is  to  be  noted that PLC  s t ores  the Sens or  Data   as a double-byte  ASCII, of the  8 bytes only t he  late half are valid.  Figure 4(a )  is a subset of  the RF D state  diagram, the  advance d  op eration s  bei n g  elided  for simpli city. WaterMo n itorC initiat e pe riodi c samplin g  in its booted event  b y   Timer. startPe r iodi c co mma nd. Timer.fire d req uest s  a  new PL C sa mpling by se nding  HOSTL I NK  instru ction s  usin the  PLCAMSen d   inte rfa c e,  and  a PL CAM p a cke t  stored i n  a  plc_ se nsor_ d a ta_t pa cket buffer.  The  p l c_ sen s o r _d a t a_t hold s  th e cu rrent Se nso r  Data after   HOSTLI NK resp on se arri ves. Then we resto r e the  Senso r  Dat a  into node _ s en so r_p a cket_t  (Figu r e. 5 ) , a nd send it to  FFD by  CC2 420AMSen d i n terface. Thu s , the pa cket  is sm aller  a n d   easi e r to tran smit; besid es,  it identifies which mo nitori ng nod e it wa s born of.      B oot.bo o ted PL CA M S en d. s e n d C C 242 0A MS end.sen d T i m e r . fire d P L C R ec ei ve.receive CC 24 20 A M S S en d.send Done   (a)   Time r. fired Bo ot.boote d PL CAM S en d. sen d DT UAM S e nd.send PLCRecei v e. recei v e DTU A M S e n d . send Done CC2420 Receiv e . receive   (b)     Figure 4. (a)  RFD o p e r atin g scena ri o; (b ) FFD o perating scen ario.       3.2. FFD  FFD  ha s fun c tion s a s  foll ows: 1.  Re ce ive  nod e_ sen s or_pa cket_t  variable  sent  from  a   RFD; 2. Re a d  the Senso r  Data in PLC; 3.  Send every node _se n so r_p a cket_ t  variable to th e   remote ma na gement platfo rm. The rem o te transmi ssi on function i s  implemented  by GRPS DTU.  GPRS  DTU is  a devic e  for c o nvers i on between  s e rial data and IP  pack e t. It has the PPP  dial-up  and T C P/IP proto c ol  en ca psul ated in  G P RS DT U, e nablin g tra n spare n t tran smissi on  between   seri al devices and rem o te compute r s [7].  Different from  RF D, PLCReceive.receive doe s  not retransmit HOS T LINK respons e , but  sen d s th e re store d  n ode_ sen s o r _p acket_t variable  to the re mo te mana gem ent platform  by  DTUAMS end  interface. CC242 0Re c e i ve forw a r d s  the node _ s en so r_p a cket_t variable  by  DTUAMS end  interfa c e  after  re ceiving  i t  from  RF D. Wh en thi s  i s  d one, th TinyOS sy stem   Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOM NIKA   ISSN:  2302-4 046     Depl oym ent of TinyOS for On line Water Sensing  (Xin  Wang 4805 returns to  th e ori g inal  sta t e waiting fo r next Ti mer.fi red  event. T he FF D o perating sce n a r io is  s h ow n  in  F i gu r e  4( b )     00 RD 00 nu l l ni t r at e nul l nu l l ph os p h a t e ph fc s * @ T O S_ NODE_ I D ni t r at e ph osp hat e ph p l c_sen s o r _d at a_ t n o de_s en so r _ p a c k e t _ t     Figure 5. Rel a tionship bet wee n  plc_se n s or_data _ t an d node _sen sor_p a cket_t       4. Remote M a nageme nt  Platform   The archite c t u re of re mote  manage ment  platform is shown in Figu re 6.      Vi rtual   Se r i al Po r t   Se r v ic e IP Datagr am Lab VIE W Data  P r oc ess Se r i al Dat a MySQ L Data base S ens or Data S ens or D a ta and C o m m and L abV IE W M onitor  C e n t er H i sto r y D a ta     Figure 6. Architecture of Re mote Management Platform      4.1. Virtual Serial Port Ser v ice  The remote  manag eme n t comp uter  re ceives t he IP p a cket which  contain s  Sen s or Data.  For ea sy op e r ation, the IP packet  is  co nverted into  seri al data b y  Virtual Serial Port Servic e.   Then th e serial data i s  u s ed to  comm unicate with   uppe r p r o c ed ure s  throug h  the virtuali z ed  seri al po rt.    4.2. Data Pro cess Proc ed ure     The Data Proce s s Proce dure, i m plem ented  by  Lab VIEW softwa r e, is respon sible  for  bindin g  the virtual se rial po rt  and re ceive s  Sensor Data from GPRS  DTU. As floa t in CP1H PLC  is stored a s  two 16-bit  words in a scendin g   ord e r, LabVIEW must convert  it before be ing   transfo rme d  i n to float. The  obtaine d sen s or data i s   stored  into the  databa se  and  displ a yed in t h e   monitori ng ce nter. This  proce s s is impl emented  by  a pro ducer-consume r  pattern. In this way,  the Sen s or  Data  can  be  stored i n to  MySQL data base imme di ately in prod uce r   cycle,  a nd is  displ a yed in a  con s tant sp e ed in co nsum er cy cle.     4.3. Data Pro cess Proc ed ure   MySQL, an o pen  sou r ced  relation al dat aba se  with hi gh pe rform a n c e, can run i n  most  operating sy stems. LabVI E W con n e c ts MySQL vi Datab a se Co nne ctivity To olkit and O D BC  interface. Th e Monito rin g  Ce nter i s   n o t only resp onsi b le fo r d i splayin g  the  Sensor Data of  monitori ng  no des in  re al ti me b u t al so  achi eves  the  function of h i stori c al i nqui ry an d a bno rmal  alarm.       5. Other op e r ating s y stems for WS N   Beside s the  TinyOS, there a r so me  o t her  embe dd ed  o p e r ating  system s de si gned   for  the sen s o r  ne tworks.   Conti k i i s  a n  op en  so urce  ope rating  sy s t em fo r n e t wo rk e d ,  me mor y -c on s t r a in ed  system s with  a particular f o cu s on lo w-power wi re l e ss Inte rnet of  Thing s  devices. Example s  o f   whe r e Contiki  is used in clu de stre et lighting system s, sou nd monito ring for  sma r t cities, radi atio n   monitori ng sy stem s, and al arm sy stems.  Contiki  was  cre a ted by Adam Du nkels  in 2002 an d h a Evaluation Warning : The document was created with Spire.PDF for Python.
                               ISSN: 23 02-4 046                     TELKOM NI KA  Vol. 12, No. 6, June 20 14:  4802 – 4 807   4806 been fu rthe develop ed b y  a wo rld - wi de team  of  develop ers from Atmel,  Ci sco, Enea, E T Zuri ch, Redwire, RWT H   Aachen Uni v ersity,  Ox ford  University, SAP, Sensi node, SICS,  ST   Microele c tro n i cs, Zole rtia, and many ot hers. The  na me Conti k i comes from T hor Heyerda h l's  famous  Kon-Tik i  raft.  ERIKA Enterprise i s   an  open- source and  royalty-free O SEK/VDX  Kernel. Thi s  RT OS  inclu d e s  also  RT-Druid, which i s  a  dev elopme n t en vironme n t distributed a s  a  set of Eclip se   plugin s . ERIKA Enterprise implement s variou co nforma nce cl asse s,  includ ing the stan dard   OSEK/VDXconformanc class e s  BCC1,  BCC2, E CC1, ECC2, CCCA, CCCB.  Moreover, E R IKA   provide s  oth e r  custom  con f orman c cla s ses  nam ed FP  (Fixed pri o rity),  EDF (Earlie st  dea dl ine   first sche dulin g), and F R SH (an implem e n tati on of resource reserva t ion proto c ol s).  Nan o -RK is  a  real -time o p e rating  sy ste m  from  Carn egie Mell on  University de sign ed to   run on mi cro - co ntroll ers for use in se nso r  netwo rks. Nano -RK sup port s  a fixed-p r iority fully  pree mptive sche dule r  with  fine-grai ned  timing prim iti v es to supp o r t real-tim e task  sets. "Na n o implies that t he RT OS is small, con s um ing 2KB  of RAM and usi n g 18KB of flash, whil e "RK "  is   sho r t  f o r  re s our ce  ke rnel.  A  re sou r ce  ke rnel  provides re se rvati ons  on  ho w often  syste m   resou r ces ca n be  con s um ed. Fo r exam ple, a ta sk mi ght only  be  allowe d to  exe c ute  10m s ev ery  150m s (CP U  reservatio n), or a node mi ght only be allowe d to transmit 10 network p a cket s pe minute (network re se rvatio n). The s re servation s  form a virtual  en ergy b udget t o  en su re a  n ode  meets it s d e si gned  battery l i fetime as wel l  as  protectin g  a fail ed  nod e from  ge nerating ex ce ssi ve   netwo rk traffi c. Nano -RK i s  o pen  so urce, is  wr itten  in C  and  ru ns on the  Atme l-ba sed  FireF l sen s o r  netwo rkin g platform , the MicaZ m o tes a s  well a s  the MSP43 0  pro c e s sor.   LiteOS is a  real -time ope rating  syste m  from  Univ ersity of Illinois for u s e i n  sen s o r   netwo rks.  LiteOS i s  a  UNIX-lik e o perating  system  that fits  on  memo ry-con strain ed  se n s o r   node s. This  operating sy stem allows u s ers to ope ra te wirele ss sensor net wo rks li ke ope rat i ng   Unix, whi c h i s  ea sie r  for  peopl e with  adeq uate  Un i x  backgroun d. LiteOS provides  a fam iliar  prog ram m ing  environm ent  base d  on UNIX, thread s, and C. It follows a hybri d  prog ram m i ng  model that al lows both ev ent-d riven an d threa d -d riv en programm i ng. Li teOS i s  ope n source,  written in C a nd run s  on th e Atmel base d  MicaZ a nd IRIS sen s o r  n e tworkin g  pla tform.  OpenT ag i s  a  DASH7 p r ot ocol  stack a n d  minimal Re al-Time  Ope r ating System, written   in the  C prog rammin g  la ng uage. It i s   de sign ed to   run  on  micro c ont rolle rs o r  radi o System on  a  Chip  (SoC). OpenT ag  wa s engi nee red  to be a very  comp act software pa ckag e. However,  with   prop er  co nfig uration, it  ca n also run in  any  POSIX environm ent. OpenT ag  ca n also p r ovid e all   function ality required for a n y type of D ASH7  Mode  2 device, rat her  than ju st the eponymous  “tag”-type en dpoint devi c e       6. Conclusio n   As a re al time  operating sy stem optimi z ed for  WSN,  TinyOS is first employed in  the field   of water  qual ity monitoring  in our  syste m  to  achi eve  the goal s of  water  quality  data coll ecti on   and it s remot e  tran smi s sio n . The  sy ste m  sugge sts  t he comp one n t -based programming   meth od   and the eve n t-drive n  ope rating me ch a n ism, which  is inde pen de nt of network infra s tru c tu re,   flexible and a ffordable to b e  implemente d  and ha s a promi s in g pro s pe ct. Ho wever, the syste m   is far from  b e ing p e rfe c t. More research i s  n eed ed  co ncerni ng  hidde n termi nal, out-of-o r der  packet an d other issu es in the future. Besi de s, the bala n ce  betwe en sy stem lifetime and   transmissio n rate is un de rd  con s ide r atio n.      Ackn o w l e dg ements   This  wo rk was  sup p o r ted  by the National  Na tu ral Scien c F o u ndation of  China (No.    61273070), the Programm e of Intr oduci ng Talents  of Discipli ne  to  Universities (B12018), PAPD  of Jiang su  Hi gher Ed ucation Institution s  and th e Fu ndame n tal Rese arch Fu n d s for the  Ce ntral  Universitie s  (JUS RP11 132 ).      Referen ces   [1] Z hao  X.  Res e arch on env ironment  system for  water m o nitor . Internati o n a l C onfer enc on Inte lli ge nt  S y stem Des i g n  and Eng i n eeri ng App lic ati on.  Chan gsh a . 20 10; 2: 197- 199.   Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOM NIKA   ISSN:  2302-4 046     Depl oym ent of TinyOS for On line Water Sensing  (Xin  Wang 4807 [2]  Alex  A, Jenny DR.  Des i gn in g an  auto m ate d  w a ter qu ality  mo nitor i ng  sy stem for W e st  and  Rh od e   Rivers . Proce e d in gs of the 2009 IEEE S y s t ems and In for m ation En gin e e rin g  Desi gn  S y mp osi u m.  Charl o ttesvil l e.  2009; 1 31-1 3 6 .   [3]  Joa-N g  Mar i o,  Lu  I-T a i. A p eer-to-p eer z o ne-b a sed  t w o- l e vel  li nk state  routi n g  for m obil e   ad  h o c   net w o rks.  IEEE Journal on S e lected  Areas in Comm unications . 199 9; 17( 9): 1415- 14 25.   [4]  Azzedi ne B. A l gorithms  an protoco l s for  w i reless  sens or  net w o rks. H o b o ken: J ohn  W ile y & S ons .   200 9.  [5]  Ga y  D, L e vis  P, Culler  D. So ftw a re  de si gn p a tte rns for T i ny OS.  ACM T r ansacti ons o n  Emb e d d e d   Co mp uting Sys t ems . 20 05; 40 (7): 40-49.   [6]  Omron Corp or ation. Comm un icatio ns  comm ands refer enc e  manua l. K y ot o .  2010.   [7]  Metz C. A poin t ed look at  the  poi nt-to-poi nt p r otocol.  IEEE Internet Computing . 199 9; 3(4) : 85-88.     Evaluation Warning : The document was created with Spire.PDF for Python.