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

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1786</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1786"/>
				<updated>2016-08-17T21:07:36Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Radio Layer */&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;
Contiki provides us with three network stacks,&lt;br /&gt;
&lt;br /&gt;
1. IPv4&amp;lt;br&amp;gt;&lt;br /&gt;
2. IPv6&amp;lt;br&amp;gt;&lt;br /&gt;
3. Rime&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The uIP TCP/IP stack, which provides us with IPv4 networking, the uIPv6 stack, which provides IPv6 networking, and the Rime stack, which is a set of custom lightweight networking protocols designed for low-power wireless networks.&lt;br /&gt;
&lt;br /&gt;
== Contiki Netstack ==&lt;br /&gt;
&lt;br /&gt;
Contiki&amp;#039;s Network Protocol stack (NETSTACK) organizes the network modules into a complete protocol stack covering all traditional OSI Layers.&lt;br /&gt;
 &lt;br /&gt;
[[File:Contikinetstack.png|center|frame|Contiki Network Stack]]&lt;br /&gt;
&lt;br /&gt;
=== Netstack Concepts ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Four Layers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
1. Network layer - NETSTACK_NETWORK&amp;lt;br&amp;gt;&lt;br /&gt;
2. MAC (Medium Access Control) layer - NETSTACK_MAC&amp;lt;br&amp;gt;&lt;br /&gt;
3. RDC (Radio Duty Cycling) layer - NETSTACK_RDC&amp;lt;br&amp;gt;&lt;br /&gt;
4. Radio layer - NETSTACK_RADIO&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The packet buffer - packetbuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* One buffer, holds a single packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* All layers of the netstack operate on the packetbuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Large enough to hold a single radio packet - PACKETBUF_CONF_LEN&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Queue buffers - queuebuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The packetbuf only holds the current packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* To store packets on queues, use a queuebuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Use a list to keep track of them.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;uIP packet buffer - uip_buf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Framers - NETSTACK_FRAMER&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The framer module converts link-layer headers to packet attributes - &amp;#039;&amp;#039;&amp;#039;parse()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* And packet attributes to link-layer headers - &amp;#039;&amp;#039;&amp;#039;create()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network &amp;amp; Routing Layer ==&lt;br /&gt;
&lt;br /&gt;
* Contiki automatically forms a wireless IPv6 network with the help of routing protocol called RPL (Routing Protocol for Low-power and Lossy Networks (LLNs)).&amp;lt;br&amp;gt;&lt;br /&gt;
* RPL forms routing graph from root node or AP (Access Point). It builds acyclic graph from root node called DODAG (Destination Oriented Directed Acyclic Graph).&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPLDODAG.png|center|frame|RPL DODAG]]&amp;lt;br&amp;gt;&lt;br /&gt;
* DIO (DODAG Information Object) messages are broadcast by all nodes starting from the root node. It includes the node&amp;#039;s rank, ETX, DAG version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF1.png|center|frame|5 nodes Network]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF2.png|center|frame|DIO message sent by root node]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF3.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF4.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF5.png|center|frame|Rank of the nodes with respect to the root]]&amp;lt;br&amp;gt;&lt;br /&gt;
* The node selects a parent based on the received DIO messages and calculates its rank.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adaptation Layer ==&lt;br /&gt;
&lt;br /&gt;
The network layer contains two sublayers, the upper IPv6 layer and the lower adaption layer.&lt;br /&gt;
&lt;br /&gt;
The Adaptation Layer provides IPv6 and UDP header compression and fragmentation to transport IPv6 packets with a maximum transmission (MTU) of 1280 bytes over IEEE 802.15.4 with a MTU of 127 byte.&lt;br /&gt;
&lt;br /&gt;
== MAC Layer ==&lt;br /&gt;
* The simplest layer in the IoT/IP stack.&amp;lt;br&amp;gt;&lt;br /&gt;
* Avoid collisions, back-off if there is traffic.&amp;lt;br&amp;gt;&lt;br /&gt;
* CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Sense the medium before sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Back-off if someone else is sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Timing depends on RDC layer.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Network layer decided number of transmissions.&amp;lt;br&amp;gt;&lt;br /&gt;
* nullmac: Forwards packets from the upper layer to the radio driver and vice versa.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RDC Layer ==&lt;br /&gt;
&lt;br /&gt;
Radio Duty Cycling layer saves energy by allowing a node to keep its radio transceiver off most of the time. &lt;br /&gt;
&lt;br /&gt;
Contiki has three duty cycling mechanisms: ContikiMAC, X-MAC and LPP. ContikiMAC is a protocol based on the principles behind low-power listening but with better power efficiency. Contiki&amp;#039;s X-MAC is based on the original X-MAC protocol, but has been enhanced to reduce power consumption and maintain good network conditions. Contiki&amp;#039;s LPP is based on the Low-Power Probing (LPP) protocol but with enhancements that improve power consumption as well as provide mechanisms for sending broadcast data.&lt;br /&gt;
&lt;br /&gt;
== Radio Layer ==&lt;br /&gt;
&lt;br /&gt;
Radio Layer is the lowest layer in the Contiki Netstack. Here, the data arrives in bytes or as a full packet via interrupt handlers. The input data is read out into the buffer, packetbuf and the process is polled. This polling process will cause the process to be sent to the special event and passed to the upper layers.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-building-the-internet-of-things-with-thingsquare-and-contiki-day-2-part-3&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-the-internet-of-things-with-thingsquare-and-contiki-day-1-part-2?related=1&amp;lt;br&amp;gt;&lt;br /&gt;
https://tools.ietf.org/html/rfc6550&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-1?next_slideshow=1&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/advanced-internet-of-things-firmware-engineering-with-thingsquare-and-contiki-day-1-part-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01793.html#_details&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/contiki-os/contiki/wiki/Radio-duty-cycling&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/hso-esk/emb6/wiki/The-emb6-Network-Stack&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1785</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1785"/>
				<updated>2016-08-17T21:05:26Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Radio Layer */&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;
Contiki provides us with three network stacks,&lt;br /&gt;
&lt;br /&gt;
1. IPv4&amp;lt;br&amp;gt;&lt;br /&gt;
2. IPv6&amp;lt;br&amp;gt;&lt;br /&gt;
3. Rime&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The uIP TCP/IP stack, which provides us with IPv4 networking, the uIPv6 stack, which provides IPv6 networking, and the Rime stack, which is a set of custom lightweight networking protocols designed for low-power wireless networks.&lt;br /&gt;
&lt;br /&gt;
== Contiki Netstack ==&lt;br /&gt;
&lt;br /&gt;
Contiki&amp;#039;s Network Protocol stack (NETSTACK) organizes the network modules into a complete protocol stack covering all traditional OSI Layers.&lt;br /&gt;
 &lt;br /&gt;
[[File:Contikinetstack.png|center|frame|Contiki Network Stack]]&lt;br /&gt;
&lt;br /&gt;
=== Netstack Concepts ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Four Layers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
1. Network layer - NETSTACK_NETWORK&amp;lt;br&amp;gt;&lt;br /&gt;
2. MAC (Medium Access Control) layer - NETSTACK_MAC&amp;lt;br&amp;gt;&lt;br /&gt;
3. RDC (Radio Duty Cycling) layer - NETSTACK_RDC&amp;lt;br&amp;gt;&lt;br /&gt;
4. Radio layer - NETSTACK_RADIO&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The packet buffer - packetbuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* One buffer, holds a single packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* All layers of the netstack operate on the packetbuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Large enough to hold a single radio packet - PACKETBUF_CONF_LEN&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Queue buffers - queuebuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The packetbuf only holds the current packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* To store packets on queues, use a queuebuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Use a list to keep track of them.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;uIP packet buffer - uip_buf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Framers - NETSTACK_FRAMER&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The framer module converts link-layer headers to packet attributes - &amp;#039;&amp;#039;&amp;#039;parse()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* And packet attributes to link-layer headers - &amp;#039;&amp;#039;&amp;#039;create()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network &amp;amp; Routing Layer ==&lt;br /&gt;
&lt;br /&gt;
* Contiki automatically forms a wireless IPv6 network with the help of routing protocol called RPL (Routing Protocol for Low-power and Lossy Networks (LLNs)).&amp;lt;br&amp;gt;&lt;br /&gt;
* RPL forms routing graph from root node or AP (Access Point). It builds acyclic graph from root node called DODAG (Destination Oriented Directed Acyclic Graph).&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPLDODAG.png|center|frame|RPL DODAG]]&amp;lt;br&amp;gt;&lt;br /&gt;
* DIO (DODAG Information Object) messages are broadcast by all nodes starting from the root node. It includes the node&amp;#039;s rank, ETX, DAG version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF1.png|center|frame|5 nodes Network]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF2.png|center|frame|DIO message sent by root node]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF3.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF4.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF5.png|center|frame|Rank of the nodes with respect to the root]]&amp;lt;br&amp;gt;&lt;br /&gt;
* The node selects a parent based on the received DIO messages and calculates its rank.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adaptation Layer ==&lt;br /&gt;
&lt;br /&gt;
The network layer contains two sublayers, the upper IPv6 layer and the lower adaption layer.&lt;br /&gt;
&lt;br /&gt;
The Adaptation Layer provides IPv6 and UDP header compression and fragmentation to transport IPv6 packets with a maximum transmission (MTU) of 1280 bytes over IEEE 802.15.4 with a MTU of 127 byte.&lt;br /&gt;
&lt;br /&gt;
== MAC Layer ==&lt;br /&gt;
* The simplest layer in the IoT/IP stack.&amp;lt;br&amp;gt;&lt;br /&gt;
* Avoid collisions, back-off if there is traffic.&amp;lt;br&amp;gt;&lt;br /&gt;
* CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Sense the medium before sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Back-off if someone else is sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Timing depends on RDC layer.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Network layer decided number of transmissions.&amp;lt;br&amp;gt;&lt;br /&gt;
* nullmac: Forwards packets from the upper layer to the radio driver and vice versa.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RDC Layer ==&lt;br /&gt;
&lt;br /&gt;
Radio Duty Cycling layer saves energy by allowing a node to keep its radio transceiver off most of the time. &lt;br /&gt;
&lt;br /&gt;
Contiki has three duty cycling mechanisms: ContikiMAC, X-MAC and LPP. ContikiMAC is a protocol based on the principles behind low-power listening but with better power efficiency. Contiki&amp;#039;s X-MAC is based on the original X-MAC protocol, but has been enhanced to reduce power consumption and maintain good network conditions. Contiki&amp;#039;s LPP is based on the Low-Power Probing (LPP) protocol but with enhancements that improve power consumption as well as provide mechanisms for sending broadcast data.&lt;br /&gt;
&lt;br /&gt;
== Radio Layer ==&lt;br /&gt;
&lt;br /&gt;
Radio Layer is the lowest layer in the Contiki Netstack. Here, the data arrives in bytes or as a full packet via interrupt handlers. The input data is read out into the buffer, packetbuf and poll the process. This polling process will cause the process to be sent to the special event and passed to the upper layers.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-building-the-internet-of-things-with-thingsquare-and-contiki-day-2-part-3&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-the-internet-of-things-with-thingsquare-and-contiki-day-1-part-2?related=1&amp;lt;br&amp;gt;&lt;br /&gt;
https://tools.ietf.org/html/rfc6550&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-1?next_slideshow=1&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/advanced-internet-of-things-firmware-engineering-with-thingsquare-and-contiki-day-1-part-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01793.html#_details&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/contiki-os/contiki/wiki/Radio-duty-cycling&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/hso-esk/emb6/wiki/The-emb6-Network-Stack&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1780</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1780"/>
				<updated>2016-08-17T20:35:37Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* References */&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;
Contiki provides us with three network stacks,&lt;br /&gt;
&lt;br /&gt;
1. IPv4&amp;lt;br&amp;gt;&lt;br /&gt;
2. IPv6&amp;lt;br&amp;gt;&lt;br /&gt;
3. Rime&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The uIP TCP/IP stack, which provides us with IPv4 networking, the uIPv6 stack, which provides IPv6 networking, and the Rime stack, which is a set of custom lightweight networking protocols designed for low-power wireless networks.&lt;br /&gt;
&lt;br /&gt;
== Contiki Netstack ==&lt;br /&gt;
&lt;br /&gt;
Contiki&amp;#039;s Network Protocol stack (NETSTACK) organizes the network modules into a complete protocol stack covering all traditional OSI Layers.&lt;br /&gt;
 &lt;br /&gt;
[[File:Contikinetstack.png|center|frame|Contiki Network Stack]]&lt;br /&gt;
&lt;br /&gt;
=== Netstack Concepts ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Four Layers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
1. Network layer - NETSTACK_NETWORK&amp;lt;br&amp;gt;&lt;br /&gt;
2. MAC (Medium Access Control) layer - NETSTACK_MAC&amp;lt;br&amp;gt;&lt;br /&gt;
3. RDC (Radio Duty Cycling) layer - NETSTACK_RDC&amp;lt;br&amp;gt;&lt;br /&gt;
4. Radio layer - NETSTACK_RADIO&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The packet buffer - packetbuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* One buffer, holds a single packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* All layers of the netstack operate on the packetbuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Large enough to hold a single radio packet - PACKETBUF_CONF_LEN&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Queue buffers - queuebuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The packetbuf only holds the current packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* To store packets on queues, use a queuebuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Use a list to keep track of them.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;uIP packet buffer - uip_buf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Framers - NETSTACK_FRAMER&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The framer module converts link-layer headers to packet attributes - &amp;#039;&amp;#039;&amp;#039;parse()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* And packet attributes to link-layer headers - &amp;#039;&amp;#039;&amp;#039;create()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network &amp;amp; Routing Layer ==&lt;br /&gt;
&lt;br /&gt;
* Contiki automatically forms a wireless IPv6 network with the help of routing protocol called RPL (Routing Protocol for Low-power and Lossy Networks (LLNs)).&amp;lt;br&amp;gt;&lt;br /&gt;
* RPL forms routing graph from root node or AP (Access Point). It builds acyclic graph from root node called DODAG (Destination Oriented Directed Acyclic Graph).&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPLDODAG.png|center|frame|RPL DODAG]]&amp;lt;br&amp;gt;&lt;br /&gt;
* DIO (DODAG Information Object) messages are broadcast by all nodes starting from the root node. It includes the node&amp;#039;s rank, ETX, DAG version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF1.png|center|frame|5 nodes Network]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF2.png|center|frame|DIO message sent by root node]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF3.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF4.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF5.png|center|frame|Rank of the nodes with respect to the root]]&amp;lt;br&amp;gt;&lt;br /&gt;
* The node selects a parent based on the received DIO messages and calculates its rank.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adaptation Layer ==&lt;br /&gt;
&lt;br /&gt;
== MAC Layer ==&lt;br /&gt;
* The simplest layer in the IoT/IP stack.&amp;lt;br&amp;gt;&lt;br /&gt;
* Avoid collisions, back-off if there is traffic.&amp;lt;br&amp;gt;&lt;br /&gt;
* CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Sense the medium before sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Back-off if someone else is sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Timing depends on RDC layer.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Network layer decided number of transmissions.&amp;lt;br&amp;gt;&lt;br /&gt;
* nullmac: Forwards packets from the upper layer to the radio driver and vice versa.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RDC Layer ==&lt;br /&gt;
&lt;br /&gt;
Radio Duty Cycling layer saves energy by allowing a node to keep its radio transceiver off most of the time. &lt;br /&gt;
&lt;br /&gt;
Contiki has three duty cycling mechanisms: ContikiMAC, X-MAC and LPP. ContikiMAC is a protocol based on the principles behind low-power listening but with better power efficiency. Contiki&amp;#039;s X-MAC is based on the original X-MAC protocol, but has been enhanced to reduce power consumption and maintain good network conditions. Contiki&amp;#039;s LPP is based on the Low-Power Probing (LPP) protocol but with enhancements that improve power consumption as well as provide mechanisms for sending broadcast data.&lt;br /&gt;
&lt;br /&gt;
== Radio Layer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-building-the-internet-of-things-with-thingsquare-and-contiki-day-2-part-3&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-the-internet-of-things-with-thingsquare-and-contiki-day-1-part-2?related=1&amp;lt;br&amp;gt;&lt;br /&gt;
https://tools.ietf.org/html/rfc6550&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-1?next_slideshow=1&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/advanced-internet-of-things-firmware-engineering-with-thingsquare-and-contiki-day-1-part-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01793.html#_details&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/contiki-os/contiki/wiki/Radio-duty-cycling&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1779</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1779"/>
				<updated>2016-08-17T20:35:04Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* RDC Layer */&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;
Contiki provides us with three network stacks,&lt;br /&gt;
&lt;br /&gt;
1. IPv4&amp;lt;br&amp;gt;&lt;br /&gt;
2. IPv6&amp;lt;br&amp;gt;&lt;br /&gt;
3. Rime&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The uIP TCP/IP stack, which provides us with IPv4 networking, the uIPv6 stack, which provides IPv6 networking, and the Rime stack, which is a set of custom lightweight networking protocols designed for low-power wireless networks.&lt;br /&gt;
&lt;br /&gt;
== Contiki Netstack ==&lt;br /&gt;
&lt;br /&gt;
Contiki&amp;#039;s Network Protocol stack (NETSTACK) organizes the network modules into a complete protocol stack covering all traditional OSI Layers.&lt;br /&gt;
 &lt;br /&gt;
[[File:Contikinetstack.png|center|frame|Contiki Network Stack]]&lt;br /&gt;
&lt;br /&gt;
=== Netstack Concepts ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Four Layers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
1. Network layer - NETSTACK_NETWORK&amp;lt;br&amp;gt;&lt;br /&gt;
2. MAC (Medium Access Control) layer - NETSTACK_MAC&amp;lt;br&amp;gt;&lt;br /&gt;
3. RDC (Radio Duty Cycling) layer - NETSTACK_RDC&amp;lt;br&amp;gt;&lt;br /&gt;
4. Radio layer - NETSTACK_RADIO&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The packet buffer - packetbuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* One buffer, holds a single packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* All layers of the netstack operate on the packetbuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Large enough to hold a single radio packet - PACKETBUF_CONF_LEN&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Queue buffers - queuebuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The packetbuf only holds the current packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* To store packets on queues, use a queuebuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Use a list to keep track of them.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;uIP packet buffer - uip_buf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Framers - NETSTACK_FRAMER&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The framer module converts link-layer headers to packet attributes - &amp;#039;&amp;#039;&amp;#039;parse()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* And packet attributes to link-layer headers - &amp;#039;&amp;#039;&amp;#039;create()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network &amp;amp; Routing Layer ==&lt;br /&gt;
&lt;br /&gt;
* Contiki automatically forms a wireless IPv6 network with the help of routing protocol called RPL (Routing Protocol for Low-power and Lossy Networks (LLNs)).&amp;lt;br&amp;gt;&lt;br /&gt;
* RPL forms routing graph from root node or AP (Access Point). It builds acyclic graph from root node called DODAG (Destination Oriented Directed Acyclic Graph).&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPLDODAG.png|center|frame|RPL DODAG]]&amp;lt;br&amp;gt;&lt;br /&gt;
* DIO (DODAG Information Object) messages are broadcast by all nodes starting from the root node. It includes the node&amp;#039;s rank, ETX, DAG version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF1.png|center|frame|5 nodes Network]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF2.png|center|frame|DIO message sent by root node]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF3.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF4.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF5.png|center|frame|Rank of the nodes with respect to the root]]&amp;lt;br&amp;gt;&lt;br /&gt;
* The node selects a parent based on the received DIO messages and calculates its rank.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adaptation Layer ==&lt;br /&gt;
&lt;br /&gt;
== MAC Layer ==&lt;br /&gt;
* The simplest layer in the IoT/IP stack.&amp;lt;br&amp;gt;&lt;br /&gt;
* Avoid collisions, back-off if there is traffic.&amp;lt;br&amp;gt;&lt;br /&gt;
* CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Sense the medium before sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Back-off if someone else is sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Timing depends on RDC layer.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Network layer decided number of transmissions.&amp;lt;br&amp;gt;&lt;br /&gt;
* nullmac: Forwards packets from the upper layer to the radio driver and vice versa.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RDC Layer ==&lt;br /&gt;
&lt;br /&gt;
Radio Duty Cycling layer saves energy by allowing a node to keep its radio transceiver off most of the time. &lt;br /&gt;
&lt;br /&gt;
Contiki has three duty cycling mechanisms: ContikiMAC, X-MAC and LPP. ContikiMAC is a protocol based on the principles behind low-power listening but with better power efficiency. Contiki&amp;#039;s X-MAC is based on the original X-MAC protocol, but has been enhanced to reduce power consumption and maintain good network conditions. Contiki&amp;#039;s LPP is based on the Low-Power Probing (LPP) protocol but with enhancements that improve power consumption as well as provide mechanisms for sending broadcast data.&lt;br /&gt;
&lt;br /&gt;
== Radio Layer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-building-the-internet-of-things-with-thingsquare-and-contiki-day-2-part-3&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-the-internet-of-things-with-thingsquare-and-contiki-day-1-part-2?related=1&amp;lt;br&amp;gt;&lt;br /&gt;
https://tools.ietf.org/html/rfc6550&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-1?next_slideshow=1&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/advanced-internet-of-things-firmware-engineering-with-thingsquare-and-contiki-day-1-part-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01793.html#_details&amp;lt;br&amp;gt;&lt;br /&gt;
https://github.com/contiki-os/contiki/wiki/Change-mac-or-radio-duty-cycling-protocols&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1777</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1777"/>
				<updated>2016-08-17T20:14:17Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* References */&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;
Contiki provides us with three network stacks,&lt;br /&gt;
&lt;br /&gt;
1. IPv4&amp;lt;br&amp;gt;&lt;br /&gt;
2. IPv6&amp;lt;br&amp;gt;&lt;br /&gt;
3. Rime&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The uIP TCP/IP stack, which provides us with IPv4 networking, the uIPv6 stack, which provides IPv6 networking, and the Rime stack, which is a set of custom lightweight networking protocols designed for low-power wireless networks.&lt;br /&gt;
&lt;br /&gt;
== Contiki Netstack ==&lt;br /&gt;
&lt;br /&gt;
Contiki&amp;#039;s Network Protocol stack (NETSTACK) organizes the network modules into a complete protocol stack covering all traditional OSI Layers.&lt;br /&gt;
 &lt;br /&gt;
[[File:Contikinetstack.png|center|frame|Contiki Network Stack]]&lt;br /&gt;
&lt;br /&gt;
=== Netstack Concepts ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Four Layers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
1. Network layer - NETSTACK_NETWORK&amp;lt;br&amp;gt;&lt;br /&gt;
2. MAC (Medium Access Control) layer - NETSTACK_MAC&amp;lt;br&amp;gt;&lt;br /&gt;
3. RDC (Radio Duty Cycling) layer - NETSTACK_RDC&amp;lt;br&amp;gt;&lt;br /&gt;
4. Radio layer - NETSTACK_RADIO&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The packet buffer - packetbuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* One buffer, holds a single packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* All layers of the netstack operate on the packetbuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Large enough to hold a single radio packet - PACKETBUF_CONF_LEN&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Queue buffers - queuebuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The packetbuf only holds the current packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* To store packets on queues, use a queuebuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Use a list to keep track of them.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;uIP packet buffer - uip_buf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Framers - NETSTACK_FRAMER&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The framer module converts link-layer headers to packet attributes - &amp;#039;&amp;#039;&amp;#039;parse()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* And packet attributes to link-layer headers - &amp;#039;&amp;#039;&amp;#039;create()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network &amp;amp; Routing Layer ==&lt;br /&gt;
&lt;br /&gt;
* Contiki automatically forms a wireless IPv6 network with the help of routing protocol called RPL (Routing Protocol for Low-power and Lossy Networks (LLNs)).&amp;lt;br&amp;gt;&lt;br /&gt;
* RPL forms routing graph from root node or AP (Access Point). It builds acyclic graph from root node called DODAG (Destination Oriented Directed Acyclic Graph).&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPLDODAG.png|center|frame|RPL DODAG]]&amp;lt;br&amp;gt;&lt;br /&gt;
* DIO (DODAG Information Object) messages are broadcast by all nodes starting from the root node. It includes the node&amp;#039;s rank, ETX, DAG version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF1.png|center|frame|5 nodes Network]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF2.png|center|frame|DIO message sent by root node]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF3.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF4.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF5.png|center|frame|Rank of the nodes with respect to the root]]&amp;lt;br&amp;gt;&lt;br /&gt;
* The node selects a parent based on the received DIO messages and calculates its rank.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adaptation Layer ==&lt;br /&gt;
&lt;br /&gt;
== MAC Layer ==&lt;br /&gt;
* The simplest layer in the IoT/IP stack.&amp;lt;br&amp;gt;&lt;br /&gt;
* Avoid collisions, back-off if there is traffic.&amp;lt;br&amp;gt;&lt;br /&gt;
* CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Sense the medium before sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Back-off if someone else is sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Timing depends on RDC layer.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Network layer decided number of transmissions.&amp;lt;br&amp;gt;&lt;br /&gt;
* nullmac: Forwards packets from the upper layer to the radio driver and vice versa.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RDC Layer ==&lt;br /&gt;
&lt;br /&gt;
== Radio Layer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-building-the-internet-of-things-with-thingsquare-and-contiki-day-2-part-3&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-the-internet-of-things-with-thingsquare-and-contiki-day-1-part-2?related=1&amp;lt;br&amp;gt;&lt;br /&gt;
https://tools.ietf.org/html/rfc6550&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-1?next_slideshow=1&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/advanced-internet-of-things-firmware-engineering-with-thingsquare-and-contiki-day-1-part-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01793.html#_details&lt;br /&gt;
https://github.com/contiki-os/contiki/wiki/Change-mac-or-radio-duty-cycling-protocols&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1776</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1776"/>
				<updated>2016-08-17T19:44:51Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &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;
Contiki provides us with three network stacks,&lt;br /&gt;
&lt;br /&gt;
1. IPv4&amp;lt;br&amp;gt;&lt;br /&gt;
2. IPv6&amp;lt;br&amp;gt;&lt;br /&gt;
3. Rime&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The uIP TCP/IP stack, which provides us with IPv4 networking, the uIPv6 stack, which provides IPv6 networking, and the Rime stack, which is a set of custom lightweight networking protocols designed for low-power wireless networks.&lt;br /&gt;
&lt;br /&gt;
== Contiki Netstack ==&lt;br /&gt;
&lt;br /&gt;
Contiki&amp;#039;s Network Protocol stack (NETSTACK) organizes the network modules into a complete protocol stack covering all traditional OSI Layers.&lt;br /&gt;
 &lt;br /&gt;
[[File:Contikinetstack.png|center|frame|Contiki Network Stack]]&lt;br /&gt;
&lt;br /&gt;
=== Netstack Concepts ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Four Layers&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
1. Network layer - NETSTACK_NETWORK&amp;lt;br&amp;gt;&lt;br /&gt;
2. MAC (Medium Access Control) layer - NETSTACK_MAC&amp;lt;br&amp;gt;&lt;br /&gt;
3. RDC (Radio Duty Cycling) layer - NETSTACK_RDC&amp;lt;br&amp;gt;&lt;br /&gt;
4. Radio layer - NETSTACK_RADIO&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;The packet buffer - packetbuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* One buffer, holds a single packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* All layers of the netstack operate on the packetbuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Large enough to hold a single radio packet - PACKETBUF_CONF_LEN&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Queue buffers - queuebuf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The packetbuf only holds the current packet.&amp;lt;br&amp;gt;&lt;br /&gt;
* To store packets on queues, use a queuebuf.&amp;lt;br&amp;gt;&lt;br /&gt;
* Use a list to keep track of them.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;uIP packet buffer - uip_buf&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Framers - NETSTACK_FRAMER&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* The framer module converts link-layer headers to packet attributes - &amp;#039;&amp;#039;&amp;#039;parse()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
* And packet attributes to link-layer headers - &amp;#039;&amp;#039;&amp;#039;create()&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network &amp;amp; Routing Layer ==&lt;br /&gt;
&lt;br /&gt;
* Contiki automatically forms a wireless IPv6 network with the help of routing protocol called RPL (Routing Protocol for Low-power and Lossy Networks (LLNs)).&amp;lt;br&amp;gt;&lt;br /&gt;
* RPL forms routing graph from root node or AP (Access Point). It builds acyclic graph from root node called DODAG (Destination Oriented Directed Acyclic Graph).&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPLDODAG.png|center|frame|RPL DODAG]]&amp;lt;br&amp;gt;&lt;br /&gt;
* DIO (DODAG Information Object) messages are broadcast by all nodes starting from the root node. It includes the node&amp;#039;s rank, ETX, DAG version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF1.png|center|frame|5 nodes Network]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF2.png|center|frame|DIO message sent by root node]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF3.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF4.png|center|frame|DIO message broadcasted by receiving nodes]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:NF5.png|center|frame|Rank of the nodes with respect to the root]]&amp;lt;br&amp;gt;&lt;br /&gt;
* The node selects a parent based on the received DIO messages and calculates its rank.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adaptation Layer ==&lt;br /&gt;
&lt;br /&gt;
== MAC Layer ==&lt;br /&gt;
* The simplest layer in the IoT/IP stack.&amp;lt;br&amp;gt;&lt;br /&gt;
* Avoid collisions, back-off if there is traffic.&amp;lt;br&amp;gt;&lt;br /&gt;
* CSMA/CA: Carrier Sense Multiple Access with Collision Avoidance&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Sense the medium before sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Back-off if someone else is sending.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Timing depends on RDC layer.&amp;lt;br&amp;gt;&lt;br /&gt;
:+ Network layer decided number of transmissions.&amp;lt;br&amp;gt;&lt;br /&gt;
* nullmac: Forwards packets from the upper layer to the radio driver and vice versa.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RDC Layer ==&lt;br /&gt;
&lt;br /&gt;
== Radio Layer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-building-the-internet-of-things-with-thingsquare-and-contiki-day-2-part-3&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-the-internet-of-things-with-thingsquare-and-contiki-day-1-part-2?related=1&amp;lt;br&amp;gt;&lt;br /&gt;
https://tools.ietf.org/html/rfc6550&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/building-day-2-upload-1?next_slideshow=1&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.slideshare.net/ADunkels/advanced-internet-of-things-firmware-engineering-with-thingsquare-and-contiki-day-1-part-2&amp;lt;br&amp;gt;&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01793.html#_details&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1771</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1771"/>
				<updated>2016-08-16T20:07:58Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Contiki Shell Commands, their usage and Contiki shell programming */&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;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The Contiki Shell is an interactive on-mote UNIX-­style shell that allows for text‐based interaction with a sensor node or a network of sensor nodes through a set of commands that can be executed on a UNIX like command line terminal. It has features such as piping data, run in background, file system interaction, network commands, sensor measurement commands and system commands. The shell can be accessed either over a serial USB connection or over a network using Telnet. &lt;br /&gt;
&lt;br /&gt;
Below are the various instances of shells provided in Contiki:&lt;br /&gt;
&amp;lt;p&amp;gt;1) &amp;#039;&amp;#039;&amp;#039;example-shell&amp;#039;&amp;#039;&amp;#039;: This shell can be compiled only for the native target, but not on Tmote Sky due to the firmware image size limitation on the Tmote Sky.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;2) &amp;#039;&amp;#039;&amp;#039;sky-shell&amp;#039;&amp;#039;&amp;#039;: This shell is a thinned out version, which can be compiled on Tmote Sky nodes, allowing the firmware image to fit the Tmote Sky memory.&amp;lt;/p&amp;gt; &lt;br /&gt;
&amp;lt;p&amp;gt;3) &amp;#039;&amp;#039;&amp;#039;sky-shell-exec&amp;#039;&amp;#039;&amp;#039;: This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;4) &amp;#039;&amp;#039;&amp;#039;sky-shell-webserver&amp;#039;&amp;#039;&amp;#039;: This is a shell that features the command sky-all-data, allowing to collect different sensor measurements and network   statistics from a Tmote Sky mote.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will run the shell over a USB serial connection and will focus on &amp;#039;&amp;#039;&amp;#039;example-shell&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;sky-shell&amp;#039;&amp;#039;&amp;#039; provided in Contiki source.&lt;br /&gt;
&lt;br /&gt;
== Objective ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;At the end of this tutorial, goal is to make you at ease with the Contiki shell.&amp;lt;/p&amp;gt;&lt;br /&gt;
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
In this tutorial you will learn about the following topics:&lt;br /&gt;
&amp;lt;p&amp;gt;1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;2) Various Contiki Shell Commands, their usage and Contiki shell programming.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;3) How to create your own Shell Commands.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;4) How to create your own Shell for Contiki through an example project.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;5) You get to execute various fun examples and understand the Contiki shell along the way.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sounds exciting ? Game for it ? Let&amp;#039;s begin then!&lt;br /&gt;
&lt;br /&gt;
== Source Code and Example Projects ==&lt;br /&gt;
&amp;lt;p&amp;gt;Let&amp;#039;s figure out where the source code for shell is in Contiki &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This folder has all the source and headers for the Contiki Shell &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;p&amp;gt; This folder has the example-shell project &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/examples/example-shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;p&amp;gt; This folder has the sky-shell project &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;~/contiki-2.7/examples/sky-shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== How to Compile and Install a Contiki shell ? ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;#039;&amp;#039;&amp;#039; example-shell is a Comprehensive Shell and can be used for initial development. &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Pros: It&amp;#039;s compiled on the native target, so you have the flexibility of developing your own shell commands and include it in the shell for further testing. Since, there&amp;#039;s no stringent memory constraints on native targets, this project is useful for initial development phase.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can&amp;#039;t be compiled on Tmote Sky motes. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;example-shell.c&amp;#039;&amp;#039;&amp;#039; is the shell file in this project.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; These shell_xx_init() are located in contiki-2.7/apps/shell/ in files like shell-filename.c. You can explore the source code to check for what features they come with and what&amp;#039;s in it, to make our lives simpler. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS(example_shell_process, &amp;quot;Contiki shell&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_shell_process);&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS_THREAD(example_shell_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  serial_shell_init();&lt;br /&gt;
&lt;br /&gt;
  shell_base64_init();&lt;br /&gt;
  shell_blink_init();&lt;br /&gt;
  /*shell_checkpoint_init();*/&lt;br /&gt;
  /*shell_coffee_init();*/&lt;br /&gt;
  shell_download_init();&lt;br /&gt;
  /*shell_exec_init();*/&lt;br /&gt;
  shell_file_init();&lt;br /&gt;
  shell_httpd_init();&lt;br /&gt;
  shell_irc_init();&lt;br /&gt;
  shell_netfile_init();&lt;br /&gt;
  /*shell_ping_init();*/ /* uIP ping */&lt;br /&gt;
  shell_power_init();&lt;br /&gt;
  /*shell_profile_init();*/&lt;br /&gt;
  shell_ps_init();&lt;br /&gt;
  /*shell_reboot_init();*/&lt;br /&gt;
  shell_rime_debug_init();&lt;br /&gt;
  shell_rime_netcmd_init();&lt;br /&gt;
  shell_rime_ping_init(); /* Rime ping */&lt;br /&gt;
  shell_rime_sendcmd_init();&lt;br /&gt;
  shell_rime_sniff_init();&lt;br /&gt;
  shell_rime_init();&lt;br /&gt;
  /*shell_rsh_init();*/&lt;br /&gt;
  shell_run_init();&lt;br /&gt;
  shell_sendtest_init();&lt;br /&gt;
  /*shell_sky_init();*/&lt;br /&gt;
  shell_tcpsend_init();&lt;br /&gt;
  shell_text_init();&lt;br /&gt;
  shell_time_init();&lt;br /&gt;
  shell_udpsend_init();&lt;br /&gt;
  shell_vars_init();&lt;br /&gt;
  shell_wget_init();&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; As we see above some of the shell_xx_init() are already commented out, this done on the pretext that these features are not supported on native target.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;#039;&amp;#039;&amp;#039; Compiling and installing the Contiki shell on native target &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd contiki-2.7/examples/example-shell &lt;br /&gt;
make  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; Run the Contiki Shell on native target &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;./example-shell.native &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; After running the Contiki Shell, you will see the Contiki Shell prompt &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native &lt;br /&gt;
Contiki 2.7 started&lt;br /&gt;
Rime started with address 2.1&lt;br /&gt;
MAC nullmac RDC nullrdc NETWORK Rime&lt;br /&gt;
2.1: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.&lt;br /&gt;
&amp;lt;pre&amp;gt;help&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;You can now run any supported shell commands&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;For example, running &amp;#039;&amp;#039;&amp;#039;echo hello&amp;#039;&amp;#039;&amp;#039; will echo the &amp;lt;text&amp;gt; back on the shell prompt. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;2.1: Contiki&amp;gt; &lt;br /&gt;
echo hello&lt;br /&gt;
hello&lt;br /&gt;
2.1: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;#039;&amp;#039;&amp;#039;sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;sky-shell.c&amp;#039;&amp;#039;&amp;#039; is the shell file in this project&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS(sky_shell_process, &amp;quot;Sky Contiki shell&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sky_shell_process);&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
#define WITH_PERIODIC_DEBUG 0&lt;br /&gt;
#if WITH_PERIODIC_DEBUG&lt;br /&gt;
static struct ctimer debug_timer;&lt;br /&gt;
static void&lt;br /&gt;
periodic_debug(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  ctimer_set(&amp;amp;debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);&lt;br /&gt;
  collect_print_stats();&lt;br /&gt;
}&lt;br /&gt;
#endif /* WITH_PERIODIC_DEBUG */&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS_THREAD(sky_shell_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
#if WITH_PERIODIC_DEBUG&lt;br /&gt;
  ctimer_set(&amp;amp;debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);&lt;br /&gt;
#endif /* WITH_PERIODIC_DEBUG */&lt;br /&gt;
&lt;br /&gt;
  serial_shell_init();&lt;br /&gt;
  shell_blink_init();&lt;br /&gt;
  /*  shell_file_init();&lt;br /&gt;
      shell_coffee_init();*/&lt;br /&gt;
  /*  shell_download_init();&lt;br /&gt;
      shell_rime_sendcmd_init();*/&lt;br /&gt;
  /*  shell_ps_init();*/&lt;br /&gt;
  shell_reboot_init();&lt;br /&gt;
  shell_rime_init();&lt;br /&gt;
  shell_rime_netcmd_init();&lt;br /&gt;
  /*  shell_rime_ping_init();&lt;br /&gt;
  shell_rime_debug_init();&lt;br /&gt;
  shell_rime_debug_runicast_init();*/&lt;br /&gt;
  /*  shell_rime_sniff_init();*/&lt;br /&gt;
  shell_sky_init();&lt;br /&gt;
  shell_power_init();&lt;br /&gt;
  shell_powertrace_init();&lt;br /&gt;
  /*  shell_base64_init();*/&lt;br /&gt;
  shell_text_init();&lt;br /&gt;
  shell_time_init();&lt;br /&gt;
  /*  shell_checkpoint_init();*/&lt;br /&gt;
  /*  shell_sendtest_init();*/&lt;br /&gt;
  shell_rime_unicast_init();&lt;br /&gt;
  shell_collect_view_init();&lt;br /&gt;
&lt;br /&gt;
#if DEBUG_SNIFFERS&lt;br /&gt;
  rime_sniffer_add(&amp;amp;s);&lt;br /&gt;
#endif /* DEBUG_SNIFFERS */&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; As we see above some of the shell_xx_init() are already commented out, this done on the pretext that these features if supported will overflow the Tmote Sky memory and the Code will not compile.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039; However, if we require any shell_xx_init() features, we can uncomment them but we need to make sure the code compiles such that the sky mote memory doesn&amp;#039;t overflow. serial_shell_init() invokes the serial contiki shell&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;#039;&amp;#039;&amp;#039; Compiling and uploading the Contiki Sky Shell on sky motes &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;To install a shell on the a node, go to the sky-shell, connect a TMote sky to your computer and upload the shell application on the node.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd contiki-2.7/examples/sky-shell &lt;br /&gt;
make TARGET=sky sky-shell.upload savetarget &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Wait for the compilation and uploading to finish.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;To connect to the shell over the USB port, run: &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; You can now login to the node with the command &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make login &amp;lt;/pre&amp;gt; &amp;lt;p&amp;gt;Press the return key to get a shell prompt.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; After running the Contiki Shell, you will see the Contiki Sky Shell prompt &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login&lt;br /&gt;
using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
connecting to /dev/ttyUSB0 (115200) [OK]&lt;br /&gt;
&lt;br /&gt;
SEND 1 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;help&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;You can now run any supported shell commands&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;For example, running &amp;#039;&amp;#039;&amp;#039;echo hello&amp;#039;&amp;#039;&amp;#039; will echo the &amp;lt;text&amp;gt; back on the shell prompt. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
echo hello&lt;br /&gt;
SEND 11 bytes&lt;br /&gt;
hello&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Modify sky-shell project for this tutorial ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Replace the sky-shell.c file with the following version of sky-shell.c file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; Please copy the below source code into the sky-shell.c file &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2008, Swedish Institute of Computer Science.&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 * 3. Neither the name of the Institute nor the names of its contributors&lt;br /&gt;
 *    may be used to endorse or promote products derived from this software&lt;br /&gt;
 *    without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS&amp;#039;&amp;#039; AND&lt;br /&gt;
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE&lt;br /&gt;
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE&lt;br /&gt;
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&lt;br /&gt;
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS&lt;br /&gt;
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;br /&gt;
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT&lt;br /&gt;
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY&lt;br /&gt;
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;br /&gt;
 * SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 * This file is part of the Contiki operating system.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * \file&lt;br /&gt;
 *         Tmote Sky-specific Contiki shell&lt;br /&gt;
 * \author&lt;br /&gt;
 *         Adam Dunkels &amp;lt;adam@sics.se&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;shell.h&amp;quot;&lt;br /&gt;
#include &amp;quot;serial-shell.h&amp;quot;&lt;br /&gt;
#include &amp;quot;collect-view.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;net/rime/rime.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS(sky_shell_process, &amp;quot;Sky Contiki shell&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;sky_shell_process);&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
#define WITH_PERIODIC_DEBUG 0&lt;br /&gt;
#if WITH_PERIODIC_DEBUG&lt;br /&gt;
static struct ctimer debug_timer;&lt;br /&gt;
static void&lt;br /&gt;
periodic_debug(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  ctimer_set(&amp;amp;debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);&lt;br /&gt;
  collect_print_stats();&lt;br /&gt;
}&lt;br /&gt;
#endif /* WITH_PERIODIC_DEBUG */&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS_THREAD(sky_shell_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
#if WITH_PERIODIC_DEBUG&lt;br /&gt;
  ctimer_set(&amp;amp;debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);&lt;br /&gt;
#endif /* WITH_PERIODIC_DEBUG */&lt;br /&gt;
&lt;br /&gt;
  serial_shell_init();&lt;br /&gt;
  shell_blink_init();&lt;br /&gt;
  shell_file_init();&lt;br /&gt;
&lt;br /&gt;
  shell_ps_init();&lt;br /&gt;
  shell_reboot_init();&lt;br /&gt;
&lt;br /&gt;
  shell_sky_init();&lt;br /&gt;
  shell_power_init();&lt;br /&gt;
  shell_powertrace_init();&lt;br /&gt;
&lt;br /&gt;
  shell_text_init();&lt;br /&gt;
  shell_time_init();&lt;br /&gt;
&lt;br /&gt;
  shell_collect_view_init();&lt;br /&gt;
&lt;br /&gt;
#if DEBUG_SNIFFERS&lt;br /&gt;
  rime_sniffer_add(&amp;amp;s);&lt;br /&gt;
#endif /* DEBUG_SNIFFERS */&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This will create a sky shell with features or shell commands that we will go through in the next section&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Please compile the sky-shell project and upload the sky-shell.upload to the Sky mote and Login to the mote as explained in previous section&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;If successful you should be able to see the following and get a Contiki shell prompt&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget&lt;br /&gt;
  AR        contiki-sky.a&lt;br /&gt;
  CC        sky-shell.c&lt;br /&gt;
  CC        ../../platform/sky/./contiki-sky-main.c&lt;br /&gt;
  LD        sky-shell.sky&lt;br /&gt;
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex&lt;br /&gt;
make IHEXFILE=sky-shell.ihex sky-reset sky-upload&lt;br /&gt;
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
make -k -j 20 sky-reset-sequence&lt;br /&gt;
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Use -h for help&lt;br /&gt;
Reset device ...&lt;br /&gt;
Done&lt;br /&gt;
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
make -j 20 sky-upload-sequence&lt;br /&gt;
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
+++++ Erasing /dev/ttyUSB0&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Use -h for help&lt;br /&gt;
Mass Erase...&lt;br /&gt;
Transmit default password ...&lt;br /&gt;
+++++ Programming /dev/ttyUSB0&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Invoking BSL...&lt;br /&gt;
Transmit default password ...&lt;br /&gt;
Current bootstrap loader version: 1.61 (Device ID: f16c)&lt;br /&gt;
Changing baudrate to 38400 ...&lt;br /&gt;
Program ...&lt;br /&gt;
45722 bytes programmed.&lt;br /&gt;
+++++ Resetting /dev/ttyUSB0&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Use -h for help&lt;br /&gt;
Reset device ...&lt;br /&gt;
Done&lt;br /&gt;
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
saving Makefile.target&lt;br /&gt;
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex&lt;br /&gt;
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login&lt;br /&gt;
using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
connecting to /dev/ttyUSB0 (115200) [OK]&lt;br /&gt;
+�{/#+�3++�&amp;amp;�&lt;br /&gt;
SEND 1 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;If you don&amp;#039;t end up getting the above set of messages on the comand prompt and end up getting the set of messages on command prompt as shown below, then your setup has not been successful&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget&lt;br /&gt;
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex&lt;br /&gt;
make IHEXFILE=sky-shell.ihex sky-reset sky-upload&lt;br /&gt;
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
make -k -j 20 sky-reset-sequence&lt;br /&gt;
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
Done&lt;br /&gt;
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
make -j 20 sky-upload-sequence&lt;br /&gt;
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
Done&lt;br /&gt;
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell&amp;#039;&lt;br /&gt;
saving Makefile.target&lt;br /&gt;
rm sky-shell.ihex&lt;br /&gt;
user@instant-contiki:~/contiki-2.7/examples/sky-shell$&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This indicates that your Tmote Sky mote is disconnected!!!&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Make sure that your Tmote Sky mote is connected and try compiling again and it should work this time :) Did you heave a sigh there?&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;I did! When I figured out what was going wrong.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Nevertheless, we are All Set and Good to Launch now :) :)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Contiki Shell Commands, their usage and Contiki shell programming ==&lt;br /&gt;
Ready to dive in ?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Everyone needs help at some point in time, don&amp;#039;t we? So let&amp;#039;s punch in help on the Contiki Sky Shell to figure out what all shell commands are at our disposal and we will take them head on, one at a time :) &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;You should see a list of all available shell commands as shown below:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
help&lt;br /&gt;
SEND 5 bytes&lt;br /&gt;
Available commands:&lt;br /&gt;
?: shows this help&lt;br /&gt;
append &amp;lt;filename&amp;gt;: append to file&lt;br /&gt;
binprint: print binary data in decimal format&lt;br /&gt;
blink [num]: blink LEDs ([num] times)&lt;br /&gt;
collect-view-data: sensor data, power consumption, network stats&lt;br /&gt;
echo &amp;lt;text&amp;gt;: print &amp;lt;text&amp;gt;&lt;br /&gt;
energy: print energy profile&lt;br /&gt;
exit: exit shell&lt;br /&gt;
hd: print binary data in hexadecimal format&lt;br /&gt;
help: shows this help&lt;br /&gt;
kill &amp;lt;command&amp;gt;: stop a specific command&lt;br /&gt;
killall: stop all running commands&lt;br /&gt;
ls: list files&lt;br /&gt;
nodeid: set node ID&lt;br /&gt;
null: discard input&lt;br /&gt;
power: print power profile&lt;br /&gt;
powerconv: convert power profile to human readable output&lt;br /&gt;
powertrace [interval]: turn powertracing on or off, with reporting interval &amp;lt;interval&amp;gt;&lt;br /&gt;
ps: list all running processes&lt;br /&gt;
quit: exit shell&lt;br /&gt;
randwait &amp;lt;maxtime&amp;gt; &amp;lt;command&amp;gt;: wait for a random time before running a command&lt;br /&gt;
read &amp;lt;filename&amp;gt; [offset] [block size]: read from a file, with the offset and the block size as options&lt;br /&gt;
reboot: reboot the system&lt;br /&gt;
repeat &amp;lt;num&amp;gt; &amp;lt;time&amp;gt; &amp;lt;command&amp;gt;: run a command every &amp;lt;time&amp;gt; seconds&lt;br /&gt;
rfchannel &amp;lt;channel&amp;gt;: change CC2420 radio channel (11 - 26)&lt;br /&gt;
rm &amp;lt;filename&amp;gt;: remove the file named filename&lt;br /&gt;
sense: print out sensor data&lt;br /&gt;
senseconv: convert &amp;#039;sense&amp;#039; data to human readable format&lt;br /&gt;
size: print the size of the input&lt;br /&gt;
time [seconds]: output time in binary format, or set time in seconds since 1970&lt;br /&gt;
timestamp: prepend a timestamp to data&lt;br /&gt;
txpower &amp;lt;power&amp;gt;: change CC2420 transmission power (0 - 31)&lt;br /&gt;
write &amp;lt;filename&amp;gt;: write to file&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Lets, go ahead and do the simplest first! echo :)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
echo howdy contiki shell?&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 6 bytes&lt;br /&gt;
howdy contiki shell?&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Contiki Shell Commands&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;1) Text Related Commands:&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;echo &amp;lt;text&amp;gt;&amp;#039;&amp;#039;&amp;#039;: print &amp;lt;text&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;binprint&amp;#039;&amp;#039;&amp;#039;: print binary data in decimal format&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;hd&amp;#039;&amp;#039;&amp;#039;: print binary data in hexadecimal format&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;size&amp;#039;&amp;#039;&amp;#039;: print the size of the input&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell-text.c&amp;#039;&amp;#039;&amp;#039; : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell_text_init()&amp;#039;&amp;#039;&amp;#039;: This function is used to register text related shell commands with the Contiki Shell.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;echo carpe diem!&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
echo carpe diem!&lt;br /&gt;
SEND 17 bytes&lt;br /&gt;
carpe diem!&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;The following commands prints time data in decimal format.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;2943 secs have elapsed since the mote was last power up.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time | binprint &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
time | binprint&lt;br /&gt;
SEND 16 bytes&lt;br /&gt;
6 49032 34883 0 65535 0 2943 &lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;The following command prints data in hexadecimal format.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;hd&amp;lt;/p&amp;gt;&lt;br /&gt;
Press Cntrl+Return&lt;br /&gt;
&amp;lt;p&amp;gt;hello world&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Press Cntrl+Return to get the shell prompt back after output is printed.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
hd&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
hello world&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 &amp;lt;/pre&amp;gt;&lt;br /&gt;
------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;The following command prints size of the data.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;size&amp;lt;/p&amp;gt;&lt;br /&gt;
Press Cntrl+Return&lt;br /&gt;
&amp;lt;p&amp;gt;trojan for life!&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Press Cntrl+Return to get the shell prompt back after output is printed.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
size&lt;br /&gt;
SEND 5 bytes&lt;br /&gt;
trojan for life!&lt;br /&gt;
SEND 17 bytes&lt;br /&gt;
&lt;br /&gt;
SEND 1 bytes&lt;br /&gt;
16&lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
------------------------------------------&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;2) Time related Shell commands&amp;#039;&amp;#039;&amp;#039;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;time [seconds]&amp;#039;&amp;#039;&amp;#039;: output time in binary format, or set time in seconds since 1970.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;repeat &amp;lt;num&amp;gt; &amp;lt;time&amp;gt; &amp;lt;command&amp;gt;&amp;#039;&amp;#039;&amp;#039;: run a command every time seconds.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;randwait &amp;lt;maxtime&amp;gt; &amp;lt;command&amp;gt;&amp;#039;&amp;#039;&amp;#039;: wait for a random time before running a command.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;timestamp&amp;#039;&amp;#039;&amp;#039;: prepend a timestamp to data.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;shell-time.c&amp;#039;&amp;#039;&amp;#039; : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;shell_time_init()&amp;#039;&amp;#039;&amp;#039;: This function is used to register time related shell commands with the Contiki Shell.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;Following command will set the current time on mote to 10 secs after 1970.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;That it forces the time to be set to a value given.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time 10 | binprint &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
time 10 | binprint&lt;br /&gt;
SEND 19 bytes&lt;br /&gt;
6 59950 11844 0 65535 0 10 &lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
--------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;Following command will set the current time on mote to 66000 secs after 1970.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Since 66000 &amp;gt; 65536 , time[0] overflows and time[1] has the order bits &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time 66000 | binprint &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
time 66000 | binprint&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
6 39554 33340 0 65535 1 464 &lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time 0 | randwait 10 {repeat 10 1 {time | binprint}}&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Press Cntrl+Return to get the shell prompt back after output is printed.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
time 0 | randwait 10 {repeat 10 1 {time | binprint}}    &lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 13 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
6 4870 1641 0 65535 0 9 &lt;br /&gt;
6 4998 34372 0 65535 0 10 &lt;br /&gt;
6 5126 1604 0 65535 0 11 &lt;br /&gt;
6 5254 34372 0 65535 0 12 &lt;br /&gt;
6 5382 1605 0 65535 0 13 &lt;br /&gt;
6 5510 34372 0 65535 0 14 &lt;br /&gt;
6 5638 1604 0 65535 0 15 &lt;br /&gt;
6 5766 34372 0 65535 0 16 &lt;br /&gt;
6 5894 1604 0 65535 0 17 &lt;br /&gt;
6 6022 34372 0 65535 0 18&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Following command will print the time elapsed every sec for 100 secs&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time | repeat 20 1 {time | binprint}&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Press Cntrl+Return to get the shell prompt back after output is printed.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
time | repeat 20 1 {time | binprint}&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 17 bytes&lt;br /&gt;
�z�^z���&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
6 35963 31502 0 65535 0 251 &lt;br /&gt;
6 36090 64068 0 65535 0 252 &lt;br /&gt;
6 36218 31300 0 65535 0 253 &lt;br /&gt;
6 36346 64068 0 65535 0 254 &lt;br /&gt;
6 36474 31300 0 65535 0 255 &lt;br /&gt;
6 36602 64068 0 65535 0 256 &lt;br /&gt;
6 36730 31300 0 65535 0 257 &lt;br /&gt;
6 36858 64068 0 65535 0 258 &lt;br /&gt;
6 36986 31300 0 65535 0 259 &lt;br /&gt;
6 37114 64068 0 65535 0 260 &lt;br /&gt;
6 37242 31300 0 65535 0 261 &lt;br /&gt;
6 37370 64068 0 65535 0 262 &lt;br /&gt;
6 37498 31300 0 65535 0 263 &lt;br /&gt;
6 37626 64068 0 65535 0 264 &lt;br /&gt;
6 37754 31300 0 65535 0 265 &lt;br /&gt;
6 37882 64068 0 65535 0 266 &lt;br /&gt;
6 38010 31300 0 65535 0 267 &lt;br /&gt;
6 38138 64068 0 65535 0 268 &lt;br /&gt;
6 38266 31300 0 65535 0 269 &lt;br /&gt;
6 38394 64068 0 65535 0 270&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 4 1 {echo hello} &amp;amp;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Press Cntrl+Return to get the shell prompt back after output is printed.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 4 1 {echo hello} &amp;amp;&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 6 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
hello&lt;br /&gt;
hello&lt;br /&gt;
hello&lt;br /&gt;
hello&lt;br /&gt;
&lt;br /&gt;
SEND 1 bytes&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;3) File System Related Commands:&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;ls&amp;#039;&amp;#039;&amp;#039;: list files&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;write &amp;lt;filename&amp;gt;&amp;#039;&amp;#039;&amp;#039;: write to file. To write a string of character to a file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;read &amp;lt;filename&amp;gt; [offset] [block size]&amp;#039;&amp;#039;&amp;#039;: read from a file, with the offset and the block size as options. The offset is the number of characters that must be skipped before reading the file, starting from 0. The block size option separates the output of the read functions in blocks of size block size. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;append &amp;lt;filename&amp;gt;&amp;#039;&amp;#039;&amp;#039;: append to file.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;rm &amp;lt;filename&amp;gt;&amp;#039;&amp;#039;&amp;#039;: remove the file named filename.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell-file.c&amp;#039;&amp;#039;&amp;#039; : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell_file_init()&amp;#039;&amp;#039;&amp;#039;: This function is used to register file system related shell commands with the Contiki Shell.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; Following command echos the text and is written to a file &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;echo howdy? | write msg.txt&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;echo hi! | write hi.txt&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;read msg.txt 0 6 &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;ls&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
echo howdy? | write msg.txt&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 8 bytes&lt;br /&gt;
howdy?&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
echo hi! | write hi.txt&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 4 bytes&lt;br /&gt;
hi!&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
read msg.txt 0 6 &lt;br /&gt;
SEND 18 bytes&lt;br /&gt;
howdy?&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
ls&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
58 &lt;br /&gt;
6 msg.txt&lt;br /&gt;
3 hi.txt&lt;br /&gt;
Total size: 67&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;The following set of commands repeats hey text 4 times every time step and appends the text into a file. Removes all the existing files later &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 4 1 {echo hey | append logfile.txt}&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;read logfile.txt 0 3&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;ls&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;rm msg.txt&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;rm hi.txt&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;rm logfile.txt&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;ls&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 4 1 {echo hey | append logfile.txt}&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
hey&lt;br /&gt;
hey&lt;br /&gt;
hey&lt;br /&gt;
hey&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
read logfile.txt 0 3&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 1 bytes&lt;br /&gt;
hey&lt;br /&gt;
hey&lt;br /&gt;
hey&lt;br /&gt;
hey&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
ls&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
58 &lt;br /&gt;
6 msg.txt&lt;br /&gt;
3 hi.txt&lt;br /&gt;
12 logfile.txt&lt;br /&gt;
Total size: 79&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
rm msg.txt&lt;br /&gt;
SEND 11 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
rm hi.txt&lt;br /&gt;
SEND 10 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
rm logfile.txt&lt;br /&gt;
SEND 15 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
ls&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
58 &lt;br /&gt;
Total size: 58&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------------------------&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;4) Sky mote Related Commands:&amp;#039;&amp;#039;&amp;#039;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;sense&amp;#039;&amp;#039;&amp;#039;: print out sensor data.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;senseconv&amp;#039;&amp;#039;&amp;#039;: convert &amp;#039;sense&amp;#039; data to human readable format.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;nodeid&amp;#039;&amp;#039;&amp;#039;: set node ID, If no node ID was given on the command line, we print out the current nodeid or else we burn the new node ID.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;txpower &amp;lt;power&amp;gt;&amp;#039;&amp;#039;&amp;#039;: change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;rfchannel &amp;lt;channel&amp;gt;&amp;#039;&amp;#039;&amp;#039;: change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;shell-sky.c&amp;#039;&amp;#039;&amp;#039; : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;shell_sky_init()&amp;#039;&amp;#039;&amp;#039;: This function is used to register sky mote related shell commands with the Contiki Shell.&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; This set of commands prints the sensor data in human readable format&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;sense|senseconv&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
sense|senseconv&lt;br /&gt;
SEND 16 bytes&lt;br /&gt;
Light 1 4&lt;br /&gt;
Light 2 13&lt;br /&gt;
Temperature 23.2&lt;br /&gt;
Relative humidity 79 &lt;br /&gt;
RSSI 8&lt;br /&gt;
Voltage 2.5&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; Following command prints out the txpower as 5, which is being set &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Print format: msglen power&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;txpower 5 | binprint&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
txpower 5 | binprint&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 1 bytes&lt;br /&gt;
1 5 &lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; Following command prints out the rfchannel as 15, which is being set &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Print format: msglen channelno&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;rfchannel 15| binprint&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
rfchannel 15| binprint&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
1 15 &lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;Following command outputs the sensor measurements every time step 4 times and appends to a file &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 4 1 {sense | senseconv | append logfile.txt}&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;read logfile.txt 0 36&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 4 1 {sense | senseconv | append logfile.txt}&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
Light 1 5&lt;br /&gt;
Light 2 13&lt;br /&gt;
Temperature 23.2&lt;br /&gt;
Relative humidity 79&lt;br /&gt;
RSSI 11&lt;br /&gt;
Voltage 2.5&lt;br /&gt;
Light 1 4&lt;br /&gt;
Light 2 13&lt;br /&gt;
Temperature 23.2&lt;br /&gt;
Relative humidity 79&lt;br /&gt;
RSSI 8&lt;br /&gt;
Voltage 2.5&lt;br /&gt;
Light 1 4&lt;br /&gt;
Light 2 13&lt;br /&gt;
Temperature 23.2&lt;br /&gt;
Relative humidity 79&lt;br /&gt;
RSSI 2&lt;br /&gt;
Voltage 2.5&lt;br /&gt;
Light 1 4&lt;br /&gt;
Light 2 13&lt;br /&gt;
Temperature 23.2&lt;br /&gt;
Relative humidity 79&lt;br /&gt;
RSSI 0&lt;br /&gt;
Voltage 2.5&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
read logfile.txt 0 36&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
Light 1 5Light 2 13Temperature 23.2&lt;br /&gt;
Relative humidity 79RSSI 11Voltage&lt;br /&gt;
 2.5Light 1 4Light 2 13Temperature 23.2&lt;br /&gt;
Relative humidity 79RSSI 8Volt&lt;br /&gt;
age 2.5Light 1 4Light 2 13Temperatur&lt;br /&gt;
e 23.2Relative humidity 79RSSI 2V&lt;br /&gt;
oltage 2.5Light 1 4Light 2 13Tempera&lt;br /&gt;
ture 23.2Relative humidity 79RSSI&lt;br /&gt;
 0Voltage 2.5&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;set nodeid&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;nodeid 5 &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
nodeid 5&lt;br /&gt;
SEND 9 bytes&lt;br /&gt;
Node ID: 5&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;5) LED Related Commands:&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;blink [num]&amp;#039;&amp;#039;&amp;#039;: blink LEDs ([num] times)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell-blink.c&amp;#039;&amp;#039;&amp;#039; : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell_blink_init()&amp;#039;&amp;#039;&amp;#039;: This function is used to register LED blink related shell commands with the Contiki Shell.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
----------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;LED&amp;#039;s blink 5 times&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;blink 5&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
blink 5&lt;br /&gt;
SEND 8 bytes&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;6) Power Related Commands:&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;power&amp;#039;&amp;#039;&amp;#039;: print power profile&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;energy&amp;#039;&amp;#039;&amp;#039;: print energy profile&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;powerconv&amp;#039;&amp;#039;&amp;#039;: convert power profile to human readable output&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell-power.c&amp;#039;&amp;#039;&amp;#039; : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;shell_power_init()&amp;#039;&amp;#039;&amp;#039;: This function is used to register power related shell commands with the Contiki Shell.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
----------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;Following power commands prints the power profile of sensor node in human readable format &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;power | powerconv&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
power | powerconv&lt;br /&gt;
SEND 18 bytes&lt;br /&gt;
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; Experiment &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;echo change power to 0 | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;txpower 0 | binprint | power | powerconv | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 2 1 {power | powerconv} | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;echo change power to 3 | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;txpower 3 | binprint | power | powerconv | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 2 1 {power | powerconv} | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;echo change power to 10 | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;txpower 10| binprint | power | powerconv | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 2 1 {power | powerconv} | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;echo change power to 31 | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;txpower 31| binprint | power | powerconv | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;repeat 2 1 {power | powerconv} | append powfile.log &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;read powfile.log 0 40 &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
echo change power to 0 | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 4 bytes&lt;br /&gt;
change power to 0&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
txpower 0 | binprint | power | powerconv | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 2 1 {power | powerconv} | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 2 1 {power | powerconv} | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
txpower 3 | binprint | power | powerconv | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 2 1 {power | powerconv} | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
echo change power to 10 | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 5 bytes&lt;br /&gt;
change power to 10&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
txpower 10| binprint | power | powerconv | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 2 1 {power | powerconv} | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
echo change power to 31 | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 5 bytes&lt;br /&gt;
change power to 31&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
txpower 31| binprint | power | powerconv | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
repeat 2 1 {power | powerconv} | append powfile.log&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 12 bytes&lt;br /&gt;
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
read powfile.log 0 40&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 2 bytes&lt;br /&gt;
change power to 0CPU 3% LPM 96% tx 0% rx&lt;br /&gt;
 0% idle tx 0% idle rx 0% tot 2043 uWCPU&lt;br /&gt;
 3% LPM 96% tx 0% rx 0% idle tx 0% idle &lt;br /&gt;
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx&lt;br /&gt;
 0% idle tx 0% idle rx 0% tot 2046 uWCPU&lt;br /&gt;
 3% LPM 96% tx 0% rx 0% idle tx 0% idle &lt;br /&gt;
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx&lt;br /&gt;
 0% idle tx 0% idle rx 0% tot 2099 uWcha&lt;br /&gt;
nge power to 10CPU 3% LPM 96% tx 0% rx 0&lt;br /&gt;
% idle tx 0% idle rx 0% tot 2148 uWCPU 3&lt;br /&gt;
% LPM 96% tx 0% rx 0% idle tx 0% idle rx&lt;br /&gt;
 0% tot 2099 uWchange power to 31CPU 3% &lt;br /&gt;
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0&lt;br /&gt;
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% &lt;br /&gt;
idle tx 0% idle rx 0% tot 2086 uW&lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
----------------------------&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Other Commands&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;1)&amp;#039;&amp;#039;&amp;#039;ps&amp;#039;&amp;#039;&amp;#039;: this command will list all running processes. By default, the following processes are executed: Shell server, Shell, Contiki serial shell, Serial driver, CC2420 driver, ctimer process, Sensors, Event timer.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;2)&amp;#039;&amp;#039;&amp;#039;kill &amp;lt;command&amp;gt;&amp;#039;&amp;#039;&amp;#039;: stop a specific command. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;3)&amp;#039;&amp;#039;&amp;#039;killall&amp;#039;&amp;#039;&amp;#039;: stop all running commands.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;4)&amp;#039;&amp;#039;&amp;#039;reboot&amp;#039;&amp;#039;&amp;#039;: this command reboots the mote. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;5)&amp;#039;&amp;#039;&amp;#039;collect-view-data&amp;#039;&amp;#039;&amp;#039;: provides sensor data, power consumption, network stats for the sky mote. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;6)&amp;#039;&amp;#039;&amp;#039;powertrace&amp;#039;&amp;#039;&amp;#039;: this gives the power profile of the mote. &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;This command lists all the running processes &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;ps&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
ps&lt;br /&gt;
SEND 3 bytes&lt;br /&gt;
Processes:&lt;br /&gt;
ps&lt;br /&gt;
Shell server&lt;br /&gt;
Shell&lt;br /&gt;
Contiki serial shell&lt;br /&gt;
Serial driver&lt;br /&gt;
CC2420 driver&lt;br /&gt;
Sensors&lt;br /&gt;
Ctimer process&lt;br /&gt;
Event timer&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; This command reboots the shell &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time|binprint&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;reboot&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; After rebooting print time, to see the restart of the mote time &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;time|binprint&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
time | binprint&lt;br /&gt;
SEND 16 bytes&lt;br /&gt;
6 34454 38458 0 65535 0 269 &lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
reboot&lt;br /&gt;
SEND 7 bytes&lt;br /&gt;
Rebooting the node in four seconds...&lt;br /&gt;
Rime started with address 5.0&lt;br /&gt;
MAC 05:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 5.&lt;br /&gt;
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26&lt;br /&gt;
Starting &amp;#039;Sky Contiki shell&amp;#039;&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
time | binprint&lt;br /&gt;
SEND 16 bytes&lt;br /&gt;
6 2736 45115 0 65535 0 21 &lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
---------------------------&lt;br /&gt;
&amp;lt;p&amp;gt; This command prints out the collect view data for the mote &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; Format of the print: [len][clock][timesynch_time][cpu][lpm][transmit][listen][parent][parent_etx][current_rtmetric][num_neighbors][beacon_interval][BATTERY_VOLTAGE_SENSOR][BATTERY_INDICATOR][LIGHT1_SENSOR][LIGHT2_SENSOR][TEMP_SENSOR][HUMIDITY_SENSOR][RSSI_SENSOR][ETX1_SENSOR][ETX2_SENSOR][ETX3_SENSOR][ETX4_SENSOR]&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;collect-view-data | binprint&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
collect-view-data | binprint&lt;br /&gt;
SEND 20 bytes&lt;br /&gt;
SEND 9 bytes&lt;br /&gt;
22 26024 0 1672 50278 0 269 0 128 0 6 0 2075 1 6 3 65535 65535 0 0 0 0 &lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
&amp;lt;p&amp;gt;This commands prints the power profile of the mote. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;powertrace&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
powertrace&lt;br /&gt;
SEND 11 bytes&lt;br /&gt;
 16188 P 5.0 0 130619 4009338 0 23333 0 23333 130619 4009338 0 23333 0 23333 (radio 0.56% / 0.56% tx 0.00% / 0.00% listen 0.56% / 0.56%)&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to write your own Shell commands ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in &amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in &amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Shell.c has all the basic code blocks to build your own shell command. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;Example skeleton of code in shell-your-cmdfile.c to create your own shell command&amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS(multiplyNums_process, &amp;quot;Multiply two numbers&amp;quot;);&lt;br /&gt;
SHELL_COMMAND(mulNum_command, &amp;quot;mn&amp;quot;, &amp;quot;mn: Multiply two numbers&amp;quot;, &amp;amp;multiplyNums_process);&lt;br /&gt;
/* --------------------------------- */&lt;br /&gt;
PROCESS_THREAD(multiplyNums_process, ev, data) {&lt;br /&gt;
PROCESS_BEGIN();&lt;br /&gt;
  // ...&lt;br /&gt;
  // ...&lt;br /&gt;
PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
.....&lt;br /&gt;
.....&lt;br /&gt;
shell_register_command(&amp;amp;mulNum_command);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== An example project for creating your own Shell with your commands ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following two files in this path &amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039; &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;1)shell-try-example.c&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;2)shell-try-example.h&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Source code: shell-try-example.c&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039; Two new shell commands are created&amp;#039;&amp;#039;&amp;#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;#039;&amp;#039;&amp;#039;echo2&amp;#039;&amp;#039;&amp;#039;: This shell command echoes the text twice back onto the shell prompt &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;#039;&amp;#039;&amp;#039;blinkAllOnce&amp;#039;&amp;#039;&amp;#039;: This shell command is used to make each of the LED&amp;#039;s (Red,Blu,Green) blink once each. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() &amp;lt;/p&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang =&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * \file   shell-try-example.c&lt;br /&gt;
 *         try Example Contiki shell command&lt;br /&gt;
 * \author&lt;br /&gt;
 *         Abhilash Hegde &amp;lt;hegdea@usc.edu&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;shell.h&amp;quot;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;quot;dev/leds.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS(shell_echo2_process, &amp;quot;echo2&amp;quot;);&lt;br /&gt;
SHELL_COMMAND(echo2_command,&lt;br /&gt;
	      &amp;quot;echo2&amp;quot;,&lt;br /&gt;
	      &amp;quot;echo2: echoes back entered text twice&amp;quot;,&lt;br /&gt;
	      &amp;amp;shell_echo2_process);&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS_THREAD(shell_echo2_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
  &lt;br /&gt;
  /* Echo the data back twice */&lt;br /&gt;
  shell_output(&amp;amp;echo2_command, data, (int)strlen(data), data, (int)strlen(data));&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS(shell_blinkAllOnce_process, &amp;quot;blinkAllOnce&amp;quot;);&lt;br /&gt;
SHELL_COMMAND(blinkAllOnce_command,&lt;br /&gt;
	      &amp;quot;blinkAllOnce&amp;quot;,&lt;br /&gt;
	      &amp;quot;blinkAllOnce: blink all LEDs one time&amp;quot;,&lt;br /&gt;
	      &amp;amp;shell_blinkAllOnce_process);&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)&lt;br /&gt;
{  &lt;br /&gt;
  static struct etimer etimer;&lt;br /&gt;
&lt;br /&gt;
  PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  etimer_set(&amp;amp;etimer, CLOCK_SECOND/2);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;etimer));&lt;br /&gt;
  leds_on(LEDS_RED);&lt;br /&gt;
&lt;br /&gt;
  etimer_reset(&amp;amp;etimer);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;etimer));&lt;br /&gt;
  leds_off(LEDS_RED);&lt;br /&gt;
&lt;br /&gt;
  etimer_reset(&amp;amp;etimer);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;etimer));&lt;br /&gt;
  leds_on(LEDS_GREEN);&lt;br /&gt;
&lt;br /&gt;
  etimer_reset(&amp;amp;etimer);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;etimer));&lt;br /&gt;
  leds_off(LEDS_GREEN);&lt;br /&gt;
&lt;br /&gt;
  etimer_reset(&amp;amp;etimer);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;etimer));&lt;br /&gt;
  leds_on(LEDS_BLUE);&lt;br /&gt;
&lt;br /&gt;
  etimer_reset(&amp;amp;etimer);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;etimer));&lt;br /&gt;
  leds_off(LEDS_BLUE);&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
void&lt;br /&gt;
shell_try_init(void)&lt;br /&gt;
{&lt;br /&gt;
  shell_register_command(&amp;amp;echo2_command);&lt;br /&gt;
  shell_register_command(&amp;amp;blinkAllOnce_command);&lt;br /&gt;
}&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Header: shell-try-example.h&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang =&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * \file   shell-try-example.h&lt;br /&gt;
 *         try Example Contiki shell command&lt;br /&gt;
 * \author&lt;br /&gt;
 *         Abhilash Hegde &amp;lt;hegdea@usc.edu&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#ifndef __SHELL_TRY_H__&lt;br /&gt;
#define __SHELL_TRY_H__&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;shell.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
void shell_try_init(void);&lt;br /&gt;
&lt;br /&gt;
#endif /* __SHELL_TRY_H__ */&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Make the changes in Makefile.shell located in &amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039; to include shell-try-example.c in shell_src &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;shell_src = shell.c shell-reboot.c \&lt;br /&gt;
            shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \&lt;br /&gt;
            shell-blink.c shell-text.c shell-try-example.c shell-time.c \&lt;br /&gt;
            shell-file.c shell-netfile.c shell-run.c \&lt;br /&gt;
            shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \&lt;br /&gt;
            shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \&lt;br /&gt;
            shell-wget.c shell-httpd.c shell-irc.c \&lt;br /&gt;
            shell-checkpoint.c shell-power.c \&lt;br /&gt;
            shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \&lt;br /&gt;
            shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \&lt;br /&gt;
            shell-rime-unicast.c \&lt;br /&gt;
            shell-base64.c \&lt;br /&gt;
            shell-netperf.c shell-memdebug.c \&lt;br /&gt;
	    shell-powertrace.c shell-collect-view.c shell-crc.c&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Now create a new project mySky-shell under ~/contiki-2.7/examples &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Add this source file mySky-shell.c in the project &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang =&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2008, Swedish Institute of Computer Science.&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 * 3. Neither the name of the Institute nor the names of its contributors&lt;br /&gt;
 *    may be used to endorse or promote products derived from this software&lt;br /&gt;
 *    without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS&amp;#039;&amp;#039; AND&lt;br /&gt;
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE&lt;br /&gt;
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE&lt;br /&gt;
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&lt;br /&gt;
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS&lt;br /&gt;
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;br /&gt;
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT&lt;br /&gt;
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY&lt;br /&gt;
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;br /&gt;
 * SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 * This file is part of the Contiki operating system.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * \file&lt;br /&gt;
 *         Tmote Sky-specific My Contiki shell &lt;br /&gt;
 *         Base code reference: sky-shell.c&lt;br /&gt;
 * \author&lt;br /&gt;
 *         Abhilash Hegde &amp;lt;hegdea@usc.edu&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;shell.h&amp;quot;&lt;br /&gt;
#include &amp;quot;serial-shell.h&amp;quot;&lt;br /&gt;
#include &amp;quot;collect-view.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
//#include &amp;quot;net/rime.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS(mysky_shell_process, &amp;quot;My Sky Contiki shell&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;mysky_shell_process);&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
#define WITH_PERIODIC_DEBUG 0&lt;br /&gt;
#if WITH_PERIODIC_DEBUG&lt;br /&gt;
static struct ctimer debug_timer;&lt;br /&gt;
static void&lt;br /&gt;
periodic_debug(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  ctimer_set(&amp;amp;debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);&lt;br /&gt;
  collect_print_stats();&lt;br /&gt;
}&lt;br /&gt;
#endif /* WITH_PERIODIC_DEBUG */&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
PROCESS_THREAD(mysky_shell_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
#if WITH_PERIODIC_DEBUG&lt;br /&gt;
  ctimer_set(&amp;amp;debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);&lt;br /&gt;
#endif /* WITH_PERIODIC_DEBUG */&lt;br /&gt;
&lt;br /&gt;
  serial_shell_init();&lt;br /&gt;
  shell_blink_init();&lt;br /&gt;
  shell_file_init();&lt;br /&gt;
&lt;br /&gt;
  shell_ps_init();&lt;br /&gt;
  shell_reboot_init();&lt;br /&gt;
&lt;br /&gt;
  shell_sky_init();&lt;br /&gt;
  shell_power_init();&lt;br /&gt;
  shell_powertrace_init();&lt;br /&gt;
&lt;br /&gt;
  shell_text_init();&lt;br /&gt;
  shell_time_init();&lt;br /&gt;
&lt;br /&gt;
  shell_collect_view_init();&lt;br /&gt;
  shell_try_init();&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
/*---------------------------------------------------------------------------*/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Add this Makefile in the project&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang =&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
CONTIKI_PROJECT = mySky-shell&lt;br /&gt;
all: $(CONTIKI_PROJECT)&lt;br /&gt;
&lt;br /&gt;
APPS = serial-shell powertrace collect-view&lt;br /&gt;
CONTIKI = ../..&lt;br /&gt;
&lt;br /&gt;
include $(CONTIKI)/Makefile.include&lt;br /&gt;
-include /home/user/nes/testbed-scripts/Makefile.include&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Add another Makefile.target to the project &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang =&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
TARGET = sky&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;compile the project&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;After successful compilation, you will see the following messages on the command prompt&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget&lt;br /&gt;
msp430-objcopy mySky-shell.sky -O ihex mySky-shell.ihex&lt;br /&gt;
make IHEXFILE=mySky-shell.ihex sky-reset sky-upload&lt;br /&gt;
make[1]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell&amp;#039;&lt;br /&gt;
make -k -j 20 sky-reset-sequence&lt;br /&gt;
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell&amp;#039;&lt;br /&gt;
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Use -h for help&lt;br /&gt;
Reset device ...&lt;br /&gt;
Done&lt;br /&gt;
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell&amp;#039;&lt;br /&gt;
make -j 20 sky-upload-sequence&lt;br /&gt;
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell&amp;#039;&lt;br /&gt;
+++++ Erasing /dev/ttyUSB0&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Use -h for help&lt;br /&gt;
Mass Erase...&lt;br /&gt;
Transmit default password ...&lt;br /&gt;
+++++ Programming /dev/ttyUSB0&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Invoking BSL...&lt;br /&gt;
Transmit default password ...&lt;br /&gt;
Current bootstrap loader version: 1.61 (Device ID: f16c)&lt;br /&gt;
Changing baudrate to 38400 ...&lt;br /&gt;
Program ...&lt;br /&gt;
46214 bytes programmed.&lt;br /&gt;
+++++ Resetting /dev/ttyUSB0&lt;br /&gt;
MSP430 Bootstrap Loader Version: 1.39-telos-7&lt;br /&gt;
Use -h for help&lt;br /&gt;
Reset device ...&lt;br /&gt;
Done&lt;br /&gt;
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell&amp;#039;&lt;br /&gt;
make[1]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell&amp;#039;&lt;br /&gt;
saving Makefile.target&lt;br /&gt;
rm mySky-shell.ihex&lt;br /&gt;
user@instant-contiki:~/contiki-2.7/examples/mySky-shell$&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Login in to the mote using the following command&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;make login&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;After logging into the mote, you will see the shell prompt as seen below&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make login&lt;br /&gt;
using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
connecting to /dev/ttyUSB0 (115200) [OK]&lt;br /&gt;
��{/#��3�#���#&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Hit Enter, too see shell prompt and Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
help&lt;br /&gt;
SEND 5 bytes&lt;br /&gt;
Available commands:&lt;br /&gt;
?: shows this help&lt;br /&gt;
append &amp;lt;filename&amp;gt;: append to file&lt;br /&gt;
binprint: print binary data in decimal format&lt;br /&gt;
blink [num]: blink LEDs ([num] times)&lt;br /&gt;
blinkAllOnce: blink all LEDs one time&lt;br /&gt;
collect-view-data: sensor data, power consumption, network stats&lt;br /&gt;
echo &amp;lt;text&amp;gt;: print &amp;lt;text&amp;gt;&lt;br /&gt;
echo2: echoes back entered text twice&lt;br /&gt;
energy: print energy profile&lt;br /&gt;
exit: exit shell&lt;br /&gt;
hd: print binary data in hexadecimal format&lt;br /&gt;
help: shows this help&lt;br /&gt;
kill &amp;lt;command&amp;gt;: stop a specific command&lt;br /&gt;
killall: stop all running commands&lt;br /&gt;
ls: list files&lt;br /&gt;
nodeid: set node ID&lt;br /&gt;
null: discard input&lt;br /&gt;
power: print power profile&lt;br /&gt;
powerconv: convert power profile to human readable output&lt;br /&gt;
powertrace [interval]: turn powertracing on or off, with reporting interval &amp;lt;interval&amp;gt;&lt;br /&gt;
ps: list all running processes&lt;br /&gt;
quit: exit shell&lt;br /&gt;
randwait &amp;lt;maxtime&amp;gt; &amp;lt;command&amp;gt;: wait for a random time before running a command&lt;br /&gt;
read &amp;lt;filename&amp;gt; [offset] [block size]: read from a file, with the offset and the block size as options&lt;br /&gt;
reboot: reboot the system&lt;br /&gt;
repeat &amp;lt;num&amp;gt; &amp;lt;time&amp;gt; &amp;lt;command&amp;gt;: run a command every &amp;lt;time&amp;gt; seconds&lt;br /&gt;
rfchannel &amp;lt;channel&amp;gt;: change CC2420 radio channel (11 - 26)&lt;br /&gt;
rm &amp;lt;filename&amp;gt;: remove the file named filename&lt;br /&gt;
sense: print out sensor data&lt;br /&gt;
senseconv: convert &amp;#039;sense&amp;#039; data to human readable format&lt;br /&gt;
size: print the size of the input&lt;br /&gt;
time [seconds]: output time in binary format, or set time in seconds since 1970&lt;br /&gt;
timestamp: prepend a timestamp to data&lt;br /&gt;
txpower &amp;lt;power&amp;gt;: change CC2420 transmission power (0 - 31)&lt;br /&gt;
write &amp;lt;filename&amp;gt;: write to file&lt;br /&gt;
5.0: Contiki&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Lets execute the two new shell commands added to the shell&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
echo2 Trojan&lt;br /&gt;
SEND 13 bytes&lt;br /&gt;
TrojanTrojan&lt;br /&gt;
5.0: Contiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;blinkAllOnce command will blink all LED&amp;#039;s exactly once one by one&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;5.0: Contiki&amp;gt; &lt;br /&gt;
blinkAllOnce&lt;br /&gt;
SEND 13 bytes&lt;br /&gt;
5.0: Contiki&amp;gt; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Voila! There it is blinking of LEDs, Notice it ?&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Issues you might face ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; You may run out of memory on the mote, when more than possible shell_xx_init()&amp;#039;s are used in your firmware image of Contiki shell. This will result in compilation failure. By Trial and error figure what would be a reasonable set of shell_xx_init()&amp;#039;s that can be registered as part of your Contiki Shell.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;During the run of contiki serial shell, due to invalid data or commands, garbage values might be displayed in the shell. In such cases either use the reboot command to reboot the serial shell for Contiki or Build the shell again and upload it on the mote to solve the issue.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/&lt;br /&gt;
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos&lt;br /&gt;
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a01796.html&lt;br /&gt;
&lt;br /&gt;
== Feedback ==&lt;br /&gt;
&amp;lt;p&amp;gt;Please post your feedback here for any further improvements to tutorials.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Comments Welcome :)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Hope you had a great time learning. &amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

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

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1749</id>
		<title>CFS-Coffee</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1749"/>
				<updated>2016-07-29T22:01:03Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==Permanent Storage of Contiki on Tmote Sky (CFS-Coffee) ==&lt;br /&gt;
&lt;br /&gt;
Contiki provides File System to achieve the goal of permanent storage. The Contiki File System(CFS) works as a Virtual File System and provides some interfaces for different file systems. CFS-POSIX and Coffee are two with full functionalities. CFS-POSIX is used in Contiki platforms that runs in native mode. Coffee, on the other hand, is primarily aimed at sensor devices that equiped with Flash Memories or EEPROM.&lt;br /&gt;
&lt;br /&gt;
==The CFS Programming Interface==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00128.html&lt;br /&gt;
&lt;br /&gt;
==Introduction to Coffee==&lt;br /&gt;
&lt;br /&gt;
Coffee is a fully functional file system designed specifically for the characteristics of flash memories and EEPROM. Coffee is usually used in sensor devices with flash (e.g Tmote Sky), so two principles are pretty important. First, the metadata stored in RAM for each file should be small because sensor devices have very limited RAM space. Second, bits in flash memories can be toggled from 1 to 0, but not toggled back from 0 to 1 without doing an expensive erase. Thus, when modifying a file, Coffee creates an invisible micro log which is linked to the original file. The micro log contains the lastest data of the file. For user, the micro log and the original file is just one logical file, as if they modify the original file. When the micro log eventually fills up, Coffee transparently merges the content of the original file and the micro log into a new file, and deletes the two former files. &lt;br /&gt;
&lt;br /&gt;
Coffee has a flat directory structure. It only has the root directory. Thus, cfs_opendir() only accept “/” or “.” as the second argument. When removing a file from a Coffee, there are two steps. First, external user calls cfs_remove(). The file mentioned by user will be marked as obsolete. Obsolete files cannot be seen by external users. Coffee will actually delete files only when a new file reservation request cannot be granted.&lt;br /&gt;
&lt;br /&gt;
The implementation of Coffee in core/cfs/cfs-coffee.c is totally platform independent. The specific configuration of Coffee for different platforms is written in csf-coffee-arch.c. We can see many csf-coffee-arch.c files in plarform/./csf-coffee-arch.c, e.g plarform/z1/csf-coffee-arch.c, plarform/esb/csf-coffee-arch.c, plarform/sky/csf-coffee-arch.c. When we decide the platform, such as TARGET=sky, we compile plarform/sky/csf-coffee-arch.c and ignore all other csf-coffee-arch.c files. Macro definitions in plarform/sky/csf-coffee-arch.c configure the details of coffee in Sky Mote. Macro definition contains parameters like COFFEE_SECTOR_SIZE, COFFEE_PAGE_SIZE, COFFEE_FD_SET_SIZE, COFFEE_MICRO_LOGS and so on. Also, it defines COFFEE_WRITE, COFFEE_READ and COFFEE_ERASE to point to the device drivers I/O function. &lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Interface Extensions==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00122.html&lt;br /&gt;
&lt;br /&gt;
cfs_coffee_format() may take a few second because all sectors must be erased.  cfs_coffee_reserve() and int cfs_coffee_configure_log() can optimize Coffee’s handling of the file.&lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Summary==&lt;br /&gt;
&lt;br /&gt;
Here is an example of how everything works. Suppose we want to run Contiki on Sky Mote. First make sure TARGET=sky. Then every file about sky is compiled and you can also see a new folder which is created called sky_obj. Inside contains everything you need to run on Sky Mote. Suppose you want to use Coffee as the File System. Write cfs_coffee_format() before the first time you try to operate on Coffee. This function notice the system that you want to use Coffee and the system will do some formatting. Let’s say then you want to read something from an existing file with the function call cfs_read(). This function is defined in core/cfs/cfs.h. Because we make use of Coffee, the implementation of this function will be in core/cfs/cfs-coffee.c. The function cfs_read() actually calls the macro definition COFFEE_READ(). The definition of COFFEE_READ() is in cfs-coffee-arch.c. Since we make TARGET=sky, the one that was compiled and used by us is platform/sky/cfs-coffee-arch.c. This file defines COFFEE_READ() to point to Sky Mote drivers I/O function. Finally, the external users’ cfs_read() gets to the Sky Driver I/O function.&lt;br /&gt;
&lt;br /&gt;
==An Example of Running Coffee on Tmote Sky==&lt;br /&gt;
&lt;br /&gt;
This example shows the basic way to open, read, write and append files in Coffee. The platform we choose here is Tmote Sky.&lt;br /&gt;
First, open an example provided by Contiki (/home/user/contiki-2.7/example/sky/example- coffee.c).&lt;br /&gt;
Here, it defines two test functions:&lt;br /&gt;
  static int file_test(const char *filename, char *msg) &lt;br /&gt;
opens a file named FILENAME with CFS_WRITE | CFS_APPEND | CFS_READ. It appends the opening file with records and prints out everything in the file.&lt;br /&gt;
  static int dir_test(void) &lt;br /&gt;
opens the root directory and prints out all entries of root.&lt;br /&gt;
The Process calls file_test() twice and dir_test() once. Then the process ends.&lt;br /&gt;
Now, we do some modifications based on this example. First we add a function static int read_test(void). The implementation of this function is shown as below:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  static int&lt;br /&gt;
  read_test(void)&lt;br /&gt;
  {&lt;br /&gt;
	  struct cfs_dir dir;&lt;br /&gt;
	  struct cfs_dirent dirent;&lt;br /&gt;
	  int fd;&lt;br /&gt;
	  int r;&lt;br /&gt;
	  struct record {&lt;br /&gt;
    		  char message[16];&lt;br /&gt;
    		  uint8_t sequence;&lt;br /&gt;
  	  } record;&lt;br /&gt;
	  static int i = 0;&lt;br /&gt;
	  if (cfs_opendir(&amp;amp;dir, &amp;quot;/&amp;quot;) != 0)&lt;br /&gt;
	  {&lt;br /&gt;
		printf(&amp;quot;Fail to open the root directory\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	while(cfs_readdir(&amp;amp;dir, &amp;amp;dirent) == 0)&lt;br /&gt;
	{&lt;br /&gt;
		i ++;&lt;br /&gt;
		printf(&amp;quot;\nFile name: %s\n&amp;quot;, dirent.name);&lt;br /&gt;
		if ((fd =cfs_open(dirent.name, CFS_READ)) != -1)&lt;br /&gt;
		{&lt;br /&gt;
			cfs_seek(fd, 0, CFS_SEEK_SET);&lt;br /&gt;
			for(;;) &lt;br /&gt;
			{&lt;br /&gt;
    				r = cfs_read(fd, &amp;amp;record, sizeof(record));&lt;br /&gt;
    				if(r == 0) {&lt;br /&gt;
      					break;&lt;br /&gt;
    				} else if(r &amp;gt; sizeof(record)) {&lt;br /&gt;
      					printf(&amp;quot;failed to read %d bytes from %s, got %d\n&amp;quot;,(int)sizeof(record), dirent.name, r);&lt;br /&gt;
      					cfs_close(fd);&lt;br /&gt;
      					return -1;&lt;br /&gt;
    				}&lt;br /&gt;
&lt;br /&gt;
    				printf(&amp;quot;Read message \&amp;quot;%s\&amp;quot;, sequence %u\n&amp;quot;,record.message, record.sequence);&lt;br /&gt;
  			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (i == 0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nNo file exists.\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return 1;&lt;br /&gt;
	}&lt;br /&gt;
		&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function of read_test() is quite simple. It opens the root file system and reads all the data in the file system. In the while() loop, it reads an entry of a file. Then it makes use of the entry to open the file and read all the data out.&lt;br /&gt;
&lt;br /&gt;
Also, in the process, we add an etimer at the beginning. The process can only move on either when the timer expired or someone push a button. If the timer expire, the process will run cfs_coffee_format(), which will set all the flash to 1. Otherwise, we don’t do this. Then we call read_test(), which read all the data in the file system. After that, we check whether there are files exist in the system. If there is, we give up wirting. Otherwise, we create two files and write some data in.&lt;br /&gt;
The process then looks like:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_coffee_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
	static int flag = 0;&lt;br /&gt;
	button_sensor.configure(SENSORS_ACTIVE, 1);&lt;br /&gt;
&lt;br /&gt;
	static struct etimer ak;&lt;br /&gt;
	etimer_set(&amp;amp;ak, CLOCK_SECOND * 6);&lt;br /&gt;
	&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER || ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor);&lt;br /&gt;
&lt;br /&gt;
	if (ev == PROCESS_EVENT_TIMER)&lt;br /&gt;
		cfs_coffee_format();	&lt;br /&gt;
&lt;br /&gt;
	if ((flag = read_test()) == -1)&lt;br /&gt;
		PROCESS_EXIT();&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	static struct etimer et;&lt;br /&gt;
	etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);&lt;br /&gt;
&lt;br /&gt;
	if (flag == 1)&lt;br /&gt;
		printf(&amp;quot;\nData exists...No written again...\n&amp;quot;);&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nData begin to write...\n&amp;quot;);&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The first test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 1 failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The second test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 2 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(file_test(FILENAME_2, &amp;quot;The third test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 3 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(dir_test() == 0) {&lt;br /&gt;
    			printf(&amp;quot;dir test failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, connect your mote to your PC’s USB port and change directory. &lt;br /&gt;
  cd contiki-2.7/examples/sky &lt;br /&gt;
&lt;br /&gt;
Compile this Coffee example to Sky Mote.&lt;br /&gt;
  sudo make TARGET=sky example-coffee.upload login&lt;br /&gt;
&lt;br /&gt;
Once login, wait for 6 seconds patiently for the first time out.If it success, we should see terminal has the output like this:&lt;br /&gt;
Here you can see, we create two files and write some data in. Then, disconnect your mote and do whatever you want. Maybe one day later, you come back. Now it’s the time to keep moving. &lt;br /&gt;
Welcome back. Now connect your mote with USB port again and do:&lt;br /&gt;
  sudo make TARGET=sky login&lt;br /&gt;
You are in the process again and please follow the following two steps:&lt;br /&gt;
1. push “RESET” button;&lt;br /&gt;
2. push “USER” button within 6 seconds.&lt;br /&gt;
Now, the program will not call cfs_coffee_format(). If succeed, you will see: &lt;br /&gt;
As you can see, we read out all the data that you wrote in one day ago. Everything is right there without any change.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1748</id>
		<title>CFS-Coffee</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1748"/>
				<updated>2016-07-29T21:58:37Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Permanent Storage of Contiki on Tmote Sky (CFS-Coffee) ==&lt;br /&gt;
&lt;br /&gt;
Contiki provides File System to achieve the goal of permanent storage. The Contiki File System(CFS) works as a Virtual File System and provides some interfaces for different file systems. CFS-POSIX and Coffee are two with full functionalities. CFS-POSIX is used in Contiki platforms that runs in native mode. Coffee, on the other hand, is primarily aimed at sensor devices that equiped with Flash Memories or EEPROM.&lt;br /&gt;
&lt;br /&gt;
==The CFS Programming Interface==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00128.html&lt;br /&gt;
&lt;br /&gt;
==Introduction to Coffee==&lt;br /&gt;
&lt;br /&gt;
Coffee is a fully functional file system designed specifically for the characteristics of flash memories and EEPROM. Coffee is usually used in sensor devices with flash (e.g Tmote Sky), so two principles are pretty important. First, the metadata stored in RAM for each file should be small because sensor devices have very limited RAM space. Second, bits in flash memories can be toggled from 1 to 0, but not toggled back from 0 to 1 without doing an expensive erase. Thus, when modifying a file, Coffee creates an invisible micro log which is linked to the original file. The micro log contains the lastest data of the file. For user, the micro log and the original file is just one logical file, as if they modify the original file. When the micro log eventually fills up, Coffee transparently merges the content of the original file and the micro log into a new file, and deletes the two former files. &lt;br /&gt;
&lt;br /&gt;
Coffee has a flat directory structure. It only has the root directory. Thus, cfs_opendir() only accept “/” or “.” as the second argument. When removing a file from a Coffee, there are two steps. First, external user calls cfs_remove(). The file mentioned by user will be marked as obsolete. Obsolete files cannot be seen by external users. Coffee will actually delete files only when a new file reservation request cannot be granted.&lt;br /&gt;
&lt;br /&gt;
The implementation of Coffee in core/cfs/cfs-coffee.c is totally platform independent. The specific configuration of Coffee for different platforms is written in csf-coffee-arch.c. We can see many csf-coffee-arch.c files in plarform/./csf-coffee-arch.c, e.g plarform/z1/csf-coffee-arch.c, plarform/esb/csf-coffee-arch.c, plarform/sky/csf-coffee-arch.c. When we decide the platform, such as TARGET=sky, we compile plarform/sky/csf-coffee-arch.c and ignore all other csf-coffee-arch.c files. Macro definitions in plarform/sky/csf-coffee-arch.c configure the details of coffee in Sky Mote. Macro definition contains parameters like COFFEE_SECTOR_SIZE, COFFEE_PAGE_SIZE, COFFEE_FD_SET_SIZE, COFFEE_MICRO_LOGS and so on. Also, it defines COFFEE_WRITE, COFFEE_READ and COFFEE_ERASE to point to the device drivers I/O function. &lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Interface Extensions==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00122.html&lt;br /&gt;
&lt;br /&gt;
cfs_coffee_format() may take a few second because all sectors must be erased.  cfs_coffee_reserve() and int cfs_coffee_configure_log() can optimize Coffee’s handling of the file.&lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Summary==&lt;br /&gt;
&lt;br /&gt;
Here is an example of how everything works. Suppose we want to run Contiki on Sky Mote. First make sure TARGET=sky. Then every file about sky is compiled and you can also see a new folder which is created called sky_obj. Inside contains everything you need to run on Sky Mote. Suppose you want to use Coffee as the File System. Write cfs_coffee_format() before the first time you try to operate on Coffee. This function notice the system that you want to use Coffee and the system will do some formatting. Let’s say then you want to read something from an existing file with the function call cfs_read(). This function is defined in core/cfs/cfs.h. Because we make use of Coffee, the implementation of this function will be in core/cfs/cfs-coffee.c. The function cfs_read() actually calls the macro definition COFFEE_READ(). The definition of COFFEE_READ() is in cfs-coffee-arch.c. Since we make TARGET=sky, the one that was compiled and used by us is platform/sky/cfs-coffee-arch.c. This file defines COFFEE_READ() to point to Sky Mote drivers I/O function. Finally, the external users’ cfs_read() gets to the Sky Driver I/O function.&lt;br /&gt;
&lt;br /&gt;
==An Example of Running Coffee on Tmote Sky==&lt;br /&gt;
&lt;br /&gt;
This example shows the basic way to open, read, write and append files in Coffee. The platform we choose here is Tmote Sky.&lt;br /&gt;
First, open an example provided by Contiki (/home/user/contiki-2.7/example/sky/example- coffee.c).&lt;br /&gt;
Here, it defines two test functions:&lt;br /&gt;
  static int file_test(const char *filename, char *msg) &lt;br /&gt;
opens a file named FILENAME with CFS_WRITE | CFS_APPEND | CFS_READ. It appends the opening file with records and prints out everything in the file.&lt;br /&gt;
  static int dir_test(void) &lt;br /&gt;
opens the root directory and prints out all entries of root.&lt;br /&gt;
The Process calls file_test() twice and dir_test() once. Then the process ends.&lt;br /&gt;
Now, we do some modifications based on this example. First we add a function static int read_test(void). The implementation of this function is shown as below:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  static int&lt;br /&gt;
  read_test(void)&lt;br /&gt;
  {&lt;br /&gt;
	  struct cfs_dir dir;&lt;br /&gt;
	  struct cfs_dirent dirent;&lt;br /&gt;
	  int fd;&lt;br /&gt;
	  int r;&lt;br /&gt;
	  struct record {&lt;br /&gt;
    		  char message[16];&lt;br /&gt;
    		  uint8_t sequence;&lt;br /&gt;
  	  } record;&lt;br /&gt;
	  static int i = 0;&lt;br /&gt;
	  if (cfs_opendir(&amp;amp;dir, &amp;quot;/&amp;quot;) != 0)&lt;br /&gt;
	  {&lt;br /&gt;
		printf(&amp;quot;Fail to open the root directory\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	while(cfs_readdir(&amp;amp;dir, &amp;amp;dirent) == 0)&lt;br /&gt;
	{&lt;br /&gt;
		i ++;&lt;br /&gt;
		printf(&amp;quot;\nFile name: %s\n&amp;quot;, dirent.name);&lt;br /&gt;
		if ((fd =cfs_open(dirent.name, CFS_READ)) != -1)&lt;br /&gt;
		{&lt;br /&gt;
			cfs_seek(fd, 0, CFS_SEEK_SET);&lt;br /&gt;
			for(;;) &lt;br /&gt;
			{&lt;br /&gt;
    				r = cfs_read(fd, &amp;amp;record, sizeof(record));&lt;br /&gt;
    				if(r == 0) {&lt;br /&gt;
      					break;&lt;br /&gt;
    				} else if(r &amp;gt; sizeof(record)) {&lt;br /&gt;
      					printf(&amp;quot;failed to read %d bytes from %s, got %d\n&amp;quot;,(int)sizeof(record), dirent.name, r);&lt;br /&gt;
      					cfs_close(fd);&lt;br /&gt;
      					return -1;&lt;br /&gt;
    				}&lt;br /&gt;
&lt;br /&gt;
    				printf(&amp;quot;Read message \&amp;quot;%s\&amp;quot;, sequence %u\n&amp;quot;,record.message, record.sequence);&lt;br /&gt;
  			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (i == 0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nNo file exists.\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return 1;&lt;br /&gt;
	}&lt;br /&gt;
		&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function of read_test() is quite simple. It opens the root file system and reads all the data in the file system. In the while() loop, it reads an entry of a file. Then it makes use of the entry to open the file and read all the data out.&lt;br /&gt;
&lt;br /&gt;
Also, in the process, we add an etimer at the beginning. The process can only move on either when the timer expired or someone push a button. If the timer expire, the process will run cfs_coffee_format(), which will set all the flash to 1. Otherwise, we don’t do this. Then we call read_test(), which read all the data in the file system. After that, we check whether there are files exist in the system. If there is, we give up wirting. Otherwise, we create two files and write some data in.&lt;br /&gt;
The process then looks like:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_coffee_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
	static int flag = 0;&lt;br /&gt;
	button_sensor.configure(SENSORS_ACTIVE, 1);&lt;br /&gt;
&lt;br /&gt;
	static struct etimer ak;&lt;br /&gt;
	etimer_set(&amp;amp;ak, CLOCK_SECOND * 6);&lt;br /&gt;
	&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER || ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor);&lt;br /&gt;
&lt;br /&gt;
	if (ev == PROCESS_EVENT_TIMER)&lt;br /&gt;
		cfs_coffee_format();	&lt;br /&gt;
&lt;br /&gt;
	if ((flag = read_test()) == -1)&lt;br /&gt;
		PROCESS_EXIT();&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	static struct etimer et;&lt;br /&gt;
	etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);&lt;br /&gt;
&lt;br /&gt;
	if (flag == 1)&lt;br /&gt;
		printf(&amp;quot;\nData exists...No written again...\n&amp;quot;);&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nData begin to write...\n&amp;quot;);&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The first test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 1 failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The second test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 2 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(file_test(FILENAME_2, &amp;quot;The third test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 3 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(dir_test() == 0) {&lt;br /&gt;
    			printf(&amp;quot;dir test failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, connect your mote to your PC’s USB port and change directory. &lt;br /&gt;
  cd contiki-2.7/examples/sky &lt;br /&gt;
&lt;br /&gt;
Compile this Coffee example to Sky Mote.&lt;br /&gt;
  sudo make TARGET=sky example-coffee.upload login&lt;br /&gt;
&lt;br /&gt;
Once login, wait for 6 seconds patiently for the first time out.If it success, we should see terminal has the output like this:&lt;br /&gt;
Here you can see, we create two files and write some data in. Then, disconnect your mote and do whatever you want. Maybe one day later, you come back. Now it’s the time to keep moving. &lt;br /&gt;
Welcome back. Now connect your mote with USB port again and do:&lt;br /&gt;
  sudo make TARGET=sky login&lt;br /&gt;
You are in the process again and please follow the following two steps:&lt;br /&gt;
1. push “RESET” button;&lt;br /&gt;
2. push “USER” button within 6 seconds.&lt;br /&gt;
Now, the program will not call cfs_coffee_format(). If succeed, you will see: &lt;br /&gt;
As you can see, we read out all the data that you wrote in one day ago. Everything is right there without any change.&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1747</id>
		<title>CFS-Coffee</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1747"/>
				<updated>2016-07-29T21:55:19Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Permanent Storage of Contiki on Tmote Sky (CFS-Coffee) ==&lt;br /&gt;
&lt;br /&gt;
Contiki provides File System to achieve the goal of permanent storage. The Contiki File System(CFS) works as a Virtual File System and provides some interfaces for different file systems. CFS-POSIX and Coffee are two with full functionalities. CFS-POSIX is used in Contiki platforms that runs in native mode. Coffee, on the other hand, is primarily aimed at sensor devices that equiped with Flash Memories or EEPROM.&lt;br /&gt;
&lt;br /&gt;
==The CFS Programming Interface==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00128.html&lt;br /&gt;
&lt;br /&gt;
==Introduction to Coffee==&lt;br /&gt;
&lt;br /&gt;
Coffee is a fully functional file system designed specifically for the characteristics of flash memories and EEPROM. Coffee is usually used in sensor devices with flash (e.g Tmote Sky), so two principles are pretty important. First, the metadata stored in RAM for each file should be small because sensor devices have very limited RAM space. Second, bits in flash memories can be toggled from 1 to 0, but not toggled back from 0 to 1 without doing an expensive erase. Thus, when modifying a file, Coffee creates an invisible micro log which is linked to the original file. The micro log contains the lastest data of the file. For user, the micro log and the original file is just one logical file, as if they modify the original file. When the micro log eventually fills up, Coffee transparently merges the content of the original file and the micro log into a new file, and deletes the two former files. &lt;br /&gt;
&lt;br /&gt;
Coffee has a flat directory structure. It only has the root directory. Thus, cfs_opendir() only accept “/” or “.” as the second argument. When removing a file from a Coffee, there are two steps. First, external user calls cfs_remove(). The file mentioned by user will be marked as obsolete. Obsolete files cannot be seen by external users. Coffee will actually delete files only when a new file reservation request cannot be granted.&lt;br /&gt;
&lt;br /&gt;
The implementation of Coffee in core/cfs/cfs-coffee.c is totally platform independent. The specific configuration of Coffee for different platforms is written in csf-coffee-arch.c. We can see many csf-coffee-arch.c files in plarform/./csf-coffee-arch.c, e.g plarform/z1/csf-coffee-arch.c, plarform/esb/csf-coffee-arch.c, plarform/sky/csf-coffee-arch.c. When we decide the platform, such as TARGET=sky, we compile plarform/sky/csf-coffee-arch.c and ignore all other csf-coffee-arch.c files. Macro definitions in plarform/sky/csf-coffee-arch.c configure the details of coffee in Sky Mote. Macro definition contains parameters like COFFEE_SECTOR_SIZE, COFFEE_PAGE_SIZE, COFFEE_FD_SET_SIZE, COFFEE_MICRO_LOGS and so on. Also, it defines COFFEE_WRITE, COFFEE_READ and COFFEE_ERASE to point to the device drivers I/O function. &lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Interface Extensions==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00122.html&lt;br /&gt;
&lt;br /&gt;
cfs_coffee_format() may take a few second because all sectors must be erased.  cfs_coffee_reserve() and int cfs_coffee_configure_log() can optimize Coffee’s handling of the file.&lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Summary==&lt;br /&gt;
&lt;br /&gt;
Here is an example of how everything works. Suppose we want to run Contiki on Sky Mote. First make sure TARGET=sky. Then every file about sky is compiled and you can also see a new folder which is created called sky_obj. Inside contains everything you need to run on Sky Mote. Suppose you want to use Coffee as the File System. Write cfs_coffee_format() before the first time you try to operate on Coffee. This function notice the system that you want to use Coffee and the system will do some formatting. Let’s say then you want to read something from an existing file with the function call cfs_read(). This function is defined in core/cfs/cfs.h. Because we make use of Coffee, the implementation of this function will be in core/cfs/cfs-coffee.c. The function cfs_read() actually calls the macro definition COFFEE_READ(). The definition of COFFEE_READ() is in cfs-coffee-arch.c. Since we make TARGET=sky, the one that was compiled and used by us is platform/sky/cfs-coffee-arch.c. This file defines COFFEE_READ() to point to Sky Mote drivers I/O function. Finally, the external users’ cfs_read() gets to the Sky Driver I/O function.&lt;br /&gt;
&lt;br /&gt;
==An Example of Running Coffee on Tmote Sky==&lt;br /&gt;
&lt;br /&gt;
This example shows the basic way to open, read, write and append files in Coffee. The platform we choose here is Tmote Sky.&lt;br /&gt;
First, open an example provided by Contiki (/home/user/contiki-2.7/example/sky/example- coffee.c).&lt;br /&gt;
Here, it defines two test functions:&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;static int file_test(const char *filename, char *msg)&amp;lt;/code&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
opens a file named FILENAME with CFS_WRITE | CFS_APPEND | CFS_READ. It appends the opening file with records and prints out everything in the file.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;static int dir_test(void)&amp;lt;/code&amp;gt;&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
opens the root directory and prints out all entries of root.&lt;br /&gt;
The Process calls file_test() twice and dir_test() once. Then the process ends.&lt;br /&gt;
Now, we do some modifications based on this example. First we add a function static int read_test(void). The implementation of this function is shown as below:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  static int&lt;br /&gt;
  read_test(void)&lt;br /&gt;
  {&lt;br /&gt;
	  struct cfs_dir dir;&lt;br /&gt;
	  struct cfs_dirent dirent;&lt;br /&gt;
	  int fd;&lt;br /&gt;
	  int r;&lt;br /&gt;
	  struct record {&lt;br /&gt;
    		  char message[16];&lt;br /&gt;
    		  uint8_t sequence;&lt;br /&gt;
  	  } record;&lt;br /&gt;
	  static int i = 0;&lt;br /&gt;
	  if (cfs_opendir(&amp;amp;dir, &amp;quot;/&amp;quot;) != 0)&lt;br /&gt;
	  {&lt;br /&gt;
		printf(&amp;quot;Fail to open the root directory\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	while(cfs_readdir(&amp;amp;dir, &amp;amp;dirent) == 0)&lt;br /&gt;
	{&lt;br /&gt;
		i ++;&lt;br /&gt;
		printf(&amp;quot;\nFile name: %s\n&amp;quot;, dirent.name);&lt;br /&gt;
		if ((fd =cfs_open(dirent.name, CFS_READ)) != -1)&lt;br /&gt;
		{&lt;br /&gt;
			cfs_seek(fd, 0, CFS_SEEK_SET);&lt;br /&gt;
			for(;;) &lt;br /&gt;
			{&lt;br /&gt;
    				r = cfs_read(fd, &amp;amp;record, sizeof(record));&lt;br /&gt;
    				if(r == 0) {&lt;br /&gt;
      					break;&lt;br /&gt;
    				} else if(r &amp;gt; sizeof(record)) {&lt;br /&gt;
      					printf(&amp;quot;failed to read %d bytes from %s, got %d\n&amp;quot;,(int)sizeof(record), dirent.name, r);&lt;br /&gt;
      					cfs_close(fd);&lt;br /&gt;
      					return -1;&lt;br /&gt;
    				}&lt;br /&gt;
&lt;br /&gt;
    				printf(&amp;quot;Read message \&amp;quot;%s\&amp;quot;, sequence %u\n&amp;quot;,record.message, record.sequence);&lt;br /&gt;
  			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (i == 0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nNo file exists.\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return 1;&lt;br /&gt;
	}&lt;br /&gt;
		&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function of read_test() is quite simple. It opens the root file system and reads all the data in the file system. In the while() loop, it reads an entry of a file. Then it makes use of the entry to open the file and read all the data out.&lt;br /&gt;
&lt;br /&gt;
Also, in the process, we add an etimer at the beginning. The process can only move on either when the timer expired or someone push a button. If the timer expire, the process will run cfs_coffee_format(), which will set all the flash to 1. Otherwise, we don’t do this. Then we call read_test(), which read all the data in the file system. After that, we check whether there are files exist in the system. If there is, we give up wirting. Otherwise, we create two files and write some data in.&lt;br /&gt;
The process then looks like:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_coffee_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
	static int flag = 0;&lt;br /&gt;
	button_sensor.configure(SENSORS_ACTIVE, 1);&lt;br /&gt;
&lt;br /&gt;
	static struct etimer ak;&lt;br /&gt;
	etimer_set(&amp;amp;ak, CLOCK_SECOND * 6);&lt;br /&gt;
	&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER || ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor);&lt;br /&gt;
&lt;br /&gt;
	if (ev == PROCESS_EVENT_TIMER)&lt;br /&gt;
		cfs_coffee_format();	&lt;br /&gt;
&lt;br /&gt;
	if ((flag = read_test()) == -1)&lt;br /&gt;
		PROCESS_EXIT();&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	static struct etimer et;&lt;br /&gt;
	etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);&lt;br /&gt;
&lt;br /&gt;
	if (flag == 1)&lt;br /&gt;
		printf(&amp;quot;\nData exists...No written again...\n&amp;quot;);&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nData begin to write...\n&amp;quot;);&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The first test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 1 failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The second test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 2 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(file_test(FILENAME_2, &amp;quot;The third test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 3 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(dir_test() == 0) {&lt;br /&gt;
    			printf(&amp;quot;dir test failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, connect your mote to your PC’s USB port and change directory. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;code&amp;gt;cd contiki-2.7/examples/sky&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Compile this Coffee example to Sky Mote.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;code&amp;gt;sudo make TARGET=sky example-coffee.upload login&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once login, wait for 6 seconds patiently for the first time out.If it success, we should see terminal has the output like this:&lt;br /&gt;
Here you can see, we create two files and write some data in. Then, disconnect your mote and do whatever you want. Maybe one day later, you come back. Now it’s the time to keep moving. &lt;br /&gt;
Welcome back. Now connect your mote with USB port again and do:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;code&amp;gt;sudo make TARGET=sky login&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
You are in the process again and please follow the following two steps:&lt;br /&gt;
1. push “RESET” button;&lt;br /&gt;
2. push “USER” button within 6 seconds.&lt;br /&gt;
Now, the program will not call cfs_coffee_format(). If succeed, you will see: &lt;br /&gt;
As you can see, we read out all the data that you wrote in one day ago. Everything is right there without any change.&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1746</id>
		<title>CFS-Coffee</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=CFS-Coffee&amp;diff=1746"/>
				<updated>2016-07-29T21:51:05Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Permanent Storage of Contiki on Tmote Sky (CFS-Coffee) ==&lt;br /&gt;
&lt;br /&gt;
Contiki provides File System to achieve the goal of permanent storage. The Contiki File System(CFS) works as a Virtual File System and provides some interfaces for different file systems. CFS-POSIX and Coffee are two with full functionalities. CFS-POSIX is used in Contiki platforms that runs in native mode. Coffee, on the other hand, is primarily aimed at sensor devices that equiped with Flash Memories or EEPROM.&lt;br /&gt;
&lt;br /&gt;
==The CFS Programming Interface==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00128.html&lt;br /&gt;
&lt;br /&gt;
==Introduction to Coffee==&lt;br /&gt;
&lt;br /&gt;
Coffee is a fully functional file system designed specifically for the characteristics of flash memories and EEPROM. Coffee is usually used in sensor devices with flash (e.g Tmote Sky), so two principles are pretty important. First, the metadata stored in RAM for each file should be small because sensor devices have very limited RAM space. Second, bits in flash memories can be toggled from 1 to 0, but not toggled back from 0 to 1 without doing an expensive erase. Thus, when modifying a file, Coffee creates an invisible micro log which is linked to the original file. The micro log contains the lastest data of the file. For user, the micro log and the original file is just one logical file, as if they modify the original file. When the micro log eventually fills up, Coffee transparently merges the content of the original file and the micro log into a new file, and deletes the two former files. &lt;br /&gt;
&lt;br /&gt;
Coffee has a flat directory structure. It only has the root directory. Thus, cfs_opendir() only accept “/” or “.” as the second argument. When removing a file from a Coffee, there are two steps. First, external user calls cfs_remove(). The file mentioned by user will be marked as obsolete. Obsolete files cannot be seen by external users. Coffee will actually delete files only when a new file reservation request cannot be granted.&lt;br /&gt;
&lt;br /&gt;
The implementation of Coffee in core/cfs/cfs-coffee.c is totally platform independent. The specific configuration of Coffee for different platforms is written in csf-coffee-arch.c. We can see many csf-coffee-arch.c files in plarform/./csf-coffee-arch.c, e.g plarform/z1/csf-coffee-arch.c, plarform/esb/csf-coffee-arch.c, plarform/sky/csf-coffee-arch.c. When we decide the platform, such as TARGET=sky, we compile plarform/sky/csf-coffee-arch.c and ignore all other csf-coffee-arch.c files. Macro definitions in plarform/sky/csf-coffee-arch.c configure the details of coffee in Sky Mote. Macro definition contains parameters like COFFEE_SECTOR_SIZE, COFFEE_PAGE_SIZE, COFFEE_FD_SET_SIZE, COFFEE_MICRO_LOGS and so on. Also, it defines COFFEE_WRITE, COFFEE_READ and COFFEE_ERASE to point to the device drivers I/O function. &lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Interface Extensions==&lt;br /&gt;
&lt;br /&gt;
For detail interface introduction, please refer to the below link:&lt;br /&gt;
&lt;br /&gt;
http://contiki.sourceforge.net/docs/2.6/a00122.html&lt;br /&gt;
&lt;br /&gt;
cfs_coffee_format() may take a few second because all sectors must be erased.  cfs_coffee_reserve() and int cfs_coffee_configure_log() can optimize Coffee’s handling of the file.&lt;br /&gt;
&lt;br /&gt;
==CFS-Coffee Summary==&lt;br /&gt;
&lt;br /&gt;
Here is an example of how everything works. Suppose we want to run Contiki on Sky Mote. First make sure TARGET=sky. Then every file about sky is compiled and you can also see a new folder which is created called sky_obj. Inside contains everything you need to run on Sky Mote. Suppose you want to use Coffee as the File System. Write cfs_coffee_format() before the first time you try to operate on Coffee. This function notice the system that you want to use Coffee and the system will do some formatting. Let’s say then you want to read something from an existing file with the function call cfs_read(). This function is defined in core/cfs/cfs.h. Because we make use of Coffee, the implementation of this function will be in core/cfs/cfs-coffee.c. The function cfs_read() actually calls the macro definition COFFEE_READ(). The definition of COFFEE_READ() is in cfs-coffee-arch.c. Since we make TARGET=sky, the one that was compiled and used by us is platform/sky/cfs-coffee-arch.c. This file defines COFFEE_READ() to point to Sky Mote drivers I/O function. Finally, the external users’ cfs_read() gets to the Sky Driver I/O function.&lt;br /&gt;
&lt;br /&gt;
==An Example of Running Coffee on Tmote Sky==&lt;br /&gt;
&lt;br /&gt;
This example shows the basic way to open, read, write and append files in Coffee. The platform we choose here is Tmote Sky.&lt;br /&gt;
First, open an example provided by Contiki (/home/user/contiki-2.7/example/sky/example- coffee.c).&lt;br /&gt;
Here, it defines two test functions:&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;static int file_test(const char *filename, char *msg)&amp;lt;/code&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
opens a file named FILENAME with CFS_WRITE | CFS_APPEND | CFS_READ. It appends the opening file with records and prints out everything in the file.&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;static int dir_test(void)&amp;lt;/code&amp;gt;&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
opens the root directory and prints out all entries of root.&lt;br /&gt;
The Process calls file_test() twice and dir_test() once. Then the process ends.&lt;br /&gt;
Now, we do some modifications based on this example. First we add a function static int read_test(void). The implementation of this function is shown as below:&lt;br /&gt;
&lt;br /&gt;
  static int&lt;br /&gt;
  read_test(void)&lt;br /&gt;
  {&lt;br /&gt;
	struct cfs_dir dir;&lt;br /&gt;
	struct cfs_dirent dirent;&lt;br /&gt;
&lt;br /&gt;
	int fd;&lt;br /&gt;
	int r;&lt;br /&gt;
&lt;br /&gt;
	struct record {&lt;br /&gt;
    		char message[16];&lt;br /&gt;
    		uint8_t sequence;&lt;br /&gt;
  	} record;&lt;br /&gt;
&lt;br /&gt;
	static int i = 0;&lt;br /&gt;
	if (cfs_opendir(&amp;amp;dir, &amp;quot;/&amp;quot;) != 0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;Fail to open the root directory\n&amp;quot;);&lt;br /&gt;
		return -1;&lt;br /&gt;
	}&lt;br /&gt;
	while(cfs_readdir(&amp;amp;dir, &amp;amp;dirent) == 0)&lt;br /&gt;
	{&lt;br /&gt;
		i ++;&lt;br /&gt;
		printf(&amp;quot;\nFile name: %s\n&amp;quot;, dirent.name);&lt;br /&gt;
		if ((fd =cfs_open(dirent.name, CFS_READ)) != -1)&lt;br /&gt;
		{&lt;br /&gt;
			cfs_seek(fd, 0, CFS_SEEK_SET);&lt;br /&gt;
			for(;;) &lt;br /&gt;
			{&lt;br /&gt;
    				r = cfs_read(fd, &amp;amp;record, sizeof(record));&lt;br /&gt;
    				if(r == 0) {&lt;br /&gt;
      					break;&lt;br /&gt;
    				} else if(r &amp;gt; sizeof(record)) {&lt;br /&gt;
      					printf(&amp;quot;failed to read %d bytes from %s, got %d\n&amp;quot;,(int)sizeof(record), dirent.name, r);&lt;br /&gt;
      					cfs_close(fd);&lt;br /&gt;
      					return -1;&lt;br /&gt;
    				}&lt;br /&gt;
&lt;br /&gt;
    				printf(&amp;quot;Read message \&amp;quot;%s\&amp;quot;, sequence %u\n&amp;quot;,record.message, record.sequence);&lt;br /&gt;
  			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (i == 0)&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nNo file exists.\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return 1;&lt;br /&gt;
	}&lt;br /&gt;
		&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The function of read_test() is quite simple. It opens the root file system and reads all the data in the file system. In the while() loop, it reads an entry of a file. Then it makes use of the entry to open the file and read all the data out.&lt;br /&gt;
&lt;br /&gt;
Also, in the process, we add an etimer at the beginning. The process can only move on either when the timer expired or someone push a button. If the timer expire, the process will run cfs_coffee_format(), which will set all the flash to 1. Otherwise, we don’t do this. Then we call read_test(), which read all the data in the file system. After that, we check whether there are files exist in the system. If there is, we give up wirting. Otherwise, we create two files and write some data in.&lt;br /&gt;
The process then looks like:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_coffee_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
	static int flag = 0;&lt;br /&gt;
	button_sensor.configure(SENSORS_ACTIVE, 1);&lt;br /&gt;
&lt;br /&gt;
	static struct etimer ak;&lt;br /&gt;
	etimer_set(&amp;amp;ak, CLOCK_SECOND * 6);&lt;br /&gt;
	&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER || ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor);&lt;br /&gt;
&lt;br /&gt;
	if (ev == PROCESS_EVENT_TIMER)&lt;br /&gt;
		cfs_coffee_format();	&lt;br /&gt;
&lt;br /&gt;
	if ((flag = read_test()) == -1)&lt;br /&gt;
		PROCESS_EXIT();&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	static struct etimer et;&lt;br /&gt;
	etimer_set(&amp;amp;et, CLOCK_SECOND * 2);&lt;br /&gt;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);&lt;br /&gt;
&lt;br /&gt;
	if (flag == 1)&lt;br /&gt;
		printf(&amp;quot;\nData exists...No written again...\n&amp;quot;);&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		printf(&amp;quot;\nData begin to write...\n&amp;quot;);&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The first test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 1 failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
		if(file_test(FILENAME_1, &amp;quot;The second test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 2 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(file_test(FILENAME_2, &amp;quot;The third test&amp;quot;) == 0) {&lt;br /&gt;
    			printf(&amp;quot;file test 3 failed\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		if(dir_test() == 0) {&lt;br /&gt;
    			printf(&amp;quot;dir test failed\n&amp;quot;);&lt;br /&gt;
  		}&lt;br /&gt;
&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, connect your mote to your PC’s USB port and change directory. &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;code&amp;gt;cd contiki-2.7/examples/sky&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Compile this Coffee example to Sky Mote.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;code&amp;gt;sudo make TARGET=sky example-coffee.upload login&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once login, wait for 6 seconds patiently for the first time out.If it success, we should see terminal has the output like this:&lt;br /&gt;
Here you can see, we create two files and write some data in. Then, disconnect your mote and do whatever you want. Maybe one day later, you come back. Now it’s the time to keep moving. &lt;br /&gt;
Welcome back. Now connect your mote with USB port again and do:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;code&amp;gt;sudo make TARGET=sky login&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
You are in the process again and please follow the following two steps:&lt;br /&gt;
1. push “RESET” button;&lt;br /&gt;
2. push “USER” button within 6 seconds.&lt;br /&gt;
Now, the program will not call cfs_coffee_format(). If succeed, you will see: &lt;br /&gt;
As you can see, we read out all the data that you wrote in one day ago. Everything is right there without any change.&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1745</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1745"/>
				<updated>2016-07-28T22:54:22Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 5 - Introduction to rtimer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
  }&lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(example_broadcast_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast));&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1744</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1744"/>
				<updated>2016-07-28T21:02:55Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 4 - Using ctimer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
  }&lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1743</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1743"/>
				<updated>2016-07-28T21:02:12Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 5 - Introduction to rtimer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1742</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1742"/>
				<updated>2016-07-28T21:01:39Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 5 - Introduction to rtimer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
  PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1741</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1741"/>
				<updated>2016-07-28T21:00:57Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 4 - Using ctimer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1740</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1740"/>
				<updated>2016-07-28T21:00:18Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 4 - Using ctimer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
  static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
}&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1739</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1739"/>
				<updated>2016-07-28T20:59:50Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 3 - Adding a timer */&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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
  if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
}&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1738</id>
		<title>Timers</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Timers&amp;diff=1738"/>
				<updated>2016-07-28T20:58:55Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &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;
Timers can be used to control periodic tasks as well as implement sophisticated algorithms. The implementation of each type of timer is platform-dependent and has different properties that make them useful in specific situations; some timers have low granularity (seconds) and overflow once in tens of years, and others provide high granularity (microseconds), but overflow rapidly. There are 5 types of timers provided by Contiki:&lt;br /&gt;
&lt;br /&gt;
* timer&lt;br /&gt;
* stimer&lt;br /&gt;
* ctimer&lt;br /&gt;
* etimer&lt;br /&gt;
* rtimer&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The functions of all types of timers are located inside folder &amp;#039;&amp;#039;&amp;#039;core/sys/{timer, stimer, ctimer, etimer, rtimer}.{c,h}&amp;#039;&amp;#039;&amp;#039;. A complete documentation of Timers in Contiki can be found [https://github.com/contiki-os/contiki/wiki/Timers here].&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;timer&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;stimer&amp;#039;&amp;#039;&amp;#039; are the most basic types of timers and are used to check if a time interval has passed. They do not notice when the time period has elapsed, so the application needs to check periodically if they have expired. The difference between them is the resolution: &amp;#039;&amp;#039;timers&amp;#039;&amp;#039; use system clock ticks, which gives high granularity (order of microseconds) but short overflow periods (order of seconds). On the other hand, &amp;#039;&amp;#039;stimers&amp;#039;&amp;#039; use seconds to allow much longer time periods (order of years), but has lesser granularity. &lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;etimer&amp;#039;&amp;#039;&amp;#039; provides event timers and are used to schedule events to the processes after a period of time. They are used in Contiki processes to wait for a time period while the rest of the system can work or enter low power mode.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;ctimer&amp;#039;&amp;#039;&amp;#039; provides callback timers and are used to schedule calls to functions after a period of time. Like event timers, they are used to wait for some time while the rest of the system can work or enter low power mode. Since the callback timers call a function when a timer expires, they are especially useful in any code that do not have an explicit Contiki process such as protocol implementations.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;rtimer&amp;#039;&amp;#039;&amp;#039; provides scheduling of real-time tasks. The rtimer library preempts any running Contiki process in order to let the real-time tasks execute at the scheduled time. The real-time tasks are used in time critical codes.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
*Simple implementations of each type of timer.&lt;br /&gt;
*Tasks each timer can be used for.&lt;br /&gt;
*Some functions in the timer libraries.&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Again, we will have to change folders. We will create a new file for this tutorial, but let&amp;#039;s create it in the same directory we&amp;#039;ve been working with, so type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cd contiki-2.7/examples/rime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into the terminal. For this tutorial, we will be modifying the example-broadcast.c file we have previously used, so type &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; cp example-broadcast.c example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
into your terminal. You should now see a new file, &amp;quot;example-timer.c&amp;quot; in your directory. Open it up with an editor of your choice (we will use gedit for this tutorial):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; gedit example-timer.c &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
There is currently a working example of an etimer in this code, so before we proceed, let&amp;#039;s understand this. At the beginning of the process, it is declared with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates an etimer instance. Within the while loop, it is set with the function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND*4 + random_rand() % (CLOCK_SECOND * 4)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function takes the arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; etimer_set(struct etimer *et, clock_time_t interval); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and sets the etimer et to expire after interval.&lt;br /&gt;
&lt;br /&gt;
After that, we see the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which tells the example_broadcast_process to pause until it receives an event, so the program is essentially giving up system control. When an etimer expires, it posts a PROCESS_EVENT_TIMER event to the example_broadcast_process. So this tells the process to continue and begin running again, as the etimer has expired, and an event has been posted. Now that we understand what the etimer is doing here, let&amp;#039;s incorporate some other timers.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 - Adding a timer ===&lt;br /&gt;
&lt;br /&gt;
To start simply, we are going to use a timer to just print out a message once it expires. Just below&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct etimer et; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
declare a timer with the line:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct timer t; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before the while loop, set the timer with the line: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 10); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This sets the timer to expire after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
Below the line &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; printf(&amp;quot;broadcast message sent\n&amp;quot;); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add in the code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; if(timer_expired(&amp;amp;t)){&lt;br /&gt;
   printf(&amp;quot;Timer expired\n&amp;quot;);&lt;br /&gt;
}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, save and run your code on your Tmote Sky by typing into your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.upload &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t have a Sky, run this code on Mspsim with the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; make TARGET=sky example-timer.mspsim &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Among the &amp;quot;broadcast message sent&amp;quot; messages, you should see a &amp;quot;Timer expired&amp;quot; notice. This only occurs one time, however. This is because we never reset the timer. So, return to your example-timer.c file. Underneath your printf(&amp;quot;Timer expired\n&amp;quot;) line, add the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will reset the timer to expire again in 10 * CLOCK_SECONDS. Run your code again. You should now see &amp;quot;Timer expired&amp;quot; every few broadcast messages. Now, say we only wanted to send broadcast messages for 30 seconds. Let&amp;#039;s use our timer to exit our process after it expires. Change your original timer_set function to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_set(&amp;amp;t, CLOCK_SECOND * 30); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, just delete the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; timer_reset(&amp;amp;t); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and replace it with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again, and it should stop after the timer expires. You have now learned some basic functionality of the timer.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 - Using ctimer ===&lt;br /&gt;
&lt;br /&gt;
Begin by deleting the &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_EXIT(); &amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
line that you previously wrote. We are going to implement a ctimer and no longer want to exit the process. At the beginning of the process, where you declared the other timers, include the code &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct ctimer ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This declares a ctimer, which has the property of calling a function when it expires. In order to do this, we will need to declare a function for it to call! So, just before the start of the process, underneath the line&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static struct broadcast_conn broadcast; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare the following function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void timer_events(void *ptr){ &lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;); &lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go back to the process. Just before the while loop, set the ctimer by typing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, NULL); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This set function takes in arguments that tell the ctimer which function to call, as well as what to pass into the function (NULL in this case). Run your code. You will see that your function is called one time, but since we never reset the code, it never gets called again. So, let&amp;#039;s reset the ctimer as part of the function. Just before you set the ctimer, include this line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; void *ct_ptr = &amp;amp;ct; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And change your ctimer_set function to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 5, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go up to your function, and change it to read like this: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void timer_events(void *ptr){&lt;br /&gt;
   printf(&amp;quot;Congratulations, you called this function&amp;quot;);&lt;br /&gt;
   struct ctimer* ct_ptr = ptr;&lt;br /&gt;
   ctimer_reset(ct_ptr);&lt;br /&gt;
}&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Now run your code again. The function should be called over and over again. The last thing we will do with this function is learn how to terminate the process from the function, using our same ctimer. To begin, change your c_timer set function to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; ctimer_set(&amp;amp;ct, CLOCK_SECOND * 30, timer_events, ct_ptr); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
so the process runs longer before we exit it. Now go up to your function and delete the ctimer_reset line. Replace it with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; process_exit(&amp;amp;example_broadcast_process); &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run your code again. You will see that the example_broadcast_process stops running after 30 seconds, and you have learned how to do this from a function called by a ctimer!&lt;br /&gt;
&lt;br /&gt;
=== Step 5 - Introduction to rtimer===&lt;br /&gt;
&lt;br /&gt;
The rtimer library provides real-time scheduling mechanisms, typically for applications where a response to an external event is extremely time sensitive. Rtimers use absolute system clock time as a reference.&lt;br /&gt;
&lt;br /&gt;
We will modify our original broadcast process with an rtimer, to demonstrate rtimer&amp;#039;s usefulness for calling a function at an absolute time in response to an event. In this case, our etimer produces random, simulated real-time events.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; static void function( rtimer *rt, void *ptr) {&lt;br /&gt;
    packetbuf_copyfrom(&amp;quot;Event Occurred&amp;quot;, 15);&lt;br /&gt;
    broadcast_send(&amp;amp;broadcast);&lt;br /&gt;
    printf(&amp;quot;Real Time Task Completed\n&amp;quot;); &lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The function &amp;#039;responds&amp;#039; to the scheduling of a real-time task using rtimer, and can be used to answer an external stimulus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; PROCESS_THREAD(broadcast_example_process, ev, data) {&lt;br /&gt;
    static struct etimer et;&lt;br /&gt;
    static struct rtimer rt;&lt;br /&gt;
&lt;br /&gt;
    PROCESS_EXIT_HANDLER(broadcast_close(&amp;amp;broadcast);)&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    while (1) {&lt;br /&gt;
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;t)); //Real Time Event &lt;br /&gt;
        printf(&amp;quot;Real Time Event Recorded\n&amp;quot;);&lt;br /&gt;
        rtimer_set(&amp;amp;rt, RTIMER_NOW()+RTIMER_ARCH_SECOND,1,function,NULL);&lt;br /&gt;
    }&lt;br /&gt;
    PROCESS_END();&lt;br /&gt;
} &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note the setting method for rtimer takes 4 arguments: &lt;br /&gt;
- real-time task (rtimer)&lt;br /&gt;
- time at which task must be completed&lt;br /&gt;
- duration - UNUSED&lt;br /&gt;
- function to call&lt;br /&gt;
- argument for the function, which is NULL in this case.&lt;br /&gt;
&lt;br /&gt;
Upon simulating this code, you will see the rtimer respond almost immediately to each simulated real-time event. However, using the simulation does not allow for some of the features of rtimer, because rtimer is a low level struct that has significant dependence on physical aspects of the hardware. You will notice that replacing &amp;quot;RTIMER_ARCH_SECOND&amp;quot; with &amp;quot;4096*RTIMER_ARCH_SECOND&amp;quot; does not change the delay in simulation. Code using rtimer should be run on physical tmotes, due to their dependence on physical hardware (as should stimer.)&lt;br /&gt;
&lt;br /&gt;
A complete example of rtimer&amp;#039;s uses that can be run on hardware is &amp;quot;example-rudolph1.c&amp;quot; in rime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
References:&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Timers#wiki-The_Timer_Library]&lt;br /&gt;
[http://contiki.sourceforge.net/docs/2.6/a01673.html]&lt;br /&gt;
&lt;br /&gt;
Edited by: Leo Linsky, Tim Ferrell&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1734</id>
		<title>Troubleshooting</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1734"/>
				<updated>2016-07-25T23:00:22Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Attribute Error while interfacing with Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
===== Permission denied =====&lt;br /&gt;
If you try to connect to a mote and receive a permission error, you may need to add yourself to the dialout group. The error may look something like the following:&lt;br /&gt;
&lt;br /&gt;
 /home/user/contiki/tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
 connecting to /dev/ttyUSB0 (115200)&lt;br /&gt;
 /dev/ttyUSB0: Permission denied&lt;br /&gt;
 make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Use the following command (replace &amp;lt;username&amp;gt; with your account):&lt;br /&gt;
&lt;br /&gt;
 sudo adduser &amp;lt;username&amp;gt; dialout&lt;br /&gt;
&lt;br /&gt;
-OR-&lt;br /&gt;
&lt;br /&gt;
 sudo usermod -a -G dialout &amp;lt;username&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands are equivalent. They both will add username to the dialout group. &amp;#039;&amp;#039;&amp;#039;You will then have to re-login to or reboot your computer for the changes to take effect.&amp;#039;&amp;#039;&amp;#039; You should now have read/write permissions to your USB serial devices. It is not necessary to remove any packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Trying the following command which should give  the desired output&lt;br /&gt;
&lt;br /&gt;
  make TARGET=sky sky-motelist &lt;br /&gt;
&lt;br /&gt;
(sky can be replaced by the mote which is being used e.g z1)&lt;br /&gt;
&lt;br /&gt;
The desired output&lt;br /&gt;
&lt;br /&gt;
  ../../tools/sky/motelist-linux &lt;br /&gt;
  Reference  Device           Description &lt;br /&gt;
  ---------- ---------------- --------------------------------------------- &lt;br /&gt;
  M4A7J5HF   /dev/ttyUSB0     Moteiv tmote sky &lt;br /&gt;
&lt;br /&gt;
This means it is a common serial port connection problem with Ubuntu 12.04 LTS.&lt;br /&gt;
&lt;br /&gt;
To resolve the issue do the following.&lt;br /&gt;
 &lt;br /&gt;
  sudo apt-get remove modemmanager&lt;br /&gt;
  sudo adduser $USER dialout (or)&lt;br /&gt;
  sudo usermod -a -G dialout $USER // adds the user to the dialout&lt;br /&gt;
  // replace $USER by the username&lt;br /&gt;
  sudo reboot&lt;br /&gt;
  id -Gn&lt;br /&gt;
&lt;br /&gt;
And check now if the device is attached to the dialout user group.&lt;br /&gt;
&lt;br /&gt;
  ls -l /dev/ttyUSB0&lt;br /&gt;
  crw-rw---- 1 root dialout 188, 0 Mar  5 19:58 /dev/ttyUSB0 &lt;br /&gt;
&lt;br /&gt;
There is no need to mess with dev rules or permissions. &lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Issue with make login =====&lt;br /&gt;
If you are trying to execute the serial-dump application (contiki/tools/sky/serialdump-linux) and see the message: &amp;quot;No such file or directory&amp;quot; or &amp;quot;Command not found&amp;quot;, it means that you are running in a 64-bit operating system that does not have proper 32-bit libraries installed. Since serialdump-linux is a pre-compiled 32-bit tool you need to execute the following command to install the necessary libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install ia32-libs&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On newer versions of Ubuntu, try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install libc6-i386&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work &lt;br /&gt;
&lt;br /&gt;
Then, try few commands like:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
&lt;br /&gt;
The output look similar to the following:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
        linux-gate.so.1 =&amp;gt;  (0xf772d000)&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib32/libc.so.6 (0xf75b4000)&lt;br /&gt;
        /lib/ld-linux.so.2 (0xf772e000)&lt;br /&gt;
&lt;br /&gt;
Then it means that you have to install 32-bit packages. &lt;br /&gt;
Remember to add i386 architecture or you won&amp;#039;t be able to install 32-bit packages:&lt;br /&gt;
  sudo dpkg --add-architecture i386&lt;br /&gt;
  sudo apt-get update&lt;br /&gt;
  sudo apt-get install ia32-libs&lt;br /&gt;
&lt;br /&gt;
===== Input/output error =====&lt;br /&gt;
If you try to connect to a mote and receive an Input/output error as shown below,&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/hello-world$ sudo -s make login&lt;br /&gt;
  using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
  ../../tools/sky/serialdump-linux -b115200&lt;br /&gt;
  connecting to /dev/ttyS0 (115200) [OK]&lt;br /&gt;
  could not get options: Input/output error&lt;br /&gt;
  make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Then it means that VirtualBox cannot detect the mote connected to the USB interface.&lt;br /&gt;
&lt;br /&gt;
This issue can be fixed by making a minor change in the VM settings.&lt;br /&gt;
&lt;br /&gt;
In the VirtualBox Manager, select the &amp;#039;Contiki&amp;#039; VM.&lt;br /&gt;
&lt;br /&gt;
Settings-&amp;gt; USB-&amp;gt; Add new USB Filter with all fields set to the values of the selected USB device&lt;br /&gt;
&lt;br /&gt;
and select the mote to be added. You will have to restart the VM for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
===== Problem running Cooja =====&lt;br /&gt;
If you have a problem regarding using the correct version of Java, please check that your default Java compiler is set correctly. You can use the following command:&lt;br /&gt;
&lt;br /&gt;
  sudo update-alternatives --config java&lt;br /&gt;
&lt;br /&gt;
===== Problem with compiling in Cooja =====&lt;br /&gt;
If you get an error in the linking there may be 2 possible places u need to check to correct them.&lt;br /&gt;
&lt;br /&gt;
            LD        example-netflood.sky&lt;br /&gt;
            /usr/lib/gcc/msp430/4.6.3/../../../../msp430/lib/mmpy-16/libc.a(rand.o):(.debug_info+0xd3): &lt;br /&gt;
            relocation truncated to fit: R_MSP430_16_BYTE against `no symbol&amp;#039;&lt;br /&gt;
            collect2: ld returned 1 exit status&lt;br /&gt;
            make: *** [example-netflood.sky] Error 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, check the line near 132 in file : contiki/cpu/msp430/Makefile.msp430&lt;br /&gt;
&lt;br /&gt;
which looks like the following&lt;br /&gt;
&lt;br /&gt;
         CFLAGSNO = -Wall -mmcu=$(CC_MCU) -g $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
and delete the option “-g”.&lt;br /&gt;
&lt;br /&gt;
The line should look like :&lt;br /&gt;
&lt;br /&gt;
        CFLAGSNO = -Wall -mmcu=$(CC_MCU) $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
Use the second one if the first doesnot work.&lt;br /&gt;
&lt;br /&gt;
Second one is go to the Makefile of the currently compiling program and remove the line which looks similar to the following.&lt;br /&gt;
&lt;br /&gt;
        CFLAGS += -g&lt;br /&gt;
==== Attribute Error while interfacing with Python ====&lt;br /&gt;
After installing sky-shell on the tmote sky, if you encounter the following error while running &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; python serial.py &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/sky-shell$ python serial.py&lt;br /&gt;
  Traceback (most recent call last):&lt;br /&gt;
    File &amp;quot;serial.py&amp;quot;, line 2, in &amp;lt;module&amp;gt;&lt;br /&gt;
      import serial&lt;br /&gt;
    File &amp;quot;/home/user/contiki/examples/sky-shell/serial.py&amp;quot; , line 3 , in &amp;lt;module&amp;gt;&lt;br /&gt;
      ser = serial.Serial(&lt;br /&gt;
  AttributeError: &amp;#039;module&amp;#039; object has no attribute &amp;#039;Serial&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Then delete &amp;#039;serial.pyc&amp;#039; if exists and rename &amp;#039;serial.py&amp;#039; to anything other than &amp;#039;serial&amp;#039;. Problem occurs when you import &amp;#039;something&amp;#039; when your python file name is &amp;#039;something.py&amp;#039;.&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1733</id>
		<title>Troubleshooting</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1733"/>
				<updated>2016-07-25T22:58:30Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
===== Permission denied =====&lt;br /&gt;
If you try to connect to a mote and receive a permission error, you may need to add yourself to the dialout group. The error may look something like the following:&lt;br /&gt;
&lt;br /&gt;
 /home/user/contiki/tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
 connecting to /dev/ttyUSB0 (115200)&lt;br /&gt;
 /dev/ttyUSB0: Permission denied&lt;br /&gt;
 make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Use the following command (replace &amp;lt;username&amp;gt; with your account):&lt;br /&gt;
&lt;br /&gt;
 sudo adduser &amp;lt;username&amp;gt; dialout&lt;br /&gt;
&lt;br /&gt;
-OR-&lt;br /&gt;
&lt;br /&gt;
 sudo usermod -a -G dialout &amp;lt;username&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands are equivalent. They both will add username to the dialout group. &amp;#039;&amp;#039;&amp;#039;You will then have to re-login to or reboot your computer for the changes to take effect.&amp;#039;&amp;#039;&amp;#039; You should now have read/write permissions to your USB serial devices. It is not necessary to remove any packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Trying the following command which should give  the desired output&lt;br /&gt;
&lt;br /&gt;
  make TARGET=sky sky-motelist &lt;br /&gt;
&lt;br /&gt;
(sky can be replaced by the mote which is being used e.g z1)&lt;br /&gt;
&lt;br /&gt;
The desired output&lt;br /&gt;
&lt;br /&gt;
  ../../tools/sky/motelist-linux &lt;br /&gt;
  Reference  Device           Description &lt;br /&gt;
  ---------- ---------------- --------------------------------------------- &lt;br /&gt;
  M4A7J5HF   /dev/ttyUSB0     Moteiv tmote sky &lt;br /&gt;
&lt;br /&gt;
This means it is a common serial port connection problem with Ubuntu 12.04 LTS.&lt;br /&gt;
&lt;br /&gt;
To resolve the issue do the following.&lt;br /&gt;
 &lt;br /&gt;
  sudo apt-get remove modemmanager&lt;br /&gt;
  sudo adduser $USER dialout (or)&lt;br /&gt;
  sudo usermod -a -G dialout $USER // adds the user to the dialout&lt;br /&gt;
  // replace $USER by the username&lt;br /&gt;
  sudo reboot&lt;br /&gt;
  id -Gn&lt;br /&gt;
&lt;br /&gt;
And check now if the device is attached to the dialout user group.&lt;br /&gt;
&lt;br /&gt;
  ls -l /dev/ttyUSB0&lt;br /&gt;
  crw-rw---- 1 root dialout 188, 0 Mar  5 19:58 /dev/ttyUSB0 &lt;br /&gt;
&lt;br /&gt;
There is no need to mess with dev rules or permissions. &lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Issue with make login =====&lt;br /&gt;
If you are trying to execute the serial-dump application (contiki/tools/sky/serialdump-linux) and see the message: &amp;quot;No such file or directory&amp;quot; or &amp;quot;Command not found&amp;quot;, it means that you are running in a 64-bit operating system that does not have proper 32-bit libraries installed. Since serialdump-linux is a pre-compiled 32-bit tool you need to execute the following command to install the necessary libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install ia32-libs&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On newer versions of Ubuntu, try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install libc6-i386&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work &lt;br /&gt;
&lt;br /&gt;
Then, try few commands like:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
&lt;br /&gt;
The output look similar to the following:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
        linux-gate.so.1 =&amp;gt;  (0xf772d000)&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib32/libc.so.6 (0xf75b4000)&lt;br /&gt;
        /lib/ld-linux.so.2 (0xf772e000)&lt;br /&gt;
&lt;br /&gt;
Then it means that you have to install 32-bit packages. &lt;br /&gt;
Remember to add i386 architecture or you won&amp;#039;t be able to install 32-bit packages:&lt;br /&gt;
  sudo dpkg --add-architecture i386&lt;br /&gt;
  sudo apt-get update&lt;br /&gt;
  sudo apt-get install ia32-libs&lt;br /&gt;
&lt;br /&gt;
===== Input/output error =====&lt;br /&gt;
If you try to connect to a mote and receive an Input/output error as shown below,&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/hello-world$ sudo -s make login&lt;br /&gt;
  using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
  ../../tools/sky/serialdump-linux -b115200&lt;br /&gt;
  connecting to /dev/ttyS0 (115200) [OK]&lt;br /&gt;
  could not get options: Input/output error&lt;br /&gt;
  make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Then it means that VirtualBox cannot detect the mote connected to the USB interface.&lt;br /&gt;
&lt;br /&gt;
This issue can be fixed by making a minor change in the VM settings.&lt;br /&gt;
&lt;br /&gt;
In the VirtualBox Manager, select the &amp;#039;Contiki&amp;#039; VM.&lt;br /&gt;
&lt;br /&gt;
Settings-&amp;gt; USB-&amp;gt; Add new USB Filter with all fields set to the values of the selected USB device&lt;br /&gt;
&lt;br /&gt;
and select the mote to be added. You will have to restart the VM for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
===== Problem running Cooja =====&lt;br /&gt;
If you have a problem regarding using the correct version of Java, please check that your default Java compiler is set correctly. You can use the following command:&lt;br /&gt;
&lt;br /&gt;
  sudo update-alternatives --config java&lt;br /&gt;
&lt;br /&gt;
===== Problem with compiling in Cooja =====&lt;br /&gt;
If you get an error in the linking there may be 2 possible places u need to check to correct them.&lt;br /&gt;
&lt;br /&gt;
            LD        example-netflood.sky&lt;br /&gt;
            /usr/lib/gcc/msp430/4.6.3/../../../../msp430/lib/mmpy-16/libc.a(rand.o):(.debug_info+0xd3): &lt;br /&gt;
            relocation truncated to fit: R_MSP430_16_BYTE against `no symbol&amp;#039;&lt;br /&gt;
            collect2: ld returned 1 exit status&lt;br /&gt;
            make: *** [example-netflood.sky] Error 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, check the line near 132 in file : contiki/cpu/msp430/Makefile.msp430&lt;br /&gt;
&lt;br /&gt;
which looks like the following&lt;br /&gt;
&lt;br /&gt;
         CFLAGSNO = -Wall -mmcu=$(CC_MCU) -g $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
and delete the option “-g”.&lt;br /&gt;
&lt;br /&gt;
The line should look like :&lt;br /&gt;
&lt;br /&gt;
        CFLAGSNO = -Wall -mmcu=$(CC_MCU) $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
Use the second one if the first doesnot work.&lt;br /&gt;
&lt;br /&gt;
Second one is go to the Makefile of the currently compiling program and remove the line which looks similar to the following.&lt;br /&gt;
&lt;br /&gt;
        CFLAGS += -g&lt;br /&gt;
==== Attribute Error while interfacing with Python ====&lt;br /&gt;
After installing sky-shell on the tmote sky, if you encounter the following error while running &amp;#039;python serial.py&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/sky-shell$ python serial.py&lt;br /&gt;
  Traceback (most recent call last):&lt;br /&gt;
    File &amp;quot;serial.py&amp;quot;, line 2, in &amp;lt;module&amp;gt;&lt;br /&gt;
      import serial&lt;br /&gt;
    File &amp;quot;/home/user/contiki/examples/sky-shell/serial.py&amp;quot; , line 3 , in &amp;lt;module&amp;gt;&lt;br /&gt;
      ser = serial.Serial(&lt;br /&gt;
  AttributeError: &amp;#039;module&amp;#039; object has no attribute &amp;#039;Serial&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Then delete &amp;#039;serial.pyc&amp;#039; if exists and rename &amp;#039;serial.py&amp;#039; to anything other than &amp;#039;serial&amp;#039;. Problem occurs when you import &amp;#039;something&amp;#039; when your python file name is &amp;#039;something.py&amp;#039;.&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1732</id>
		<title>Troubleshooting</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1732"/>
				<updated>2016-07-25T22:54:07Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
===== Permission denied =====&lt;br /&gt;
If you try to connect to a mote and receive a permission error, you may need to add yourself to the dialout group. The error may look something like the following:&lt;br /&gt;
&lt;br /&gt;
 /home/user/contiki/tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
 connecting to /dev/ttyUSB0 (115200)&lt;br /&gt;
 /dev/ttyUSB0: Permission denied&lt;br /&gt;
 make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Use the following command (replace &amp;lt;username&amp;gt; with your account):&lt;br /&gt;
&lt;br /&gt;
 sudo adduser &amp;lt;username&amp;gt; dialout&lt;br /&gt;
&lt;br /&gt;
-OR-&lt;br /&gt;
&lt;br /&gt;
 sudo usermod -a -G dialout &amp;lt;username&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands are equivalent. They both will add username to the dialout group. &amp;#039;&amp;#039;&amp;#039;You will then have to re-login to or reboot your computer for the changes to take effect.&amp;#039;&amp;#039;&amp;#039; You should now have read/write permissions to your USB serial devices. It is not necessary to remove any packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Trying the following command which should give  the desired output&lt;br /&gt;
&lt;br /&gt;
  make TARGET=sky sky-motelist &lt;br /&gt;
&lt;br /&gt;
(sky can be replaced by the mote which is being used e.g z1)&lt;br /&gt;
&lt;br /&gt;
The desired output&lt;br /&gt;
&lt;br /&gt;
  ../../tools/sky/motelist-linux &lt;br /&gt;
  Reference  Device           Description &lt;br /&gt;
  ---------- ---------------- --------------------------------------------- &lt;br /&gt;
  M4A7J5HF   /dev/ttyUSB0     Moteiv tmote sky &lt;br /&gt;
&lt;br /&gt;
This means it is a common serial port connection problem with Ubuntu 12.04 LTS.&lt;br /&gt;
&lt;br /&gt;
To resolve the issue do the following.&lt;br /&gt;
 &lt;br /&gt;
  sudo apt-get remove modemmanager&lt;br /&gt;
  sudo adduser $USER dialout (or)&lt;br /&gt;
  sudo usermod -a -G dialout $USER // adds the user to the dialout&lt;br /&gt;
  // replace $USER by the username&lt;br /&gt;
  sudo reboot&lt;br /&gt;
  id -Gn&lt;br /&gt;
&lt;br /&gt;
And check now if the device is attached to the dialout user group.&lt;br /&gt;
&lt;br /&gt;
  ls -l /dev/ttyUSB0&lt;br /&gt;
  crw-rw---- 1 root dialout 188, 0 Mar  5 19:58 /dev/ttyUSB0 &lt;br /&gt;
&lt;br /&gt;
There is no need to mess with dev rules or permissions. &lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Issue with make login =====&lt;br /&gt;
If you are trying to execute the serial-dump application (contiki/tools/sky/serialdump-linux) and see the message: &amp;quot;No such file or directory&amp;quot; or &amp;quot;Command not found&amp;quot;, it means that you are running in a 64-bit operating system that does not have proper 32-bit libraries installed. Since serialdump-linux is a pre-compiled 32-bit tool you need to execute the following command to install the necessary libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install ia32-libs&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On newer versions of Ubuntu, try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install libc6-i386&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work &lt;br /&gt;
&lt;br /&gt;
Then, try few commands like:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
&lt;br /&gt;
The output look similar to the following:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
        linux-gate.so.1 =&amp;gt;  (0xf772d000)&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib32/libc.so.6 (0xf75b4000)&lt;br /&gt;
        /lib/ld-linux.so.2 (0xf772e000)&lt;br /&gt;
&lt;br /&gt;
Then it means that you have to install 32-bit packages. &lt;br /&gt;
Remember to add i386 architecture or you won&amp;#039;t be able to install 32-bit packages:&lt;br /&gt;
  sudo dpkg --add-architecture i386&lt;br /&gt;
  sudo apt-get update&lt;br /&gt;
  sudo apt-get install ia32-libs&lt;br /&gt;
&lt;br /&gt;
===== Input/output error =====&lt;br /&gt;
If you try to connect to a mote and receive an Input/output error as shown below,&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/hello-world$ sudo -s make login&lt;br /&gt;
  using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
  ../../tools/sky/serialdump-linux -b115200&lt;br /&gt;
  connecting to /dev/ttyS0 (115200) [OK]&lt;br /&gt;
  could not get options: Input/output error&lt;br /&gt;
  make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Then it means that VirtualBox cannot detect the mote connected to the USB interface.&lt;br /&gt;
&lt;br /&gt;
This issue can be fixed by making a minor change in the VM settings.&lt;br /&gt;
&lt;br /&gt;
In the VirtualBox Manager, select the &amp;#039;Contiki&amp;#039; VM.&lt;br /&gt;
&lt;br /&gt;
Settings-&amp;gt; USB-&amp;gt; Add new USB Filter with all fields set to the values of the selected USB device&lt;br /&gt;
&lt;br /&gt;
and select the mote to be added. You will have to restart the VM for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
===== Problem running Cooja =====&lt;br /&gt;
If you have a problem regarding using the correct version of Java, please check that your default Java compiler is set correctly. You can use the following command:&lt;br /&gt;
&lt;br /&gt;
  sudo update-alternatives --config java&lt;br /&gt;
&lt;br /&gt;
===== Problem with compiling in Cooja =====&lt;br /&gt;
If you get an error in the linking there may be 2 possible places u need to check to correct them.&lt;br /&gt;
&lt;br /&gt;
            LD        example-netflood.sky&lt;br /&gt;
            /usr/lib/gcc/msp430/4.6.3/../../../../msp430/lib/mmpy-16/libc.a(rand.o):(.debug_info+0xd3): &lt;br /&gt;
            relocation truncated to fit: R_MSP430_16_BYTE against `no symbol&amp;#039;&lt;br /&gt;
            collect2: ld returned 1 exit status&lt;br /&gt;
            make: *** [example-netflood.sky] Error 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, check the line near 132 in file : contiki/cpu/msp430/Makefile.msp430&lt;br /&gt;
&lt;br /&gt;
which looks like the following&lt;br /&gt;
&lt;br /&gt;
         CFLAGSNO = -Wall -mmcu=$(CC_MCU) -g $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
and delete the option “-g”.&lt;br /&gt;
&lt;br /&gt;
The line should look like :&lt;br /&gt;
&lt;br /&gt;
        CFLAGSNO = -Wall -mmcu=$(CC_MCU) $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
Use the second one if the first doesnot work.&lt;br /&gt;
&lt;br /&gt;
Second one is go to the Makefile of the currently compiling program and remove the line which looks similar to the following.&lt;br /&gt;
&lt;br /&gt;
        CFLAGS += -g&lt;br /&gt;
==== Attribute Error while interfacing with Python ====&lt;br /&gt;
After installing sky-shell on the tmote sky, if you encounter the following error while running &amp;#039;python serial.py&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/sky-shell$ python serial.py&lt;br /&gt;
  Traceback (most recent call last):&lt;br /&gt;
    File &amp;quot;serial.py&amp;quot;, line 2, in &amp;lt;module&amp;gt;&lt;br /&gt;
      import serial&lt;br /&gt;
    File &amp;quot;/home/user/contiki/examples/sky-shell/serial.py&amp;quot; , line 3 , in &amp;lt;module&amp;gt;&lt;br /&gt;
      ser = serial.Serial(&lt;br /&gt;
  AttributeError: &amp;#039;module&amp;#039; object has no attribute &amp;#039;Serial&amp;#039;&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Cooja_Simulator&amp;diff=1723</id>
		<title>Cooja Simulator</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Cooja_Simulator&amp;diff=1723"/>
				<updated>2016-07-21T23:56:17Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial aims at introducing the Cooja Simulator and guiding the reader in a simple debugging exercise. We are going to work with Hello World example for the debugging process. You can also study the [[Hello_World]] tutorial to get familiar with its source code.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
* How to run Cooja Simulator.&lt;br /&gt;
* How to debug an application using Cooja Simulator.&lt;br /&gt;
&lt;br /&gt;
== Relevant Directories ==&lt;br /&gt;
&lt;br /&gt;
* /contiki/tools/cooja/ - This folder has Cooja Simulator source code. You can run Cooja inside this directory.&lt;br /&gt;
* /contiki/examples/hello-world/ - This has the source code of Hello World example.&lt;br /&gt;
&lt;br /&gt;
== Running Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
Cooja Simulator is a network simulator specifically designed for Wireless Sensor Networks. A summary of how Cooja executes binaries of different platforms (different types of nodes) and a few details about its structure can be found here:[https://github.com/contiki-os/contiki/wiki/An-Introduction-to-Cooja#Create_a_Hello_World_simulation].&lt;br /&gt;
&lt;br /&gt;
The simple way of running Cooja is executing it inside its own directory (we will see later how to execute Cooja from any working directory):&lt;br /&gt;
&lt;br /&gt;
 cd contiki/tools/cooja&lt;br /&gt;
 ant run&lt;br /&gt;
&lt;br /&gt;
We you execute Cooja the following window pops up.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-1.png|center|450px]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new simulation ===&lt;br /&gt;
&lt;br /&gt;
In the File menu you can start a new simulation or open an existing one. At this moment we will start a new one. You should select: File &amp;gt; New simulation... The following window should show up.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-2.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;#039;&amp;#039;Simulation name&amp;#039;&amp;#039; box you should enter an identifier for the new simulation, and in &amp;#039;&amp;#039;Advanced settings&amp;#039;&amp;#039; you can choose parameters of the simulation such as Radio medium, node startup delay and random seed generation. We are going to create a simulation called &amp;quot;First Cooja Sim&amp;quot;, as shown above.&lt;br /&gt;
&lt;br /&gt;
After creating a new simulation, Cooja&amp;#039;s window is filled with the main simulating tools, as shown in the next image.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-3.png|center|650px]]&lt;br /&gt;
&lt;br /&gt;
Here we briefly describe the functionalities of each tool:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Network&amp;#039;&amp;#039;&amp;#039; - Shows the location of each node in the network. Can be used to visualize the status of each node, including LEDs, mote IDs, addresses, lof outputs, etc. Initially this window is empty and we need to populate it with our sensors.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039;&amp;#039; - This panel is used to Start, Pause, Reload or execute Steps of the simulation. It shows the time of execution and the speed of simulation. It means that we can run the events several times faster than it would take in real-time execution.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Notes&amp;#039;&amp;#039;&amp;#039; - This is a simple notepad for taking notes about the simulation.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Mote output&amp;#039;&amp;#039;&amp;#039; - Shows all output of serial interface of the nodes. It is possible to enable one window of Mote output for each node in the simulation.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Timeline&amp;#039;&amp;#039;&amp;#039; - Simulation timeline where messages and events such as channel change, LEDs change, log outputs, etc are shown.&lt;br /&gt;
&lt;br /&gt;
In addition to the default tools, it is possible to exhibit other tools such as &amp;#039;&amp;#039;&amp;#039;Breakpoints&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Radio messages&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Script editor&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Buffer view&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Mote duty cycle&amp;#039;&amp;#039;&amp;#039;, which can be enable in the &amp;#039;&amp;#039;Tools&amp;#039;&amp;#039; menu.&lt;br /&gt;
&lt;br /&gt;
=== Creating a new mote type ===&lt;br /&gt;
&lt;br /&gt;
You need to create a new mote type before starting any simulation. You can do this in the menu &amp;#039;&amp;#039;&amp;#039;Motes&amp;#039;&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;&amp;#039;Add motes&amp;#039;&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;&amp;#039;Create new motes type&amp;#039;&amp;#039;&amp;#039;. Let&amp;#039;s select &amp;#039;&amp;#039;&amp;#039;Sky mote&amp;#039;&amp;#039;&amp;#039; in order to create a mote of the same type as the used Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
The window that shows up (see below) asks for the &amp;#039;&amp;#039;&amp;#039;Description&amp;#039;&amp;#039;&amp;#039; of the new mote type and the &amp;#039;&amp;#039;&amp;#039;Contiki process / Firmware&amp;#039;&amp;#039;&amp;#039;. You can name your mote type as &amp;#039;&amp;#039;First mote type&amp;#039;&amp;#039; and you can select the firmware that will be used during the simulation using the &amp;#039;&amp;#039;Browse&amp;#039;&amp;#039; button. After selecting the desired firmware you can test the compilation click the &amp;#039;&amp;#039;Compile&amp;#039;&amp;#039; button. In this example we will use the Hello World fimware, typically located at &amp;#039;&amp;#039;/contiki/examples/hello-world/hello-world.c&amp;#039;&amp;#039;. If the compiling process is successed, you will see a final message: &amp;#039;&amp;#039;LD hello-world.sky&amp;#039;&amp;#039; in the Compilation output tab.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-4.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Adding motes and running the simulation ===&lt;br /&gt;
&lt;br /&gt;
After successfully compiling the firmware in the last step you should click on &amp;#039;&amp;#039;Create&amp;#039;&amp;#039; button (see figure above). A new mote type will be created and you will be able to add a few nodes of that same type in your simulation. You will see the window shown below, where you will be able to set the number of nodes that will be created and specify their positioning. In this example we are going to create 3 new nodes and they will have random positioning.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-5.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
=== Saving simulation file ===&lt;br /&gt;
&lt;br /&gt;
The simulation configuration and parameters such as number of nodes, type of nodes, firmware used, location of nodes, etc. can be stored in a file for future simulations. You can save your simulation configuration in &amp;#039;&amp;#039;File&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;Save simulation as...&amp;#039;&amp;#039;. The generated file has extension &amp;quot;.csc&amp;quot;. In the case of Hello World firmware there already exist a .csc file inside &amp;#039;&amp;#039;contiki/examples/hello-world&amp;#039;&amp;#039;, called hello-world-example.csc, which contains 2 nodes. We are going to use this pre-existing Cooja file to show how to debug an application.&lt;br /&gt;
&lt;br /&gt;
== Debugging with Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
The easiest way to debug an application is to initially create a proper .csc simulation file, as described above. Then, inside the folder with the simulation file and all firmware source code (.c and .h files), you need to execute the following command.&lt;br /&gt;
&lt;br /&gt;
 make TARGET=cooja &amp;lt;simulation_file&amp;gt;.csc&lt;br /&gt;
&lt;br /&gt;
The command above will initialize Cooja Simulator loaded with the desired simulation file and will make Cooja recognized the source code of the application we intend to debug. In our case we are going to simulate and debug the Hello Worls application, so we need to go into /contiki/examples/hello-world folder and execute the command &amp;#039;&amp;#039;make TARGET=cooja hello-world-example.csc&amp;#039;&amp;#039;. The window shown below should be displayed.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-6.png|center|400px]]&lt;br /&gt;
&lt;br /&gt;
If we click on &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; button the simulation begins and we can see both nodes printing out log messages on the &amp;#039;&amp;#039;&amp;#039;Mote output&amp;#039;&amp;#039;&amp;#039; window.&lt;br /&gt;
&lt;br /&gt;
All debugging tools can be accessed by right-clicking on a node and selecting &amp;#039;&amp;#039;Mote tools for Sky&amp;#039;&amp;#039; in the pop-up menu. The two main debugging tools that we are going to use are: &amp;#039;&amp;#039;Msp Code Watcher&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Msp Stack Watcher&amp;#039;&amp;#039;. The first one can be used for analysing the source code of the application in a step-by-step fashion, with the possibility of setting breakpoints. The second tool is used to read and write the variables used throughout the execution.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;Msp Code Watcher&amp;#039;&amp;#039; tool can be seen below. &lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Pedro&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Cooja_Simulator&amp;diff=1722</id>
		<title>Cooja Simulator</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Cooja_Simulator&amp;diff=1722"/>
				<updated>2016-07-21T23:55:39Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial aims at introducing the Cooja Simulator and guiding the reader in a simple debugging exercise. We are going to work with Hello World example for the debugging process. You can also study the [[Hello_World]] tutorial to get familiar with its source code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
* How to run Cooja Simulator.&lt;br /&gt;
* How to debug an application using Cooja Simulator.&lt;br /&gt;
&lt;br /&gt;
== Relevant Directories ==&lt;br /&gt;
&lt;br /&gt;
* /contiki/tools/cooja/ - This folder has Cooja Simulator source code. You can run Cooja inside this directory.&lt;br /&gt;
* /contiki/examples/hello-world/ - This has the source code of Hello World example.&lt;br /&gt;
&lt;br /&gt;
== Running Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
Cooja Simulator is a network simulator specifically designed for Wireless Sensor Networks. A summary of how Cooja executes binaries of different platforms (different types of nodes) and a few details about its structure can be found here:[https://github.com/contiki-os/contiki/wiki/An-Introduction-to-Cooja#Create_a_Hello_World_simulation].&lt;br /&gt;
&lt;br /&gt;
The simple way of running Cooja is executing it inside its own directory (we will see later how to execute Cooja from any working directory):&lt;br /&gt;
&lt;br /&gt;
 cd contiki/tools/cooja&lt;br /&gt;
 ant run&lt;br /&gt;
&lt;br /&gt;
We you execute Cooja the following window pops up.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-1.png|center|450px]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new simulation ===&lt;br /&gt;
&lt;br /&gt;
In the File menu you can start a new simulation or open an existing one. At this moment we will start a new one. You should select: File &amp;gt; New simulation... The following window should show up.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-2.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;#039;&amp;#039;Simulation name&amp;#039;&amp;#039; box you should enter an identifier for the new simulation, and in &amp;#039;&amp;#039;Advanced settings&amp;#039;&amp;#039; you can choose parameters of the simulation such as Radio medium, node startup delay and random seed generation. We are going to create a simulation called &amp;quot;First Cooja Sim&amp;quot;, as shown above.&lt;br /&gt;
&lt;br /&gt;
After creating a new simulation, Cooja&amp;#039;s window is filled with the main simulating tools, as shown in the next image.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-3.png|center|650px]]&lt;br /&gt;
&lt;br /&gt;
Here we briefly describe the functionalities of each tool:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Network&amp;#039;&amp;#039;&amp;#039; - Shows the location of each node in the network. Can be used to visualize the status of each node, including LEDs, mote IDs, addresses, lof outputs, etc. Initially this window is empty and we need to populate it with our sensors.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039;&amp;#039; - This panel is used to Start, Pause, Reload or execute Steps of the simulation. It shows the time of execution and the speed of simulation. It means that we can run the events several times faster than it would take in real-time execution.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Notes&amp;#039;&amp;#039;&amp;#039; - This is a simple notepad for taking notes about the simulation.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Mote output&amp;#039;&amp;#039;&amp;#039; - Shows all output of serial interface of the nodes. It is possible to enable one window of Mote output for each node in the simulation.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Timeline&amp;#039;&amp;#039;&amp;#039; - Simulation timeline where messages and events such as channel change, LEDs change, log outputs, etc are shown.&lt;br /&gt;
&lt;br /&gt;
In addition to the default tools, it is possible to exhibit other tools such as &amp;#039;&amp;#039;&amp;#039;Breakpoints&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Radio messages&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Script editor&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Buffer view&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Mote duty cycle&amp;#039;&amp;#039;&amp;#039;, which can be enable in the &amp;#039;&amp;#039;Tools&amp;#039;&amp;#039; menu.&lt;br /&gt;
&lt;br /&gt;
=== Creating a new mote type ===&lt;br /&gt;
&lt;br /&gt;
You need to create a new mote type before starting any simulation. You can do this in the menu &amp;#039;&amp;#039;&amp;#039;Motes&amp;#039;&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;&amp;#039;Add motes&amp;#039;&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;&amp;#039;Create new motes type&amp;#039;&amp;#039;&amp;#039;. Let&amp;#039;s select &amp;#039;&amp;#039;&amp;#039;Sky mote&amp;#039;&amp;#039;&amp;#039; in order to create a mote of the same type as the used Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
The window that shows up (see below) asks for the &amp;#039;&amp;#039;&amp;#039;Description&amp;#039;&amp;#039;&amp;#039; of the new mote type and the &amp;#039;&amp;#039;&amp;#039;Contiki process / Firmware&amp;#039;&amp;#039;&amp;#039;. You can name your mote type as &amp;#039;&amp;#039;First mote type&amp;#039;&amp;#039; and you can select the firmware that will be used during the simulation using the &amp;#039;&amp;#039;Browse&amp;#039;&amp;#039; button. After selecting the desired firmware you can test the compilation click the &amp;#039;&amp;#039;Compile&amp;#039;&amp;#039; button. In this example we will use the Hello World fimware, typically located at &amp;#039;&amp;#039;/contiki/examples/hello-world/hello-world.c&amp;#039;&amp;#039;. If the compiling process is successed, you will see a final message: &amp;#039;&amp;#039;LD hello-world.sky&amp;#039;&amp;#039; in the Compilation output tab.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-4.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Adding motes and running the simulation ===&lt;br /&gt;
&lt;br /&gt;
After successfully compiling the firmware in the last step you should click on &amp;#039;&amp;#039;Create&amp;#039;&amp;#039; button (see figure above). A new mote type will be created and you will be able to add a few nodes of that same type in your simulation. You will see the window shown below, where you will be able to set the number of nodes that will be created and specify their positioning. In this example we are going to create 3 new nodes and they will have random positioning.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-5.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
=== Saving simulation file ===&lt;br /&gt;
&lt;br /&gt;
The simulation configuration and parameters such as number of nodes, type of nodes, firmware used, location of nodes, etc. can be stored in a file for future simulations. You can save your simulation configuration in &amp;#039;&amp;#039;File&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;Save simulation as...&amp;#039;&amp;#039;. The generated file has extension &amp;quot;.csc&amp;quot;. In the case of Hello World firmware there already exist a .csc file inside &amp;#039;&amp;#039;contiki/examples/hello-world&amp;#039;&amp;#039;, called hello-world-example.csc, which contains 2 nodes. We are going to use this pre-existing Cooja file to show how to debug an application.&lt;br /&gt;
&lt;br /&gt;
== Debugging with Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
The easiest way to debug an application is to initially create a proper .csc simulation file, as described above. Then, inside the folder with the simulation file and all firmware source code (.c and .h files), you need to execute the following command.&lt;br /&gt;
&lt;br /&gt;
 make TARGET=cooja &amp;lt;simulation_file&amp;gt;.csc&lt;br /&gt;
&lt;br /&gt;
The command above will initialize Cooja Simulator loaded with the desired simulation file and will make Cooja recognized the source code of the application we intend to debug. In our case we are going to simulate and debug the Hello Worls application, so we need to go into /contiki/examples/hello-world folder and execute the command &amp;#039;&amp;#039;make TARGET=cooja hello-world-example.csc&amp;#039;&amp;#039;. The window shown below should be displayed.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-6.png|center|400px]]&lt;br /&gt;
&lt;br /&gt;
If we click on &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; button the simulation begins and we can see both nodes printing out log messages on the &amp;#039;&amp;#039;&amp;#039;Mote output&amp;#039;&amp;#039;&amp;#039; window.&lt;br /&gt;
&lt;br /&gt;
All debugging tools can be accessed by right-clicking on a node and selecting &amp;#039;&amp;#039;Mote tools for Sky&amp;#039;&amp;#039; in the pop-up menu. The two main debugging tools that we are going to use are: &amp;#039;&amp;#039;Msp Code Watcher&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Msp Stack Watcher&amp;#039;&amp;#039;. The first one can be used for analysing the source code of the application in a step-by-step fashion, with the possibility of setting breakpoints. The second tool is used to read and write the variables used throughout the execution.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;Msp Code Watcher&amp;#039;&amp;#039; tool can be seen below. &lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Pedro&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

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

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Cooja_Simulator&amp;diff=1720</id>
		<title>Cooja Simulator</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Cooja_Simulator&amp;diff=1720"/>
				<updated>2016-07-21T23:48:17Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This tutorial aims at introducing the Cooja Simulator and guiding the reader in a simple debugging exercise. We are going to work with Hello World example for the debugging process. You can also study the [[Hello_World]] tutorial to get familiar with its source code.&lt;br /&gt;
&lt;br /&gt;
[[Collect_View#Using_Cooja_Simulator]]&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
* How to run Cooja Simulator.&lt;br /&gt;
* How to debug an application using Cooja Simulator.&lt;br /&gt;
&lt;br /&gt;
== Relevant Directories ==&lt;br /&gt;
&lt;br /&gt;
* /contiki/tools/cooja/ - This folder has Cooja Simulator source code. You can run Cooja inside this directory.&lt;br /&gt;
* /contiki/examples/hello-world/ - This has the source code of Hello World example.&lt;br /&gt;
&lt;br /&gt;
== Running Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
Cooja Simulator is a network simulator specifically designed for Wireless Sensor Networks. A summary of how Cooja executes binaries of different platforms (different types of nodes) and a few details about its structure can be found here:[https://github.com/contiki-os/contiki/wiki/An-Introduction-to-Cooja#Create_a_Hello_World_simulation].&lt;br /&gt;
&lt;br /&gt;
The simple way of running Cooja is executing it inside its own directory (we will see later how to execute Cooja from any working directory):&lt;br /&gt;
&lt;br /&gt;
 cd contiki/tools/cooja&lt;br /&gt;
 ant run&lt;br /&gt;
&lt;br /&gt;
We you execute Cooja the following window pops up.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-1.png|center|450px]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new simulation ===&lt;br /&gt;
&lt;br /&gt;
In the File menu you can start a new simulation or open an existing one. At this moment we will start a new one. You should select: File &amp;gt; New simulation... The following window should show up.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-2.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;#039;&amp;#039;Simulation name&amp;#039;&amp;#039; box you should enter an identifier for the new simulation, and in &amp;#039;&amp;#039;Advanced settings&amp;#039;&amp;#039; you can choose parameters of the simulation such as Radio medium, node startup delay and random seed generation. We are going to create a simulation called &amp;quot;First Cooja Sim&amp;quot;, as shown above.&lt;br /&gt;
&lt;br /&gt;
After creating a new simulation, Cooja&amp;#039;s window is filled with the main simulating tools, as shown in the next image.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-3.png|center|650px]]&lt;br /&gt;
&lt;br /&gt;
Here we briefly describe the functionalities of each tool:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Network&amp;#039;&amp;#039;&amp;#039; - Shows the location of each node in the network. Can be used to visualize the status of each node, including LEDs, mote IDs, addresses, lof outputs, etc. Initially this window is empty and we need to populate it with our sensors.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039;&amp;#039; - This panel is used to Start, Pause, Reload or execute Steps of the simulation. It shows the time of execution and the speed of simulation. It means that we can run the events several times faster than it would take in real-time execution.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Notes&amp;#039;&amp;#039;&amp;#039; - This is a simple notepad for taking notes about the simulation.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Mote output&amp;#039;&amp;#039;&amp;#039; - Shows all output of serial interface of the nodes. It is possible to enable one window of Mote output for each node in the simulation.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Timeline&amp;#039;&amp;#039;&amp;#039; - Simulation timeline where messages and events such as channel change, LEDs change, log outputs, etc are shown.&lt;br /&gt;
&lt;br /&gt;
In addition to the default tools, it is possible to exhibit other tools such as &amp;#039;&amp;#039;&amp;#039;Breakpoints&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Radio messages&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Script editor&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Buffer view&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Mote duty cycle&amp;#039;&amp;#039;&amp;#039;, which can be enable in the &amp;#039;&amp;#039;Tools&amp;#039;&amp;#039; menu.&lt;br /&gt;
&lt;br /&gt;
=== Creating a new mote type ===&lt;br /&gt;
&lt;br /&gt;
You need to create a new mote type before starting any simulation. You can do this in the menu &amp;#039;&amp;#039;&amp;#039;Motes&amp;#039;&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;&amp;#039;Add motes&amp;#039;&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;&amp;#039;Create new motes type&amp;#039;&amp;#039;&amp;#039;. Let&amp;#039;s select &amp;#039;&amp;#039;&amp;#039;Sky mote&amp;#039;&amp;#039;&amp;#039; in order to create a mote of the same type as the used Tmote Sky.&lt;br /&gt;
&lt;br /&gt;
The window that shows up (see below) asks for the &amp;#039;&amp;#039;&amp;#039;Description&amp;#039;&amp;#039;&amp;#039; of the new mote type and the &amp;#039;&amp;#039;&amp;#039;Contiki process / Firmware&amp;#039;&amp;#039;&amp;#039;. You can name your mote type as &amp;#039;&amp;#039;First mote type&amp;#039;&amp;#039; and you can select the firmware that will be used during the simulation using the &amp;#039;&amp;#039;Browse&amp;#039;&amp;#039; button. After selecting the desired firmware you can test the compilation click the &amp;#039;&amp;#039;Compile&amp;#039;&amp;#039; button. In this example we will use the Hello World fimware, typically located at &amp;#039;&amp;#039;/contiki/examples/hello-world/hello-world.c&amp;#039;&amp;#039;. If the compiling process is successed, you will see a final message: &amp;#039;&amp;#039;LD hello-world.sky&amp;#039;&amp;#039; in the Compilation output tab.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-4.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Adding motes and running the simulation ===&lt;br /&gt;
&lt;br /&gt;
After successfully compiling the firmware in the last step you should click on &amp;#039;&amp;#039;Create&amp;#039;&amp;#039; button (see figure above). A new mote type will be created and you will be able to add a few nodes of that same type in your simulation. You will see the window shown below, where you will be able to set the number of nodes that will be created and specify their positioning. In this example we are going to create 3 new nodes and they will have random positioning.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-5.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
=== Saving simulation file ===&lt;br /&gt;
&lt;br /&gt;
The simulation configuration and parameters such as number of nodes, type of nodes, firmware used, location of nodes, etc. can be stored in a file for future simulations. You can save your simulation configuration in &amp;#039;&amp;#039;File&amp;#039;&amp;#039; &amp;gt; &amp;#039;&amp;#039;Save simulation as...&amp;#039;&amp;#039;. The generated file has extension &amp;quot;.csc&amp;quot;. In the case of Hello World firmware there already exist a .csc file inside &amp;#039;&amp;#039;contiki/examples/hello-world&amp;#039;&amp;#039;, called hello-world-example.csc, which contains 2 nodes. We are going to use this pre-existing Cooja file to show how to debug an application.&lt;br /&gt;
&lt;br /&gt;
== Debugging with Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
The easiest way to debug an application is to initially create a proper .csc simulation file, as described above. Then, inside the folder with the simulation file and all firmware source code (.c and .h files), you need to execute the following command.&lt;br /&gt;
&lt;br /&gt;
 make TARGET=cooja &amp;lt;simulation_file&amp;gt;.csc&lt;br /&gt;
&lt;br /&gt;
The command above will initialize Cooja Simulator loaded with the desired simulation file and will make Cooja recognized the source code of the application we intend to debug. In our case we are going to simulate and debug the Hello Worls application, so we need to go into /contiki/examples/hello-world folder and execute the command &amp;#039;&amp;#039;make TARGET=cooja hello-world-example.csc&amp;#039;&amp;#039;. The window shown below should be displayed.&lt;br /&gt;
&lt;br /&gt;
[[File:cooja-6.png|center|400px]]&lt;br /&gt;
&lt;br /&gt;
If we click on &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; button the simulation begins and we can see both nodes printing out log messages on the &amp;#039;&amp;#039;&amp;#039;Mote output&amp;#039;&amp;#039;&amp;#039; window.&lt;br /&gt;
&lt;br /&gt;
All debugging tools can be accessed by right-clicking on a node and selecting &amp;#039;&amp;#039;Mote tools for Sky&amp;#039;&amp;#039; in the pop-up menu. The two main debugging tools that we are going to use are: &amp;#039;&amp;#039;Msp Code Watcher&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Msp Stack Watcher&amp;#039;&amp;#039;. The first one can be used for analysing the source code of the application in a step-by-step fashion, with the possibility of setting breakpoints. The second tool is used to read and write the variables used throughout the execution.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;Msp Code Watcher&amp;#039;&amp;#039; tool can be seen below. &lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Pedro&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Collect_View&amp;diff=1711</id>
		<title>Collect View</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Collect_View&amp;diff=1711"/>
				<updated>2016-07-08T01:14:59Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: /* Step 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This exercise is to familiarize the user with the collect view app provided in the Contiki OS source code. It basically involves a sink mote and one or more than one source motes. The source motes send their sensor, network, power and node properties to the sink. A java app presents all this compiled data in a graphical manner.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
* How to upload an introductory code for UDP source and sink.&lt;br /&gt;
* How to program nodes and collect data through the collect-view GUI.&lt;br /&gt;
* Things to see on the collect-view GUI.&lt;br /&gt;
&lt;br /&gt;
== Relevant Directories ==&lt;br /&gt;
&lt;br /&gt;
* /contiki/examples/collect/ - This has the shell code for collect view and the various targets.&lt;br /&gt;
* /contiki/examples/ipv6/rpl-collect/ - This has the codes which are to be uploaded to the source and sink motes for UDP communication.&lt;br /&gt;
* /contiki/tools/collect-view/ - This contains the java file for the collect view GUI.&lt;br /&gt;
* /contiki/apps/collect-view/ - This contains the codes corresponding to the targets mentioned in the examples folder.&lt;br /&gt;
&lt;br /&gt;
== Connect the Tmote Sky ==&lt;br /&gt;
&lt;br /&gt;
Before continuing with the tutorial, plug 2 Tmote Sky into the computer&amp;#039;s USB port, one for the source and the other for the sink.&lt;br /&gt;
&lt;br /&gt;
In order to transfer the ownership of the contiki directories use the following command. &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;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; sudo chown :user /dev/ttyUSB1 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using the Source Code ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Go to /examples/collect/ directory.&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Now we need to program one mote as the sink and the other as source. We will use a predefined target called sky to upload the code in the motes.&lt;br /&gt;
&lt;br /&gt;
For sink:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky MOTES=/dev/ttyUSB0 collect-view-shell.upload &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For source:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; make TARGET=sky MOTES=/dev/ttyUSB1 collect-view-shell.upload &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Now we would like to see the transfer and depiction of data on the collect-view GUI. For that to happen, go to /tools/collect-view directory and run &amp;quot;ant&amp;quot; to build the collect viewer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ant run &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039; - In order to edit GUI java files go to the /src directory.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
To view the data collected at the sink, go to the generated /tools/collect-view/dist and run - &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; java -jar collect-view.jar /dev/ttyUSB0 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
In the collect window from the Tools menu, select &amp;quot;Run Init script&amp;quot; and in the &amp;quot;Node Control&amp;quot; tab and click on &amp;quot;Start Collect.&amp;quot; This will enable the communication between the source and the sender and you will be able to see the received statistics in a graphical manner.&lt;br /&gt;
&lt;br /&gt;
== Using the GUI ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Once the motes are connected to the USB ports, go to /tools/collect-view directory and run &amp;quot;ant&amp;quot; to build the collect viewer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt; ant run &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Press the &amp;quot;Program Nodes...&amp;quot; button as seen on the GUI.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Disconnect all except one node from the USB ports. Press the &amp;quot;Connect to serial&amp;quot; button. The disconnected motes should be connected to independent power sources.&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
&lt;br /&gt;
Now in order to collect various statistics, press &amp;quot;Send Collect&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
&lt;br /&gt;
Set the various &amp;quot;Collect Settings&amp;quot; based on how frequently the data is to be collected and then press &amp;quot;Send command to nodes&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
&lt;br /&gt;
Now go through the other tabs on the GUI to study and analyze the statistics plotted.&lt;br /&gt;
&lt;br /&gt;
== Things to See on the GUI ==&lt;br /&gt;
&lt;br /&gt;
=== Topological graphs ===&lt;br /&gt;
&lt;br /&gt;
* Sensor Map&lt;br /&gt;
* Network Graph&lt;br /&gt;
&lt;br /&gt;
=== Sensor Related Plots ===&lt;br /&gt;
&lt;br /&gt;
These are subject to the availability of a particular type of sensor on the motes.&lt;br /&gt;
&lt;br /&gt;
* Temperature Sensor - Average Temperatue and Temperature.&lt;br /&gt;
* Humidity Sensor - Relative Humidity.&lt;br /&gt;
* Battery Sensor - Battery Indicator and Battery Voltage.&lt;br /&gt;
* Light Sensor - Light 1 and Light 2.&lt;br /&gt;
&lt;br /&gt;
=== Network Metrics Related Plots ===&lt;br /&gt;
&lt;br /&gt;
* Neighbours&lt;br /&gt;
* Beacon Interval&lt;br /&gt;
* Network Hops &lt;br /&gt;
** Over Time&lt;br /&gt;
** Per Node&lt;br /&gt;
* Router Metric (Over Time)&lt;br /&gt;
** Instantaneous&lt;br /&gt;
** Average&lt;br /&gt;
* ETX (Over Time)&lt;br /&gt;
* Next Hop (Over Time)&lt;br /&gt;
* Latency&lt;br /&gt;
* Lost Packets (Over Time)&lt;br /&gt;
* Received Packets&lt;br /&gt;
** Over Time&lt;br /&gt;
** Per Node&lt;br /&gt;
** Every 5 min&lt;br /&gt;
&lt;br /&gt;
=== Power Related Plots ===&lt;br /&gt;
&lt;br /&gt;
* Average Power&lt;br /&gt;
* Instantaneous Power&lt;br /&gt;
* Power History&lt;br /&gt;
* Radio Duty Cycle&lt;br /&gt;
&lt;br /&gt;
=== Other Tabs ===&lt;br /&gt;
&lt;br /&gt;
* Node Info - This gives a summary of all the nodes and their statistics.&lt;br /&gt;
* Serial Console - The user can interact directly with the mote, sending commands to read and transmit data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Primary contributors:&amp;#039;&amp;#039;&amp;#039; Bhavna, Deepanker, Nikhil, Rahul&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by: Deepanker&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1708</id>
		<title>Troubleshooting</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Troubleshooting&amp;diff=1708"/>
				<updated>2016-07-01T22:34:26Z</updated>
		
		<summary type="html">&lt;p&gt;Gugri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
===== Permission denied =====&lt;br /&gt;
If you try to connect to a mote and receive a permission error, you may need to add yourself to the dialout group. The error may look something like the following:&lt;br /&gt;
&lt;br /&gt;
 /home/user/contiki/tools/sky/serialdump-linux -b115200 /dev/ttyUSB0&lt;br /&gt;
 connecting to /dev/ttyUSB0 (115200)&lt;br /&gt;
 /dev/ttyUSB0: Permission denied&lt;br /&gt;
 make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Use the following command (replace &amp;lt;username&amp;gt; with your account):&lt;br /&gt;
&lt;br /&gt;
 sudo adduser &amp;lt;username&amp;gt; dialout&lt;br /&gt;
&lt;br /&gt;
-OR-&lt;br /&gt;
&lt;br /&gt;
 sudo usermod -a -G dialout &amp;lt;username&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These two commands are equivalent. They both will add username to the dialout group. &amp;#039;&amp;#039;&amp;#039;You will then have to re-login to or reboot your computer for the changes to take effect.&amp;#039;&amp;#039;&amp;#039; You should now have read/write permissions to your USB serial devices. It is not necessary to remove any packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Trying the following command which should give  the desired output&lt;br /&gt;
&lt;br /&gt;
  make TARGET=sky sky-motelist &lt;br /&gt;
&lt;br /&gt;
(sky can be replaced by the mote which is being used e.g z1)&lt;br /&gt;
&lt;br /&gt;
The desired output&lt;br /&gt;
&lt;br /&gt;
  ../../tools/sky/motelist-linux &lt;br /&gt;
  Reference  Device           Description &lt;br /&gt;
  ---------- ---------------- --------------------------------------------- &lt;br /&gt;
  M4A7J5HF   /dev/ttyUSB0     Moteiv tmote sky &lt;br /&gt;
&lt;br /&gt;
This means it is a common serial port connection problem with Ubuntu 12.04 LTS.&lt;br /&gt;
&lt;br /&gt;
To resolve the issue do the following.&lt;br /&gt;
 &lt;br /&gt;
  sudo apt-get remove modemmanager&lt;br /&gt;
  sudo adduser $USER dialout (or)&lt;br /&gt;
  sudo usermod -a -G dialout $USER // adds the user to the dialout&lt;br /&gt;
  // replace $USER by the username&lt;br /&gt;
  sudo reboot&lt;br /&gt;
  id -Gn&lt;br /&gt;
&lt;br /&gt;
And check now if the device is attached to the dialout user group.&lt;br /&gt;
&lt;br /&gt;
  ls -l /dev/ttyUSB0&lt;br /&gt;
  crw-rw---- 1 root dialout 188, 0 Mar  5 19:58 /dev/ttyUSB0 &lt;br /&gt;
&lt;br /&gt;
There is no need to mess with dev rules or permissions. &lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Issue with make login =====&lt;br /&gt;
If you are trying to execute the serial-dump application (contiki/tools/sky/serialdump-linux) and see the message: &amp;quot;No such file or directory&amp;quot; or &amp;quot;Command not found&amp;quot;, it means that you are running in a 64-bit operating system that does not have proper 32-bit libraries installed. Since serialdump-linux is a pre-compiled 32-bit tool you need to execute the following command to install the necessary libraries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install ia32-libs&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On newer versions of Ubuntu, try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;sudo apt-get install libc6-i386&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work &lt;br /&gt;
&lt;br /&gt;
Then, try few commands like:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
&lt;br /&gt;
The output look similar to the following:&lt;br /&gt;
&lt;br /&gt;
  ldd serialdump-linux&lt;br /&gt;
        linux-gate.so.1 =&amp;gt;  (0xf772d000)&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib32/libc.so.6 (0xf75b4000)&lt;br /&gt;
        /lib/ld-linux.so.2 (0xf772e000)&lt;br /&gt;
&lt;br /&gt;
Then it means that you have to install 32-bit packages. &lt;br /&gt;
Remember to add i386 architecture or you won&amp;#039;t be able to install 32-bit packages:&lt;br /&gt;
  sudo dpkg --add-architecture i386&lt;br /&gt;
  sudo apt-get update&lt;br /&gt;
  sudo apt-get install ia32-libs&lt;br /&gt;
&lt;br /&gt;
===== Input/output error =====&lt;br /&gt;
If you try to connect to a mote and receive an Input/output error as shown below,&lt;br /&gt;
&lt;br /&gt;
  /contiki/examples/hello-world$ sudo -s make login&lt;br /&gt;
  using saved target &amp;#039;sky&amp;#039;&lt;br /&gt;
  ../../tools/sky/serialdump-linux -b115200&lt;br /&gt;
  connecting to /dev/ttyS0 (115200) [OK]&lt;br /&gt;
  could not get options: Input/output error&lt;br /&gt;
  make: *** [login] Error 255&lt;br /&gt;
&lt;br /&gt;
Then it means that VirtualBox cannot detect the mote connected to the USB interface.&lt;br /&gt;
&lt;br /&gt;
This issue can be fixed by making a minor change in the VM settings.&lt;br /&gt;
&lt;br /&gt;
In the VirtualBox Manager, select the &amp;#039;Contiki&amp;#039; VM.&lt;br /&gt;
&lt;br /&gt;
Settings-&amp;gt; USB-&amp;gt; Add new USB Filter&lt;br /&gt;
&lt;br /&gt;
and select the mote to be added.&lt;br /&gt;
&lt;br /&gt;
===== Problem running Cooja =====&lt;br /&gt;
If you have a problem regarding using the correct version of Java, please check that your default Java compiler is set correctly. You can use the following command:&lt;br /&gt;
&lt;br /&gt;
  sudo update-alternatives --config java&lt;br /&gt;
&lt;br /&gt;
===== Problem with compling in Cooja =====&lt;br /&gt;
If you get an error in the linking there may be 2 possible places u need to check to correct them.&lt;br /&gt;
&lt;br /&gt;
            LD        example-netflood.sky&lt;br /&gt;
            /usr/lib/gcc/msp430/4.6.3/../../../../msp430/lib/mmpy-16/libc.a(rand.o):(.debug_info+0xd3): &lt;br /&gt;
            relocation truncated to fit: R_MSP430_16_BYTE against `no symbol&amp;#039;&lt;br /&gt;
            collect2: ld returned 1 exit status&lt;br /&gt;
            make: *** [example-netflood.sky] Error 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First, check the line near 132 in file : contiki/cpu/msp430/Makefile.msp430&lt;br /&gt;
&lt;br /&gt;
which looks like the following&lt;br /&gt;
&lt;br /&gt;
         CFLAGSNO = -Wall -mmcu=$(CC_MCU) -g $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
and delete the option “-g”.&lt;br /&gt;
&lt;br /&gt;
The line should look like :&lt;br /&gt;
&lt;br /&gt;
        CFLAGSNO = -Wall -mmcu=$(CC_MCU) $(CFLAGSWERROR)&lt;br /&gt;
&lt;br /&gt;
Use the second one if the first doesnot work.&lt;br /&gt;
&lt;br /&gt;
Second one is go to the Makefile of the currently compling program and remove the line which looks similar to the following.&lt;br /&gt;
&lt;br /&gt;
        CFLAGS += -g&lt;/div&gt;</summary>
		<author><name>Gugri</name></author>	</entry>

	</feed>