Saturday, February 1, 2014

LocalTime on TinyOS

3:47 PM By Unknown , , , 1 comment

When I started googling about fetching local time on motes, I hardly found any relevant help online and spent quite some time to finally make it work. So I thought of sharing what I learnt.
Say, following the naming convention, I have 2 files called TempC.nc and TempAppC.nc.







In TempAppC.nc add the following lines ..

       

implementation
{
       //General Components
 ....
 components LocalTimeMilliC;
 ....

 ...
 App.LocalTime -> LocalTimeMilliC; 
 ...
}
       
 

and in TempC.nc add the following lines ...
       
module TempC
{
 uses
 {
  ...
  interface LocalTime;
                ...
 } 
}

implementation{
        ...
 uint32_t timestamp;


       ...
       event void Boot.booted()
 {
                ...
  call Timer.startPeriodic(5000);
                ...
 }

       event void Timer.fired()
 {
                ...
                timestamp = call LocalTime.get();
                printf("Local Time = %d\n",timestamp);
                ...
         }

          ...
}

 

1 comments: