<?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=Bhavana</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=Bhavana"/>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php/Special:Contributions/Bhavana"/>
		<updated>2026-10-14T21:36:28Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=235</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=235"/>
				<updated>2014-02-19T21:27:31Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* List of Tutorials */&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;
&lt;br /&gt;
# [[Installation]]&lt;br /&gt;
# [[Broadcast Example]]&lt;br /&gt;
&lt;br /&gt;
Need review&lt;br /&gt;
&lt;br /&gt;
# [[Hello World]]&lt;br /&gt;
&lt;br /&gt;
Starting&lt;br /&gt;
# [[Tutornet]]&lt;br /&gt;
# [[Timers]]&lt;br /&gt;
# [[Cooja Simulator]]&lt;br /&gt;
# [[Contiki build system]]&lt;br /&gt;
# [[Processes]]&lt;br /&gt;
# [[Protocols stack]]&lt;br /&gt;
# [[CFS-Coffee]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=234</id>
		<title>Hello World</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=234"/>
				<updated>2014-02-19T21:25:48Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Step 1 */&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 is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Open the terminal window.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===  &lt;br /&gt;
&lt;br /&gt;
In the terminal window, go to the hello world example folder.	&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;.cd /examples/hello-world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3=== &lt;br /&gt;
&lt;br /&gt;
Compile the code for the native platform (to be used when no mote is connected to the laptop.)&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Once the compilation is over, run the Hello World program. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;./hello-world.native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
This will print the words &amp;quot;Hello, world&amp;quot; on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
== Hello World 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 Hello World 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 hello-world.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;
&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;Contiki 2.7 started. Node id is set to 3.&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Rime started with address 3.0&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;MAC 00:12:ff:11:65:23:52:ed&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Starting &amp;#039;Hello world process&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Hello, world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.&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;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=233</id>
		<title>Hello World</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=233"/>
				<updated>2014-02-19T21:24:50Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Step 2 */&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 is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Open the terminal window.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===  &lt;br /&gt;
&lt;br /&gt;
In the terminal window, go to the hello world example folder.	&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;.cd /examples/hello-world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3=== &lt;br /&gt;
&lt;br /&gt;
Compile the code for the native platform (to be used when no mote is connected to the laptop.)&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Once the compilation is over, run the Hello World program. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;./hello-world.native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
This will print the words &amp;quot;Hello, world&amp;quot; on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
== Hello World 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 Hello World 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 hello-world.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;
&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;Contiki 2.7 started. Node id is set to 3.&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Rime started with address 3.0&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;MAC 00:12:ff:11:65:23:52:ed&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Starting &amp;#039;Hello world process&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Hello, world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.&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;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=232</id>
		<title>Hello World</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=232"/>
				<updated>2014-02-19T21:23:51Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* 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 article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Open the terminal window.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===  &lt;br /&gt;
&lt;br /&gt;
In the terminal window, go to the hello world example folder.	&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;.cd /examples/hello-world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3=== &lt;br /&gt;
&lt;br /&gt;
Compile the code for the native platform (to be used when no mote is connected to the laptop.)&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Once the compilation is over, run the Hello World program. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;./hello-world.native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
This will print the words &amp;quot;Hello, world&amp;quot; on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
== Hello World 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 Hello World 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 hello-world.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;
&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;Contiki 2.7 started. Node id is set to 3.&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Rime started with address 3.0&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;MAC 00:12:ff:11:65:23:52:ed&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Starting &amp;#039;Hello world process&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Hello, world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.&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;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=231</id>
		<title>Hello World</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=231"/>
				<updated>2014-02-19T21:21:55Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Step 1 */&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 is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Open the terminal window.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===  &lt;br /&gt;
&lt;br /&gt;
In the terminal window, go to the hello world example folder.	&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;.cd /examples/hello-world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3=== &lt;br /&gt;
&lt;br /&gt;
Compile the code for the native platform (to be used when no mote is connected to the laptop.)&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Once the compilation is over, run the Hello World program. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;./hello-world.native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
This will print the words &amp;quot;Hello, world&amp;quot; on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Hello World on the Tmote Sky!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
*Step 1 - Using the opened terminal window compile and upload the Hello World program on the Tmote Sky.&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 hello-world.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;
*Step 2 - Press the reset button on the Tmote Sky. The following message will appear on the terminal window - &lt;br /&gt;
:: &amp;lt;code&amp;gt;Contiki 2.7 started. Node id is set to 3.&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Rime started with address 3.0&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;MAC 00:12:ff:11:65:23:52:ed&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Starting &amp;#039;Hello world process&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Hello, world&amp;lt;/code&amp;gt;&lt;br /&gt;
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.&lt;br /&gt;
*Step 3 - Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=230</id>
		<title>Hello World</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Hello_World&amp;diff=230"/>
				<updated>2014-02-19T21:21:07Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* 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 article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
 Open the terminal window.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===  &lt;br /&gt;
&lt;br /&gt;
In the terminal window, go to the hello world example folder.	&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;.cd /examples/hello-world&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Step 3=== &lt;br /&gt;
&lt;br /&gt;
Compile the code for the native platform (to be used when no mote is connected to the laptop.)&lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;make TARGET=native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Once the compilation is over, run the Hello World program. &lt;br /&gt;
&lt;br /&gt;
:: &amp;lt;code&amp;gt;./hello-world.native&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
This will print the words &amp;quot;Hello, world&amp;quot; on the terminal window. The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Hello World on the Tmote Sky!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
*Step 1 - Using the opened terminal window compile and upload the Hello World program on the Tmote Sky.&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 hello-world.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;
*Step 2 - Press the reset button on the Tmote Sky. The following message will appear on the terminal window - &lt;br /&gt;
:: &amp;lt;code&amp;gt;Contiki 2.7 started. Node id is set to 3.&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Rime started with address 3.0&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;MAC 00:12:ff:11:65:23:52:ed&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Starting &amp;#039;Hello world process&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
:: &amp;lt;code&amp;gt;Hello, world&amp;lt;/code&amp;gt;&lt;br /&gt;
: The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.&lt;br /&gt;
*Step 3 - Press Ctrl-C to quit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=229</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=229"/>
				<updated>2014-02-19T21:00:50Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Using Github repository */&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 guide covers installation of ContikiOS 2.7. There are basically three way of installing ContikiOS: downloading Instant Contiki, downloading ContikiOS from the Sourceforge repository or cloning it from the Github repository.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial will take you through the steps for downloading and installing ContikiOS the following ways:&lt;br /&gt;
&lt;br /&gt;
* Download Instant Contiki [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&lt;br /&gt;
* Download ContikiOS from Sourceforge repository [http://sourceforge.net/projects/contiki/files/latest/download]&lt;br /&gt;
* Clone ContikiOS from Github repository [https://github.com/contiki-os/contiki]&lt;br /&gt;
&lt;br /&gt;
=== Using Instant Contiki ===&lt;br /&gt;
&lt;br /&gt;
This is the easiest way of installing and using ContikiOS. You simply need to download Instant Contiki, which is a virtual machine created with all necessary toolchains and software for ContikiOS development.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Link to download Instant Contiki: [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
After downloading Instant Contiki you need also to download either VMWare Player or VirtualBox, if you are using Windows as your host OS. If you use MacOS X you should download VMWare Fusion, instead of VMWare Player.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: To login in to Instant Contiki: &amp;#039;&amp;#039;&amp;#039;username&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;passwork&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Using Sourceforge repository ===&lt;br /&gt;
&lt;br /&gt;
This method requires an existing installation of a Linux-based operating system. The guide assumes you are using Ubuntu 12.04 but should still be useful for similar versions.&lt;br /&gt;
&lt;br /&gt;
Download contiki-2.7.zip from http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; wget http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unzip the file. For the purposes of this guide, it is assumed that the file is unzipped into /home/user/&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;unzip contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rename the folder from contiki-2.7 to contiki.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;mv contiki-2.7 contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install all the required packages for compiling and running ContikiOS. &lt;br /&gt;
&lt;br /&gt;
If you are using a MSP430-based platform (such as Tmote) you only need the following packages: &amp;#039;&amp;#039;binutils-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430-libc&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430mcu&amp;#039;&amp;#039; and &amp;#039;&amp;#039;mspdebug&amp;#039;&amp;#039;. If you intend to code for multiple platforms, you should also install the following tool chains for other micro-controller: &amp;#039;&amp;#039;binutils-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gdb-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;avr-libc&amp;#039;&amp;#039; and &amp;#039;&amp;#039;avrdude&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
You can run the following command to install all packages for multiple platforms:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install build-essential binutils-msp430 gcc-msp430 msp430-libc msp430mcu &lt;br /&gt;
mspdebug binutils-avr gcc-avr gdb-avr avr-libc avrdude openjdk-7-jdk &lt;br /&gt;
openjdk-7-jre ant libncurses5-dev&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are done! You can now try to compile and run any example, such as [[Hello_World | Hello World]].&lt;br /&gt;
&lt;br /&gt;
=== Using Github repository ===&lt;br /&gt;
&lt;br /&gt;
This method also requires an existing installation of a Linux-based operating system. It is very similar to the previous one, but instead of downloading the source code you are going to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; it from the official Github repository. &lt;br /&gt;
&lt;br /&gt;
This method eases the update of your ContikiOS to the new releases.&lt;br /&gt;
&lt;br /&gt;
You need to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; the repository using the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;git clone git://github.com/contiki-os/contiki.git contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that you need to download all development tools as described in the previous installation method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Primary contributors:&amp;#039;&amp;#039;&amp;#039; Pedro, Kwame&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Kwame, Pedro&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=228</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=228"/>
				<updated>2014-02-19T20:59:35Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Using Sourceforge repository */&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 guide covers installation of ContikiOS 2.7. There are basically three way of installing ContikiOS: downloading Instant Contiki, downloading ContikiOS from the Sourceforge repository or cloning it from the Github repository.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial will take you through the steps for downloading and installing ContikiOS the following ways:&lt;br /&gt;
&lt;br /&gt;
* Download Instant Contiki [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&lt;br /&gt;
* Download ContikiOS from Sourceforge repository [http://sourceforge.net/projects/contiki/files/latest/download]&lt;br /&gt;
* Clone ContikiOS from Github repository [https://github.com/contiki-os/contiki]&lt;br /&gt;
&lt;br /&gt;
=== Using Instant Contiki ===&lt;br /&gt;
&lt;br /&gt;
This is the easiest way of installing and using ContikiOS. You simply need to download Instant Contiki, which is a virtual machine created with all necessary toolchains and software for ContikiOS development.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Link to download Instant Contiki: [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
After downloading Instant Contiki you need also to download either VMWare Player or VirtualBox, if you are using Windows as your host OS. If you use MacOS X you should download VMWare Fusion, instead of VMWare Player.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: To login in to Instant Contiki: &amp;#039;&amp;#039;&amp;#039;username&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;passwork&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Using Sourceforge repository ===&lt;br /&gt;
&lt;br /&gt;
This method requires an existing installation of a Linux-based operating system. The guide assumes you are using Ubuntu 12.04 but should still be useful for similar versions.&lt;br /&gt;
&lt;br /&gt;
Download contiki-2.7.zip from http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; wget http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unzip the file. For the purposes of this guide, it is assumed that the file is unzipped into /home/user/&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;unzip contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rename the folder from contiki-2.7 to contiki.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;mv contiki-2.7 contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install all the required packages for compiling and running ContikiOS. &lt;br /&gt;
&lt;br /&gt;
If you are using a MSP430-based platform (such as Tmote) you only need the following packages: &amp;#039;&amp;#039;binutils-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430-libc&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430mcu&amp;#039;&amp;#039; and &amp;#039;&amp;#039;mspdebug&amp;#039;&amp;#039;. If you intend to code for multiple platforms, you should also install the following tool chains for other micro-controller: &amp;#039;&amp;#039;binutils-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gdb-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;avr-libc&amp;#039;&amp;#039; and &amp;#039;&amp;#039;avrdude&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
You can run the following command to install all packages for multiple platforms:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install build-essential binutils-msp430 gcc-msp430 msp430-libc msp430mcu &lt;br /&gt;
mspdebug binutils-avr gcc-avr gdb-avr avr-libc avrdude openjdk-7-jdk &lt;br /&gt;
openjdk-7-jre ant libncurses5-dev&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are done! You can now try to compile and run any example, such as [[Hello_World | Hello World]].&lt;br /&gt;
&lt;br /&gt;
== Using Github repository ==&lt;br /&gt;
&lt;br /&gt;
This method also requires an existing installation of a Linux-based operating system. It is very similar to the previous one, but instead of downloading the source code you are going to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; it from the official Github repository. &lt;br /&gt;
&lt;br /&gt;
This method eases the update of your ContikiOS to the new releases.&lt;br /&gt;
&lt;br /&gt;
You need to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; the repository using the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;git clone git://github.com/contiki-os/contiki.git contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that you need to download all development tools as described in the previous installation method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Primary contributors:&amp;#039;&amp;#039;&amp;#039; Pedro, Kwame&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Kwame, Pedro&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=227</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=227"/>
				<updated>2014-02-19T20:57:00Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Using Instant 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 guide covers installation of ContikiOS 2.7. There are basically three way of installing ContikiOS: downloading Instant Contiki, downloading ContikiOS from the Sourceforge repository or cloning it from the Github repository.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial will take you through the steps for downloading and installing ContikiOS the following ways:&lt;br /&gt;
&lt;br /&gt;
* Download Instant Contiki [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&lt;br /&gt;
* Download ContikiOS from Sourceforge repository [http://sourceforge.net/projects/contiki/files/latest/download]&lt;br /&gt;
* Clone ContikiOS from Github repository [https://github.com/contiki-os/contiki]&lt;br /&gt;
&lt;br /&gt;
=== Using Instant Contiki ===&lt;br /&gt;
&lt;br /&gt;
This is the easiest way of installing and using ContikiOS. You simply need to download Instant Contiki, which is a virtual machine created with all necessary toolchains and software for ContikiOS development.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Link to download Instant Contiki: [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
After downloading Instant Contiki you need also to download either VMWare Player or VirtualBox, if you are using Windows as your host OS. If you use MacOS X you should download VMWare Fusion, instead of VMWare Player.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: To login in to Instant Contiki: &amp;#039;&amp;#039;&amp;#039;username&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;passwork&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Using Sourceforge repository ==&lt;br /&gt;
&lt;br /&gt;
This method requires an existing installation of a Linux-based operating system. The guide assumes you are using Ubuntu 12.04 but should still be useful for similar versions.&lt;br /&gt;
&lt;br /&gt;
Download contiki-2.7.zip from http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; wget http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unzip the file. For the purposes of this guide, it is assumed that the file is unzipped into /home/user/&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;unzip contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rename the folder from contiki-2.7 to contiki.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;mv contiki-2.7 contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install all the required packages for compiling and running ContikiOS. &lt;br /&gt;
&lt;br /&gt;
If you are using a MSP430-based platform (such as Tmote) you only need the following packages: &amp;#039;&amp;#039;binutils-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430-libc&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430mcu&amp;#039;&amp;#039; and &amp;#039;&amp;#039;mspdebug&amp;#039;&amp;#039;. If you intend to code for multiple platforms, you should also install the following tool chains for other micro-controller: &amp;#039;&amp;#039;binutils-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gdb-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;avr-libc&amp;#039;&amp;#039; and &amp;#039;&amp;#039;avrdude&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
You can run the following command to install all packages for multiple platforms:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install build-essential binutils-msp430 gcc-msp430 msp430-libc msp430mcu &lt;br /&gt;
mspdebug binutils-avr gcc-avr gdb-avr avr-libc avrdude openjdk-7-jdk &lt;br /&gt;
openjdk-7-jre ant libncurses5-dev&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are done! You can now try to compile and run any example, such as [[Hello_World | Hello World]].&lt;br /&gt;
&lt;br /&gt;
== Using Github repository ==&lt;br /&gt;
&lt;br /&gt;
This method also requires an existing installation of a Linux-based operating system. It is very similar to the previous one, but instead of downloading the source code you are going to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; it from the official Github repository. &lt;br /&gt;
&lt;br /&gt;
This method eases the update of your ContikiOS to the new releases.&lt;br /&gt;
&lt;br /&gt;
You need to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; the repository using the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;git clone git://github.com/contiki-os/contiki.git contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that you need to download all development tools as described in the previous installation method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Primary contributors:&amp;#039;&amp;#039;&amp;#039; Pedro, Kwame&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Kwame, Pedro&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=226</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Installation&amp;diff=226"/>
				<updated>2014-02-19T20:56:04Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* 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 guide covers installation of ContikiOS 2.7. There are basically three way of installing ContikiOS: downloading Instant Contiki, downloading ContikiOS from the Sourceforge repository or cloning it from the Github repository.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
This tutorial will take you through the steps for downloading and installing ContikiOS the following ways:&lt;br /&gt;
&lt;br /&gt;
* Download Instant Contiki [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&lt;br /&gt;
* Download ContikiOS from Sourceforge repository [http://sourceforge.net/projects/contiki/files/latest/download]&lt;br /&gt;
* Clone ContikiOS from Github repository [https://github.com/contiki-os/contiki]&lt;br /&gt;
&lt;br /&gt;
== Using Instant Contiki ==&lt;br /&gt;
&lt;br /&gt;
This is the easiest way of installing and using ContikiOS. You simply need to download Instant Contiki, which is a virtual machine created with all necessary toolchains and software for ContikiOS development.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Link to download Instant Contiki: [http://sourceforge.net/projects/contiki/files/Instant%20Contiki/]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
After downloading Instant Contiki you need also to download either VMWare Player or VirtualBox, if you are using Windows as your host OS. If you use MacOS X you should download VMWare Fusion, instead of VMWare Player.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: To login in to Instant Contiki: &amp;#039;&amp;#039;&amp;#039;username&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;passwork&amp;#039;&amp;#039;&amp;#039;: &amp;#039;&amp;#039;user&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Using Sourceforge repository ==&lt;br /&gt;
&lt;br /&gt;
This method requires an existing installation of a Linux-based operating system. The guide assumes you are using Ubuntu 12.04 but should still be useful for similar versions.&lt;br /&gt;
&lt;br /&gt;
Download contiki-2.7.zip from http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; wget http://downloads.sourceforge.net/project/contiki/Contiki/Contiki%202.7/contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unzip the file. For the purposes of this guide, it is assumed that the file is unzipped into /home/user/&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;unzip contiki-2.7.zip&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rename the folder from contiki-2.7 to contiki.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;mv contiki-2.7 contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install all the required packages for compiling and running ContikiOS. &lt;br /&gt;
&lt;br /&gt;
If you are using a MSP430-based platform (such as Tmote) you only need the following packages: &amp;#039;&amp;#039;binutils-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-msp430&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430-libc&amp;#039;&amp;#039;, &amp;#039;&amp;#039;msp430mcu&amp;#039;&amp;#039; and &amp;#039;&amp;#039;mspdebug&amp;#039;&amp;#039;. If you intend to code for multiple platforms, you should also install the following tool chains for other micro-controller: &amp;#039;&amp;#039;binutils-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gcc-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;gdb-avr&amp;#039;&amp;#039;, &amp;#039;&amp;#039;avr-libc&amp;#039;&amp;#039; and &amp;#039;&amp;#039;avrdude&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
You can run the following command to install all packages for multiple platforms:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install build-essential binutils-msp430 gcc-msp430 msp430-libc msp430mcu &lt;br /&gt;
mspdebug binutils-avr gcc-avr gdb-avr avr-libc avrdude openjdk-7-jdk &lt;br /&gt;
openjdk-7-jre ant libncurses5-dev&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are done! You can now try to compile and run any example, such as [[Hello_World | Hello World]].&lt;br /&gt;
&lt;br /&gt;
== Using Github repository ==&lt;br /&gt;
&lt;br /&gt;
This method also requires an existing installation of a Linux-based operating system. It is very similar to the previous one, but instead of downloading the source code you are going to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; it from the official Github repository. &lt;br /&gt;
&lt;br /&gt;
This method eases the update of your ContikiOS to the new releases.&lt;br /&gt;
&lt;br /&gt;
You need to &amp;#039;&amp;#039;clone&amp;#039;&amp;#039; the repository using the following command:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;git clone git://github.com/contiki-os/contiki.git contiki&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that you need to download all development tools as described in the previous installation method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Primary contributors:&amp;#039;&amp;#039;&amp;#039; Pedro, Kwame&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Kwame, Pedro&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=225</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=225"/>
				<updated>2014-02-19T20:51:00Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Macros and Structures */&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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
== Connect the Tmote Sky ==&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will open your text editor, allowing you to edit the code inside the broadcast packet.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown :user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Understanding the code ==&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&lt;br /&gt;
&lt;br /&gt;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to a &amp;quot;[http://anrg.usc.edu/contiki/index.php?title=Protothreads protothread]&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_EXITHANDLER(handler) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;broadcast_close(struct broadcast_conn *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *, clock_time_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&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: Rahul, Nikhil, Bhavana, Lakshmi&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=224</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=224"/>
				<updated>2014-02-19T20:46:09Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* 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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
== Connect the Tmote Sky ==&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will open your text editor, allowing you to edit the code inside the broadcast packet.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown :user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Understanding the code ==&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to a &amp;quot;[http://anrg.usc.edu/contiki/index.php?title=Protothreads protothread]&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_EXITHANDLER(handler) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;broadcast_close(struct broadcast_conn *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *, clock_time_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&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: Rahul, Nikhil, Bhavana, Lakshmi&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=223</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=223"/>
				<updated>2014-02-19T20:45:51Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Connect the Tmote Sky */&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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
== Connect the Tmote Sky ==&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will open your text editor, allowing you to edit the code inside the broadcast packet.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown :user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to a &amp;quot;[http://anrg.usc.edu/contiki/index.php?title=Protothreads protothread]&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_EXITHANDLER(handler) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;broadcast_close(struct broadcast_conn *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *, clock_time_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&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: Rahul, Nikhil, Bhavana, Lakshmi&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=222</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=222"/>
				<updated>2014-02-19T20:45:32Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* You will learn */&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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will open your text editor, allowing you to edit the code inside the broadcast packet.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown :user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to a &amp;quot;[http://anrg.usc.edu/contiki/index.php?title=Protothreads protothread]&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_EXITHANDLER(handler) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;broadcast_close(struct broadcast_conn *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *, clock_time_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&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: Rahul, Nikhil, Bhavana, Lakshmi&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=221</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=221"/>
				<updated>2014-02-19T20:44:58Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* 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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 4 and 8 seconds such that all Tmote Sky boards nearby will receive the packet.&lt;br /&gt;
&lt;br /&gt;
=== You will learn ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will open your text editor, allowing you to edit the code inside the broadcast packet.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown :user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every [http://anrg.usc.edu/contiki/index.php?title=Process process] should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to a &amp;quot;[http://anrg.usc.edu/contiki/index.php?title=Protothreads protothread]&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;PROCESS_EXITHANDLER(handler) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;broadcast_close(struct broadcast_conn *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&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;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; etimer_set(struct etimer *, clock_time_t) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; static struct broadcast_conn &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&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: Rahul, Nikhil, Bhavana, Lakshmi&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=160</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=160"/>
				<updated>2014-02-08T00:47:56Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* Connect the Tmote Sky: */&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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown:user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every process should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to &amp;quot;protothread&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_EXITHANDLER(handler)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_BEGIN()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_close(struct broadcast_conn *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_END()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;etimer_set(struct etimer *, clock_time_t)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;static struct broadcast_conn&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=159</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=159"/>
				<updated>2014-02-08T00:47:45Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: /* You will learn: */&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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky: ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown:user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every process should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to &amp;quot;protothread&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_EXITHANDLER(handler)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_BEGIN()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_close(struct broadcast_conn *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_END()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;etimer_set(struct etimer *, clock_time_t)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;static struct broadcast_conn&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=158</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=158"/>
				<updated>2014-02-08T00:47:34Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: &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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn: ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky: ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown:user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every process should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to &amp;quot;protothread&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_EXITHANDLER(handler)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_BEGIN()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_close(struct broadcast_conn *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_END()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;etimer_set(struct etimer *, clock_time_t)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;static struct broadcast_conn&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=157</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=157"/>
				<updated>2014-02-08T00:46:56Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: &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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn: ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky: ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2: ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3: ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4: ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown:user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5: ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every process should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to &amp;quot;protothread&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_EXITHANDLER(handler)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_BEGIN()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_close(struct broadcast_conn *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_END()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;etimer_set(struct etimer *, clock_time_t)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;static struct broadcast_conn&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets. &lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. The struct broadcast_callbacks pointer is used in broadcast_open to point  to a function that will be called when a packet arrives on the channel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=154</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=154"/>
				<updated>2014-02-08T00:41:55Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: &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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn: ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky: ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2: ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c file. In order to do this, you will need to open the file with your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type the following into the terminal:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3: ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4: ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown:user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5: ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every process should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to &amp;quot;protothread&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_EXITHANDLER(handler)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_BEGIN()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_close(struct broadcast_conn *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn :  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_END()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn : A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks :  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;etimer_set(struct etimer *, clock_time_t)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer : A pointer to the event timer&lt;br /&gt;
*clock_time_t : The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;static struct broadcast_conn&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets.&lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct: this is called when a packet has been received by the broadcast module. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=152</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=152"/>
				<updated>2014-02-08T00:39:38Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: &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 exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn: ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky: ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; cd contiki-2.7/examples/rime &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2: ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c packet. In order to do this, you will need to open the packet within your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; gedit example-broadcast.c &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into terminal. This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3: ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“Hello”,  6) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; packetbuf_copyfrom(“yourName”,  9) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4: ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown:user /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5: ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky example-broadcast.upload login &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Congratulations! You have successfully programmed the Tmote Sky! &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Tip:&amp;#039;&amp;#039;&amp;#039; You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Understanding the code ===&lt;br /&gt;
The purpose of this example is to test the broadcast layer in Rime. A glance at core/net/rime/broadcast.h and core/net/rime/broadcast.c helps in the understanding underlying concepts of this example.&lt;br /&gt;
In the code, a process called example_broadcast_process is  kicked off by AUTOSTART_PROCESSES.&lt;br /&gt;
&lt;br /&gt;
==== Macros and Structures ====&lt;br /&gt;
&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;
Every process should be defined via the PROCESS macro.&lt;br /&gt;
PROCESS has two arguments: the variable of the process structure, and a human readable string name, which is used when debugging.&lt;br /&gt;
&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;
&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;
AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.&lt;br /&gt;
&lt;br /&gt;
*&amp;amp;name: Reference to the process name&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; broadcast_recv(struct broadcast_conn *, const rimeaddr_t *) &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function parses an incoming packet and displays the message and the address of the sender.&lt;br /&gt;
By setting it as the broadcast&amp;#039;s designated callback function, broadcast_recv is automatically called when a packet is received.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This structure which has 2 structures : abc_conn, broadcast_callbacks *. The abc_conn is basic type of connection over which the broadcast connection is developed. And, the broadcast_callbacks point to recv and sent functions (in this example, just recv).&lt;br /&gt;
&lt;br /&gt;
*rimeaddr_t *: This is a union which has a character array u8[RIMEADDR_SIZE].&lt;br /&gt;
&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;
A process in Contiki consists of a single reference to &amp;quot;protothread&amp;quot;. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system. &lt;br /&gt;
Each process in the module requires an event handler under the PROCESS_THREAD macro.&lt;br /&gt;
&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;
&lt;br /&gt;
Within the body of PROCESS_THREAD there are 3 major tasks:&lt;br /&gt;
* Initialization&lt;br /&gt;
** allocate resources&lt;br /&gt;
** define variables&lt;br /&gt;
** begin process&lt;br /&gt;
* Infinite Loop&lt;br /&gt;
** while(1) is used to create an infinite loop in which the actual event-handling response takes place&lt;br /&gt;
* Deallocation&lt;br /&gt;
** end process&lt;br /&gt;
** deallocate resources&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_EXITHANDLER(handler)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Specifies an action when a process exits.&lt;br /&gt;
NOTE: This declaration must come immediately before the PROCESS_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
* handler: The action to be performed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_BEGIN()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.This macro initiates PT_BEGIN(), which is declared at the starting point of a protothread. All C statements above the PT_BEGIN() invokation will be executed each time the protothread is scheduled.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_close(struct broadcast_conn *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function closes a broadcast connection that has previously been opened with broadcast_open().This function typically is called as an exit handler.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *:  This is same as the variable from boradcast_recv().&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PROCESS_END()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
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. This macro initiates PT_END().It must always be used together with a matching PT_BEGIN() macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;broadcast_open(struct broadcast_conn *, uint16_t ,const struct broadcast_callbacks *)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Sets up an identified best-effort broadcast connection. The caller will allocate the memory for the struct broadcast_conn, usually by declaring it as a static variable. The struct broadcast_callbacks pointer  points to a structure containing a pointer to a function that will be called when a packet arrives on the channel. This function opens a connection of type abc_conn and sets the callbacks to structure passed. Also, this points to channel_set_attributes() function.&lt;br /&gt;
&lt;br /&gt;
*broadcast_conn *: A pointer to a struct broadcast_conn&lt;br /&gt;
*uint16_t:  The channel on which the connection will operate&lt;br /&gt;
*broadcast_callbacks *:  A struct broadcast_callbacks with function pointers to functions that will be called when a packet has been received&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;etimer_set(struct etimer *, clock_time_t)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
This function is used to set an event timer for a time sometime in the future. When the event timer expires, the event PROCESS_EVENT_TIMER will be posted to the process that called the etimer_set() function.&lt;br /&gt;
&lt;br /&gt;
*etimer *: A pointer to the event timer&lt;br /&gt;
*clock_time_t *: The interval before the timer expires.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;static struct broadcast_conn&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The broadcast module sends a packet to all local area neighbors with a header that identifies the sender. It also adds a single-hop address as a packet attribute to out going packets.&lt;br /&gt;
broadcast_conn structure consists of two structures&lt;br /&gt;
*abc_conn struct*: the abc(Anonymous best effort local area Broadcast) module sends packets to all local area neighbors. It uses one channel.&lt;br /&gt;
*broadcast_callbacks struct*: this is called when a packet has been received by the broadcast module. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=27</id>
		<title>Broadcast Example</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Broadcast_Example&amp;diff=27"/>
				<updated>2014-02-01T02:31:54Z</updated>
		
		<summary type="html">&lt;p&gt;Bhavana: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== &amp;lt;u&amp;gt;Exercise 1 - Broadcast&amp;lt;/u&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
This exercise is an introduction into programming the [http://www.capsil.org/capsilwiki/index.php/TELOSB/TMote_Sky Tmote Sky]. It uses the Rime stack to communicate with other Contiki nodes over the radio. You will run the broadcast example already found in the Contiki core folders to send your name from a base station via broadcast packets. The exercise sends broadcast packets at random intervals between 20 and 40 seconds such that all Tmote Sky boards nearby will receive the packet. &lt;br /&gt;
&lt;br /&gt;
=== You will learn: ===&lt;br /&gt;
&lt;br /&gt;
* How to program the Broadcast communication found within the Rime stack&lt;br /&gt;
* How to encapsulate data in packets&lt;br /&gt;
&lt;br /&gt;
=== Connect the Tmote Sky: ===&lt;br /&gt;
Before continuing with the tutorial, plug a Tmote Sky into the computer’s USB port. The LEDs on the skymote will start blinking to indicate that the mote is connected.&lt;br /&gt;
&lt;br /&gt;
=== Step 1: ===&lt;br /&gt;
&lt;br /&gt;
The first step is to change directories. At this point you should be familiar with the Contiki 2.7 core folders. The Rime stack is located within the examples folder, so type &lt;br /&gt;
&lt;br /&gt;
cd contiki-2.7/examples/rime &lt;br /&gt;
&lt;br /&gt;
directly into terminal. Once inside the rime folder, use the ls command to view all the files within it. We will be working specifically with example-broadcast.c.&lt;br /&gt;
&lt;br /&gt;
=== Step 2: ===&lt;br /&gt;
&lt;br /&gt;
Next, we will edit the data in the example-broadcast.c packet. In order to do this, you will need to open the packet within your text editor. In this exercise, we use gedit, but feel free to use whichever text editor you are most comfortable with. Type: &lt;br /&gt;
&lt;br /&gt;
gedit example-broadcast.c&lt;br /&gt;
&lt;br /&gt;
into terminal. This will open your text editor, allowing you to edit the code inside the broadcast packet. &lt;br /&gt;
&lt;br /&gt;
=== Step 3: ===&lt;br /&gt;
&lt;br /&gt;
To edit the actual data that your Tmote Sky will broadcast, scroll down to the line that contains &lt;br /&gt;
&lt;br /&gt;
packetbuf_copyfrom(“Hello”,  6)&lt;br /&gt;
&lt;br /&gt;
Change the character string to your name. Then change the number of characters accordingly. Remember to account for the null zero associated with character strings in C when changing the number of characters. The line should now read&lt;br /&gt;
&lt;br /&gt;
packetbuf_copyfrom(“yourName”,  9)&lt;br /&gt;
&lt;br /&gt;
Save and exit the text editor. &lt;br /&gt;
&lt;br /&gt;
=== Step 4: ===&lt;br /&gt;
&lt;br /&gt;
In the next step we configure Tmote Sky. Connect your mote to your computer via USB. If you are using VirtualBox or Parallels, assure that the mote actually connects to your virtual machine (the LEDs on the mote will blink when connected to the laptop). &lt;br /&gt;
&lt;br /&gt;
Then in terminal, type &lt;br /&gt;
&lt;br /&gt;
sudo chown:user /dev/ttyUSB0&lt;br /&gt;
&lt;br /&gt;
You will be prompted to enter the password for your user account. If you are running Instant Contiki, the password is user. The sudo [http://en.wikipedia.org/wiki/Chown chown] command is used to change the owner of the file in Unix-systems.&lt;br /&gt;
&lt;br /&gt;
Note: If you manually installed Contiki, you must type in your username instead of user. Then, when prompted to do so, enter your password. &lt;br /&gt;
&lt;br /&gt;
=== Step 5: ===&lt;br /&gt;
&lt;br /&gt;
In this step, we will compile and upload the Broadcast packet to your Tmote Sky. In the terminal window, type&lt;br /&gt;
&lt;br /&gt;
make TARGET=sky example-broadcast.upload login&lt;br /&gt;
&lt;br /&gt;
You will notice that instead of typing example-broadcast.sky, we use example-broadcast.upload. The .upload tells Contiki to install the binary onto the attached mote. Additionally, we add login to use the terminal to communicate with the mote over the serial interface referred to by /dev/ttyUSB0. Note that login can be specified later in another call to make, i.e. make login.&lt;br /&gt;
&lt;br /&gt;
This should compile and upload the example-broadcast.c packet such that your mote will be able to broadcast your name. After the compilation is complete, the text broadcast message sent...  should appear in terminal every 2 to 4 seconds, indicating that your name (which we added within the text editor) is being broadcast to all other motes in the area.&lt;br /&gt;
&lt;br /&gt;
Congratulations! You have successfully programmed the Tmote Sky! &lt;br /&gt;
&lt;br /&gt;
Note: If at any point, you would like to exit the compilation/broadcast stage, press CTRL-C&lt;br /&gt;
&lt;br /&gt;
Tip: You can save the TARGET by typing make TARGET=sky savetarget into terminal to avoid compiling the target repeatedly.&lt;/div&gt;</summary>
		<author><name>Bhavana</name></author>	</entry>

	</feed>