<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://anrg.usc.edu/contiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nitin</id>
		<title>Contiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://anrg.usc.edu/contiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nitin"/>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php/Special:Contributions/Nitin"/>
		<updated>2026-05-11T14:53:04Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1650</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1650"/>
				<updated>2014-11-30T03:13:14Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the firmware later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of motes. You can select any number of motes, but for simplicity we are considering only 2 motes.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Sensor_acquisition&amp;diff=1647</id>
		<title>Sensor acquisition</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Sensor_acquisition&amp;diff=1647"/>
				<updated>2014-11-23T06:44:20Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Generic Template for Creating Application on Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This article helps you learn how to create the Sensor Acquisition Program, which can be used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Sensor_acquisition&amp;diff=1646</id>
		<title>Sensor acquisition</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Sensor_acquisition&amp;diff=1646"/>
				<updated>2014-11-23T06:43:48Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application on Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This article helps you learn how to create the Sensor Acquisition Program, which can be used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1645</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1645"/>
				<updated>2014-11-23T05:47:26Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 &amp;#039;&amp;#039;&amp;#039;How to start an application in Contiki&amp;#039;&amp;#039;&amp;#039; walk you through the complete process of writing you own application in Contiki. Section#3 &amp;#039;&amp;#039;&amp;#039;Generic structure of Application in Contiki&amp;#039;&amp;#039;&amp;#039; gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;,i);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder (contiki/exmples/my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1644</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1644"/>
				<updated>2014-11-23T05:43:45Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 &amp;#039;&amp;#039;&amp;#039;How to start an application in Contiki&amp;#039;&amp;#039;&amp;#039; walk you through the complete process of writing you own application in Contiki. Section#3 &amp;#039;&amp;#039;&amp;#039;Generic structure of Application in Contiki&amp;#039;&amp;#039;&amp;#039; gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder (contiki/exmples/my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1643</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1643"/>
				<updated>2014-11-23T05:42:59Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 &amp;#039;&amp;#039;&amp;#039;How to start an application in Contiki&amp;#039;&amp;#039;&amp;#039; walk you through the complete process of writing you own application in Contiki. Section#3 &amp;#039;&amp;#039;&amp;#039;Generic structure of Application in Contiki&amp;#039;&amp;#039;&amp;#039; gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1642</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1642"/>
				<updated>2014-11-23T05:41:11Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 &amp;#039;&amp;#039;&amp;#039;How to start an application in Contiki&amp;#039;&amp;#039;&amp;#039; walk you through the complete process of writing you own application in Contiki. Section#3 &amp;#039;&amp;#039;&amp;#039;Code&amp;#039;&amp;#039;&amp;#039; contains the C code for a very simple application that prints &amp;quot;EE-652 is an awesome course at USC&amp;quot; on the terminal. Section#3 &amp;#039;&amp;#039;&amp;#039;Generic structure of Application in Contiki&amp;#039;&amp;#039;&amp;#039; gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1641</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1641"/>
				<updated>2014-11-23T05:40:32Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 &amp;#039;&amp;#039;&amp;#039;How to start an application in Contiki&amp;#039;&amp;#039;&amp;#039; walk you through the complete process of writing you own application in Contiki. Section#3 &amp;#039;&amp;#039;&amp;#039;Code&amp;#039;&amp;#039;&amp;#039; contains the C code for a very simple application that prints &amp;quot;EE-652 is an awesome course at USC&amp;quot;. Section#3 &amp;#039;&amp;#039;&amp;#039;Generic structure of Application in Contiki&amp;#039;&amp;#039;&amp;#039; gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1640</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1640"/>
				<updated>2014-11-23T05:39:42Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 How to start an application in Contiki walk you through the complete process of writing you own application in Contiki. Section#3 Code contains the C code for a very simple application that prints &amp;quot;EE-652 is an awesome course at USC&amp;quot;. Section#3 Generic structure of Application in Contiki gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1639</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1639"/>
				<updated>2014-11-23T05:38:32Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki. Section#2 [[How to start an application in Contiki]] walk you through the complete process of writing you own application in Contiki. Section#3 [[Code]] contains the C code for a very simple application that prints &amp;quot;EE-652 is an awesome course at USC&amp;quot;. Section#3 [[Generic structure of Application in Contiki]] gives a generic skeleton of any application in contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1638</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1638"/>
				<updated>2014-11-23T05:34:25Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1637</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1637"/>
				<updated>2014-11-23T05:33:20Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 6 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit.&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1636</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1636"/>
				<updated>2014-11-23T05:33:01Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 6 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then Press CTRL-C to quit&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1635</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1635"/>
				<updated>2014-11-23T05:32:01Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1634</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1634"/>
				<updated>2014-11-23T05:30:22Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 6 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;EE-652 is an awesome course at USC&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1633</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1633"/>
				<updated>2014-11-23T05:28:48Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Upload the firmware on Tmote Sky&amp;#039;&amp;#039;&amp;#039; - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app  and then write the following commands to upload your program on the Tmote Sky. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make my_first_app.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1632</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1632"/>
				<updated>2014-11-23T05:24:20Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Write my_first_app.c&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1631</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1631"/>
				<updated>2014-11-23T05:23:49Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write my_first_app.c &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Makefile&amp;#039;&amp;#039;&amp;#039; - Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1630</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1630"/>
				<updated>2014-11-23T05:23:22Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 5 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write my_first_app.c &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compilation&amp;#039;&amp;#039;&amp;#039; - Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1629</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1629"/>
				<updated>2014-11-23T05:22:23Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write my_first_app.c &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Use terminal to go to &amp;quot;contiki/examples/my_first_app&amp;quot; directory. Once you are in this directory type &amp;quot;make&amp;quot;. This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.&lt;br /&gt;
 &lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1628</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1628"/>
				<updated>2014-11-23T05:15:48Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write my_first_app.c &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1627</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1627"/>
				<updated>2014-11-23T05:14:59Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write C code. &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
  AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
  { &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1626</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1626"/>
				<updated>2014-11-23T05:12:37Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write C code. Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Create makefile in the same folder(my_first_app)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1625</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1625"/>
				<updated>2014-11-23T05:11:45Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Generic C code for Application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write C code. Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic structure of Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Create the makefile.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 CONTIKI_PROJECT = my_first_app&lt;br /&gt;
 all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
 #UIP_CONF_IPV6=1&lt;br /&gt;
&lt;br /&gt;
 CONTIKI = ../..&lt;br /&gt;
 include $(CONTIKI)/Makefile.include&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1624</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1624"/>
				<updated>2014-11-23T05:08:28Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Write C code. Every process in Contiki should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1623</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1623"/>
				<updated>2014-11-23T05:06:21Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1622</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1622"/>
				<updated>2014-11-23T05:05:52Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      /* Declare variables required */&lt;br /&gt;
      static int i=652;         &lt;br /&gt;
&lt;br /&gt;
      /* Begin Process */&lt;br /&gt;
      PROCESS_BEGIN();          &lt;br /&gt;
&lt;br /&gt;
      /* Set of C statement(s) */&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             &lt;br /&gt;
      &lt;br /&gt;
      /* Process End */&lt;br /&gt;
      PROCESS_END();            &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1621</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1621"/>
				<updated>2014-11-23T05:04:52Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static int i=652;         /* Declare variables required */&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();          /* Begin Process */&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);             /* Set of C statement(s) */&lt;br /&gt;
      &lt;br /&gt;
      PROCESS_END();            /* Process End */&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1620</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1620"/>
				<updated>2014-11-23T05:03:05Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(my_first_app_process,&amp;quot;My_First_App&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;my_first_app_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(my_first_app_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static int i=652;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;EE-%d is an awesome course at USC\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1619</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1619"/>
				<updated>2014-11-23T04:59:07Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Generic C code for Application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Header Files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1618</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1618"/>
				<updated>2014-11-23T04:58:11Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Generic Template for Creating Application on Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic C code for Application in Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1617</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1617"/>
				<updated>2014-11-23T04:55:57Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Content of my_first_app.c&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=File:Byaic_2.png&amp;diff=1616</id>
		<title>File:Byaic 2.png</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=File:Byaic_2.png&amp;diff=1616"/>
				<updated>2014-11-23T04:53:20Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: Nitin uploaded a new version of &amp;amp;quot;File:Byaic 2.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=File:Byaic_2.png&amp;diff=1615</id>
		<title>File:Byaic 2.png</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=File:Byaic_2.png&amp;diff=1615"/>
				<updated>2014-11-23T04:51:20Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1614</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1614"/>
				<updated>2014-11-23T04:51:00Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application in Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now create a new C file named my_first_app.c&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=File:Byaic_1.png&amp;diff=1613</id>
		<title>File:Byaic 1.png</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=File:Byaic_1.png&amp;diff=1613"/>
				<updated>2014-11-23T04:46:36Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: Nitin uploaded a new version of &amp;amp;quot;File:Byaic 1.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=File:Byaic_1.png&amp;diff=1612</id>
		<title>File:Byaic 1.png</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=File:Byaic_1.png&amp;diff=1612"/>
				<updated>2014-11-23T04:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1611</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1611"/>
				<updated>2014-11-23T04:43:49Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* How to start an application on Contiki */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application in Contiki ==&lt;br /&gt;
&lt;br /&gt;
Go to the directory contiki/examples and make  new sub directory named my_first_app&lt;br /&gt;
&lt;br /&gt;
[[File:byaic_1.png|center|800px]]&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1610</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1610"/>
				<updated>2014-11-23T04:33:38Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial help you understand how to build you own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application on Contiki ==&lt;br /&gt;
&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1609</id>
		<title>Build your own application in Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_in_Contiki&amp;diff=1609"/>
				<updated>2014-11-23T04:31:37Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: Created page with &amp;quot; Back to Contiki Tutorials  __TOC__  == Introduction ==  This article helps you learn how to create the Sensor Acquisition Program, which can be used to...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This article helps you learn how to create the Sensor Acquisition Program, which can be used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== How to start an application on Contiki ==&lt;br /&gt;
&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1608</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1608"/>
				<updated>2014-11-23T04:31:09Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
== List of Tutorials ==&lt;br /&gt;
&lt;br /&gt;
Completed&lt;br /&gt;
# [[Installation]]&lt;br /&gt;
# [[Hello World]]&lt;br /&gt;
# [[Broadcast Example]]&lt;br /&gt;
# [[Collect View]]&lt;br /&gt;
# [[Contiki build system]]&lt;br /&gt;
# [[Interfacing with Python]]&lt;br /&gt;
# [[Sensor acquisition]] (light, temperature, humidity)&lt;br /&gt;
&lt;br /&gt;
Need review&lt;br /&gt;
# [[Timers]] Tim, Leo&lt;br /&gt;
# [[CFS-Coffee]] Kevin&lt;br /&gt;
&lt;br /&gt;
Starting&lt;br /&gt;
# [[Tutornet]] Pedro, Kwame&lt;br /&gt;
# [[Cooja Simulator]] (Getting started, debugging) Pedro&lt;br /&gt;
# [[Network Stack]] Yash&lt;br /&gt;
# [[CSMA]] Tim, Leo&lt;br /&gt;
# [[RSS measurement]] Nitin&lt;br /&gt;
# [[RPL objective function &amp;amp; simulation using DGRM model in cooja  ]] Ashwini Telang&lt;br /&gt;
# [[RPL UDP]] Jiahao Liang&lt;br /&gt;
# [[MAC protocols in ContikiOS]] Pedro&lt;br /&gt;
# [[RPL Border Router]] Chhavi&lt;br /&gt;
# [[REST example running on Cooja and Sky motes]] Mrunal Muni &lt;br /&gt;
# [[Trickle library]] Subhashini Sundaresan&lt;br /&gt;
# [[Packetbuffer Basics]] Pradipta&lt;br /&gt;
# [[Antelope(Database Management System) - Contiki]] Gopi Krishna&lt;br /&gt;
# [[Mobility of Nodes in Cooja]] Pratyush Deshpande&lt;br /&gt;
# [[Contiki Shell]] Abhilash Nagaraj Hegde&lt;br /&gt;
# [[Contiki Coffee File System]] Zhikun Liu&lt;br /&gt;
# [[Contiki Programming Guide]] Haimo Bai&lt;br /&gt;
# [[Analyse of a real 6LoWPAN network using a Contiki-based sniffer module]] Yash Goyal&lt;br /&gt;
# [[Build your own application in Contiki]] Nitin&lt;br /&gt;
&amp;lt;!--[[Processes]] Yash --&amp;gt;&lt;br /&gt;
&amp;lt;!--[[RPL objective function modification and simulation in cooja]]--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--# [[Collect-view Code Details]] Pradipta --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color: red&amp;quot;&amp;gt;Be sure to include references in your tutorials, especially if you quote material from other sites!&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_on_Contiki&amp;diff=1607</id>
		<title>Build your own application on Contiki</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Build_your_own_application_on_Contiki&amp;diff=1607"/>
				<updated>2014-11-23T04:30:41Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: Created page with &amp;quot; Back to Contiki Tutorials  __TOC__  == Introduction ==  This tutorial helps you to understand how to build your own application in Contiki.  == How to ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to build your own application in Contiki.&lt;br /&gt;
&lt;br /&gt;
== How to start an application on Contiki ==&lt;br /&gt;
&lt;br /&gt;
Every process should start with the PROCESS macro. It takes two arguments&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*strname: The string representation of the process name.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS(name,strname) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes another macro AUTOSTART_PROCESS(struct process &amp;amp;). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
*&amp;amp;name: Reference to the process name.&lt;br /&gt;
                     &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; AUTOSTART_PROCESS(struct process &amp;amp;) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
*name: The variable name of the process structure.&lt;br /&gt;
*process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.&lt;br /&gt;
               &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_THREAD(name, process_event_t, process_data_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.&lt;br /&gt;
                             &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_BEGIN() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then we write the set of C statements as per the requirement of the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the end we use another macro PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.&lt;br /&gt;
                            &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; PROCESS_END() &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic Template for Creating Application on Contiki  ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(name,strname);&lt;br /&gt;
AUTOSTART_PROCESSES(struct process &amp;amp;);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(name, process_event_t, process_data_t)&lt;br /&gt;
{ &lt;br /&gt;
&lt;br /&gt;
----Initialization of required variables----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
---Set of C statements---&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Sensor Acquisition Program on the Tmote Sky! ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=sky savetarget&amp;lt;/code&amp;gt;    (This save the target for any future compilations)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make sensor-acq.upload&amp;lt;/code&amp;gt;    (This will upload the code on the Tmote Sky)&lt;br /&gt;
:: &amp;lt;code&amp;gt;make login&amp;lt;/code&amp;gt;    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)&lt;br /&gt;
See the following link for troubleshooting - http://anrg.usc.edu/contiki/index.php/Troubleshooting&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the reset button on the Tmote Sky. The following message will appear on the terminal window &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;Temperature=28.04 C (6764)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Humidity=73.20% (2259)&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Light=38.26 lux (94)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at&lt;br /&gt;
http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(sensor_acq_process,&amp;quot;Sensor Acquisition&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sensor_acq_process);&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(sensor_acq_process,ev,data)&lt;br /&gt;
{ &lt;br /&gt;
      static struct etimer et;&lt;br /&gt;
      static int val;&lt;br /&gt;
      static struct sensors_sensor *sensor;&lt;br /&gt;
      static float s = 0;&lt;br /&gt;
      static int dec;&lt;br /&gt;
      static float frac;&lt;br /&gt;
&lt;br /&gt;
      PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
      printf(&amp;quot;Starting Sensor Example.\n&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      while(1)&lt;br /&gt;
      {&lt;br /&gt;
	   etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	   SENSORS_ACTIVATE(light_sensor);&lt;br /&gt;
      	   SENSORS_ACTIVATE(sht11_sensor);&lt;br /&gt;
        &lt;br /&gt;
	   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           val = sht11_sensor.value(SHT11_SENSOR_TEMP);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= ((0.01*val) - 39.60);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;\nTemperature=%d.%02u C (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
	   val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY);&lt;br /&gt;
	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  &lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Humidity=%d.%02u % (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);&lt;br /&gt;
      	   if(val != -1) &lt;br /&gt;
      	   {&lt;br /&gt;
      		s = (float)(val * 0.4071);&lt;br /&gt;
      	  	dec = s;&lt;br /&gt;
      	  	frac = s - dec;&lt;br /&gt;
      	  	printf(&amp;quot;Light=%d.%02u lux (%d)\n&amp;quot;, dec, (unsigned int)(frac * 100),val);               &lt;br /&gt;
           } &lt;br /&gt;
	&lt;br /&gt;
	   etimer_reset(&amp;amp;et);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(light_sensor);&lt;br /&gt;
    	   SENSORS_DEACTIVATE(sht11_sensor);&lt;br /&gt;
&lt;br /&gt;
      } //end of while&lt;br /&gt;
    &lt;br /&gt;
      PROCESS_END();&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 2 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_ACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to activate light_sensor for measuring the light intensity and sht11_sensor for the measurement of temperature and humidity.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;val = sht11_sensor.value(SHT11_SENSOR_TEMP);&amp;lt;/code&amp;gt;&lt;br /&gt;
Here we are capturing the actual sensor value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;s = ((0.01*val) - 39.60);&amp;lt;/code&amp;gt;&lt;br /&gt;
We need to calibrate the sensor values by doing some calculations. You can find the calculations here: http://tinyos.stanford.edu/tinyos-wiki/index.php/Boomerang_ADC_Example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(light_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;SENSORS_DEACTIVATE(sht11_sensor);&amp;lt;/code&amp;gt;&lt;br /&gt;
After we are done with the calculations, we need to deactivate the sensors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1606</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1606"/>
				<updated>2014-11-23T04:27:59Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
== List of Tutorials ==&lt;br /&gt;
&lt;br /&gt;
Completed&lt;br /&gt;
# [[Installation]]&lt;br /&gt;
# [[Hello World]]&lt;br /&gt;
# [[Broadcast Example]]&lt;br /&gt;
# [[Collect View]]&lt;br /&gt;
# [[Contiki build system]]&lt;br /&gt;
# [[Interfacing with Python]]&lt;br /&gt;
# [[Sensor acquisition]] (light, temperature, humidity)&lt;br /&gt;
&lt;br /&gt;
Need review&lt;br /&gt;
# [[Timers]] Tim, Leo&lt;br /&gt;
# [[CFS-Coffee]] Kevin&lt;br /&gt;
&lt;br /&gt;
Starting&lt;br /&gt;
# [[Tutornet]] Pedro, Kwame&lt;br /&gt;
# [[Cooja Simulator]] (Getting started, debugging) Pedro&lt;br /&gt;
# [[Network Stack]] Yash&lt;br /&gt;
# [[CSMA]] Tim, Leo&lt;br /&gt;
# [[RSS measurement]] Nitin&lt;br /&gt;
# [[RPL objective function &amp;amp; simulation using DGRM model in cooja  ]] Ashwini Telang&lt;br /&gt;
# [[RPL UDP]] Jiahao Liang&lt;br /&gt;
# [[MAC protocols in ContikiOS]] Pedro&lt;br /&gt;
# [[RPL Border Router]] Chhavi&lt;br /&gt;
# [[REST example running on Cooja and Sky motes]] Mrunal Muni &lt;br /&gt;
# [[Trickle library]] Subhashini Sundaresan&lt;br /&gt;
# [[Packetbuffer Basics]] Pradipta&lt;br /&gt;
# [[Antelope(Database Management System) - Contiki]] Gopi Krishna&lt;br /&gt;
# [[Mobility of Nodes in Cooja]] Pratyush Deshpande&lt;br /&gt;
# [[Contiki Shell]] Abhilash Nagaraj Hegde&lt;br /&gt;
# [[Contiki Coffee File System]] Zhikun Liu&lt;br /&gt;
# [[Contiki Programming Guide]] Haimo Bai&lt;br /&gt;
# [[Analyse of a real 6LoWPAN network using a Contiki-based sniffer module]] Yash Goyal&lt;br /&gt;
# [[Build your own application on Contiki]] Nitin&lt;br /&gt;
&amp;lt;!--[[Processes]] Yash --&amp;gt;&lt;br /&gt;
&amp;lt;!--[[RPL objective function modification and simulation in cooja]]--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--# [[Collect-view Code Details]] Pradipta --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color: red&amp;quot;&amp;gt;Be sure to include references in your tutorials, especially if you quote material from other sites!&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1605</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1605"/>
				<updated>2014-11-23T02:58:52Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Understanding the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the firmware later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of motes. You can select any number of motes, but for simplicity we are considering only 2 motes.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1604</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1604"/>
				<updated>2014-11-23T02:57:58Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 5 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the firmware later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of motes. You can select any number of motes, but for simplicity we are considering only 2 motes.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;br /&gt;
http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1603</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1603"/>
				<updated>2014-11-23T02:56:34Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the firmware later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of new motes=2.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;br /&gt;
http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1602</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1602"/>
				<updated>2014-11-23T02:54:45Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Understanding the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the code later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of new motes=2.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;br /&gt;
http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1601</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1601"/>
				<updated>2014-11-23T02:53:04Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Understanding the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the code later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of new motes=2.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, follow [http://web.stanford.edu/class/cs244e/papers/cc2420.pdf]&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;br /&gt;
http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1600</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1600"/>
				<updated>2014-11-23T02:52:15Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Understanding the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the code later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of new motes=2.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, follow [[Media:http://web.stanford.edu/class/cs244e/papers/cc2420.pdf]]&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;br /&gt;
http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1599</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1599"/>
				<updated>2014-11-23T02:48:14Z</updated>
		
		<summary type="html">&lt;p&gt;Nitin: /* Step 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial helps you to understand how to measure Radio Signal Strength (RSS) received by a Tmote Sky. In this tutorial we have one sender and one receiver. Receiver receives the packet and display the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
You can find the step by step simulation in the next section &amp;quot;RSS Measurement Program on Cooja&amp;quot; and you can find the C code in the subsequent section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement Program on Cooja ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Create New Simulation on Cooja. Let&amp;#039;s say we call our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Create Motes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse the firmware. &lt;br /&gt;
Note: You can find the code later in this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of new motes=2.&lt;br /&gt;
Note: We are uploading same firmware on both the motes. One will act as Sender and another will act as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;br /&gt;
http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;/div&gt;</summary>
		<author><name>Nitin</name></author>	</entry>

	</feed>