<?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=Paisamar</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=Paisamar"/>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php/Special:Contributions/Paisamar"/>
		<updated>2026-05-11T15:33:46Z</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=1862</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1862"/>
				<updated>2016-11-04T19:10:15Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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]]&lt;br /&gt;
# [[Timers]]&lt;br /&gt;
# [[CFS-Coffee]]&lt;br /&gt;
# [[Cooja Simulator]]&lt;br /&gt;
# [[Network Stack]]&lt;br /&gt;
# [[RPL UDP]]&lt;br /&gt;
# [[Contiki Shell]]&lt;br /&gt;
&lt;br /&gt;
Need review&lt;br /&gt;
# [[RSS measurement]]&lt;br /&gt;
# [[Contiki Coffee File System]]&lt;br /&gt;
&lt;br /&gt;
Starting&lt;br /&gt;
# [[RPL objective function &amp;amp; simulation using DGRM model in cooja]]&lt;br /&gt;
# [[MAC protocols in ContikiOS]]&lt;br /&gt;
# [[RPL Border Router]]&lt;br /&gt;
# [[REST example running on Cooja and Sky motes]]&lt;br /&gt;
# [[Trickle library]]&lt;br /&gt;
# [[Packetbuffer Basics]]&lt;br /&gt;
# [[Antelope(Database Management System) - Contiki]]&lt;br /&gt;
# [[Mobility of Nodes in Cooja]]&lt;br /&gt;
# [[Contiki Programming Guide]]&lt;br /&gt;
# [[Analyse of a real 6LoWPAN network using a Contiki-based sniffer module]]&lt;br /&gt;
# [[Build your own application in Contiki]]&lt;br /&gt;
# [[Processes]] Yash&lt;br /&gt;
# [[RPL objective function modification and simulation in cooja]]&lt;br /&gt;
# [[Collect-view Code Details]] Pradipta&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_Border_Router&amp;diff=1861</id>
		<title>RPL Border Router</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_Border_Router&amp;diff=1861"/>
				<updated>2016-11-04T19:07:07Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction: ==&lt;br /&gt;
  &lt;br /&gt;
Border routers are routers that can be found at the edge of a network. Their function is to connect one network to another. In this tutorial we will learn how to run a simulation using the border router in Contiki 2.7. In the example which we will discuss in the rest of this tutorial the border router will be used to route data between a WSN (RPL network) and an external IP network.  &lt;br /&gt;
&lt;br /&gt;
[[File:Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Objective ==&lt;br /&gt;
  &lt;br /&gt;
The objective of this tutorial is to give you an understanding of the RPL Border Router code in Contiki 2.7 OS and learn how to simulate a network with a border router on Cooja &lt;br /&gt;
&lt;br /&gt;
At the end of the tutorial you would have learnt the following: &lt;br /&gt;
&lt;br /&gt;
1. Understanding the working of the rpl border router code &amp;lt;br&amp;gt;&lt;br /&gt;
2. Starting a simulation on Cooja simulator. &amp;lt;br&amp;gt; &lt;br /&gt;
3. Observing and validating the results &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code building blocks. ==&lt;br /&gt;
 &lt;br /&gt;
We will be using the following files &lt;br /&gt;
&lt;br /&gt;
1. border-router.c &amp;lt;br&amp;gt;&lt;br /&gt;
2. udp-server.c  (udp-client.c can also be used)&amp;lt;br&amp;gt;&lt;br /&gt;
3. slip-bridge.c (It contains callback function for processing a SLIP connection request) &amp;lt;br&amp;gt;&lt;br /&gt;
4. httpd-simple.c   (A simple web server forwarding page generation to a protothread)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
udp-server nodes will form a DAG with the border router set as the root. The border router will receive the prefix through a [SLIP][http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol] (Serial Line Interface Protocol) connection and it will be communicated to the rest of the nodes in the RPL network. &lt;br /&gt;
&lt;br /&gt;
Refer to the following code snippets in the file border-router.c In this piece of code the node configured as the border router waits for the prefix to be set. Once it receives the prefix, the border router is set as the root of the DAG after which it sets the prefix of the rest of the nodes in the network.  &lt;br /&gt;
 &lt;br /&gt;
 /* Request prefix until it has been received */ &lt;br /&gt;
  while(!prefix_set) { &lt;br /&gt;
    etimer_set(&amp;amp;et, CLOCK_SECOND); &lt;br /&gt;
    request_prefix(); &lt;br /&gt;
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&amp;amp;et)); &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id); &lt;br /&gt;
  if(dag != NULL) { &lt;br /&gt;
    rpl_set_prefix(dag, &amp;amp;prefix, 64); &lt;br /&gt;
    PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;); &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default the border router hosts a simple web page. However, this can be disabled by defining WEBSERVER as seen the code snippet below. This webpage is displayed when the IPv6 address of the border router is entered in the browser. Refer to the file httpd-simple.c for the following code snippet&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;PROCESS(border_router_process, &amp;quot;Border router process&amp;quot;);&lt;br /&gt;
#if WEBSERVER==0&lt;br /&gt;
/* No webserver */&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;border_router_process);&lt;br /&gt;
#elif WEBSERVER&amp;gt;1&lt;br /&gt;
/* Use an external webserver application */&lt;br /&gt;
#include &amp;quot;webserver-nogui.h&amp;quot;&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;border_router_process,&amp;amp;webserver_nogui_process); &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compiling the code ==&lt;br /&gt;
 &lt;br /&gt;
The code for RPL border router can be found at /contiki-2.7/examples/ipv6/rpl-border-router. Use the following command to compile the code for the border router &amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;pre&amp;gt;cd /contiki-2.7/examples/ipv6/rpl-border-router &lt;br /&gt;
make TARGET=sky. &amp;lt;/pre&amp;gt;   &lt;br /&gt;
Once this command has been successfully executed, a file named border-router.sky will be created. This file will be used to program one of the motes as the border router on Cooja.  &lt;br /&gt;
For the purpose of this tutorial we will  select  TMote Sky  as our target. &lt;br /&gt;
&lt;br /&gt;
In order to demonstrate the functionality of the border router we will create a network of nodes with the border router as the root. For creating such a network we will user the udp-server.c code.  &lt;br /&gt;
This code can be found at /contiki-2.7/examples/ipv6/rpl-udp . Use the following command to compile the code for rpl-udp &lt;br /&gt;
 &amp;lt;pre&amp;gt;cd /contiki-2.7/examples/ipv6/rpl-udp &lt;br /&gt;
make TARGET=sky &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once this command has been successfully executed a file named udp-server.sky will be created. This file will be used to program the remaining nodes in Cooja simulator. These nodes will form a DAG with the rpl border router as the root.&lt;br /&gt;
&lt;br /&gt;
== Testing on Cooja ==&lt;br /&gt;
 &lt;br /&gt;
Upon the successful completion of the above mentioned steps we are ready to create a simulation in Cooja.  &lt;br /&gt;
Start the Cooja simulator using the following command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /contiki-2.7/tools/cooja &lt;br /&gt;
ant run&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
When the GUI launches execute the following steps to create a simulation. &amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
1. From &amp;#039;File&amp;#039; select &amp;#039;New Simulation&amp;#039;. Select &amp;#039;UDGM&amp;#039;, enter the name of the simulation and click on &amp;#039;create&amp;#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
2. Click on &amp;#039;Motes&amp;#039;. From the drop down menu select &amp;#039;Add New Motes&amp;#039; followed by &amp;#039;Create new motes&amp;#039; and select the mote type as &amp;#039;Sky&amp;#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
3. Browse to the location &amp;#039;/contiki-2.7/examples/ipv6/rpl-border-router&amp;#039; and select the file rpl-border-router.sky. Click on &amp;#039;Create&amp;#039;. Add one mote of this type. &amp;lt;br&amp;gt;&lt;br /&gt;
4. Repeat step 2 and 3 but this time browse to the location /contiki-2.7/examples/ipv6/rpl-udp&amp;#039;  and select the file udp-server.sky. Add 3 - 4 motes of the type udp-server &amp;lt;br&amp;gt;&lt;br /&gt;
5. Once the motes have been added you can position the motes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Cooja_motes.png]]&lt;br /&gt;
&lt;br /&gt;
Select the options under View as shown below. These will help you creating a topology of your choice.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Motes_view.png]]&lt;br /&gt;
&lt;br /&gt;
6. Now, we need to create a bridge between the RPL network simulated on Cooja and the local machine. This can be done by right clicking on the mote which is programmed as the border router. Select &amp;#039;More tools for border router&amp;#039; and then select &amp;#039;Serial Socket (SERVER)&amp;#039;. You will get the following message on the successful completion of this step.Note that the message says &amp;#039;Listening on port 60001&amp;#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Serial_Socket.png]]&lt;br /&gt;
&lt;br /&gt;
7. Now start the simulation by clicking on Start&lt;br /&gt;
&lt;br /&gt;
== Tunslip utility ==&lt;br /&gt;
 &lt;br /&gt;
As mentioned in the introduction a border router helps in connecting one network to another. In this example the border router is used to route data between an RPL network and an external network. Till now we have only created the RPL network. Now we need to simulate the scenario in which this RPL network is connected to an external network. For this purpose we will use the Tunslip utility provided in Contiki. In this example tunslip creates a bridge between the RPL network and the local machine. &lt;br /&gt;
tunslip6.c can be found in /contiki-2.7/tools &lt;br /&gt;
Compile the tunslip6 code.&lt;br /&gt;
&amp;lt;pre&amp;gt;make tunslip6 &amp;lt;/pre&amp;gt; &lt;br /&gt;
Make a connection between the RPL network and your local machine. &lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ./tunslip6 -a 127.0.0.1 aaaa::1/64&amp;lt;/pre&amp;gt;&lt;br /&gt;
On the successful execution this command the following output will be printed on the terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;slip connected to ``127.0.0.1:60001&amp;#039;&amp;#039;&lt;br /&gt;
opened tun device ``/dev/tun0&amp;#039;&amp;#039;&lt;br /&gt;
ifconfig tun0 inet `hostname` up&lt;br /&gt;
ifconfig tun0 add aaaa::1/64&lt;br /&gt;
ifconfig tun0 add fe80::0:0:0:1/64&lt;br /&gt;
ifconfig tun0&lt;br /&gt;
&lt;br /&gt;
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  &lt;br /&gt;
          inet addr:127.0.1.1  P-t-P:127.0.1.1  Mask:255.255.255.255&lt;br /&gt;
          inet6 addr: fe80::1/64 Scope:Link&lt;br /&gt;
          inet6 addr: aaaa::1/64 Scope:Global&lt;br /&gt;
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1&lt;br /&gt;
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0&lt;br /&gt;
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0&lt;br /&gt;
          collisions:0 txqueuelen:500 &lt;br /&gt;
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)&lt;br /&gt;
&lt;br /&gt;
Rime started with address 0.18.116.1.0.1.1.1&lt;br /&gt;
MAC 00:12:74:01:00:01:01:01 Contiki 2.7 started. Node id is set to 1.&lt;br /&gt;
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26&lt;br /&gt;
Tentative link-local IPv6 address fe80:0000:0000:0000:0212:7401:0001:0101&lt;br /&gt;
Starting &amp;#039;Border router process&amp;#039; &amp;#039;Web server&amp;#039;&lt;br /&gt;
*** Address:aaaa::1 =&amp;gt; aaaa:0000:0000:0000&lt;br /&gt;
Got configuration message of type P&lt;br /&gt;
Setting prefix aaaa::&lt;br /&gt;
Server IPv6 addresses:&lt;br /&gt;
 aaaa::212:7401:1:101&lt;br /&gt;
 fe80::212:7401:1:101&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Go back to the Cooja simulator GUI and look at the dialogue box. The message has now changed to &amp;#039;Client connected: /127.0.0.1&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Client_Connected.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Verifying Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can verify that the address of the border router has been set by using the ping command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;user@instant-contiki:~/contiki-2.7$ ping6 aaaa::212:7401:1:101&lt;br /&gt;
PING aaaa::212:7401:1:101(aaaa::212:7401:1:101) 56 data bytes&lt;br /&gt;
64 bytes from aaaa::212:7401:1:101: icmp_seq=1 ttl=64 time=86.0 ms&lt;br /&gt;
64 bytes from aaaa::212:7401:1:101: icmp_seq=2 ttl=64 time=33.6 ms&lt;br /&gt;
64 bytes from aaaa::212:7401:1:101: icmp_seq=3 ttl=64 time=82.3 ms&lt;br /&gt;
64 bytes from aaaa::212:7401:1:101: icmp_seq=4 ttl=64 time=43.3 ms&lt;br /&gt;
64 bytes from aaaa::212:7401:1:101: icmp_seq=5 ttl=64 time=70.1 ms&lt;br /&gt;
^C&lt;br /&gt;
--- aaaa::212:7401:1:101 ping statistics ---&lt;br /&gt;
5 packets transmitted, 5 received, 0% packet loss, time 4006ms&lt;br /&gt;
rtt min/avg/max/mdev = 33.669/63.090/86.015/20.985 ms&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also ping one of the other nodes in the network. Here we are pinging node 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; user@instant-contiki:~/contiki-2.7$ ping6 aaaa::212:7404:4:404&lt;br /&gt;
PING aaaa::212:7404:4:404(aaaa::212:7404:4:404) 56 data bytes&lt;br /&gt;
64 bytes from aaaa::212:7404:4:404: icmp_seq=1 ttl=63 time=670 ms&lt;br /&gt;
64 bytes from aaaa::212:7404:4:404: icmp_seq=2 ttl=63 time=703 ms&lt;br /&gt;
64 bytes from aaaa::212:7404:4:404: icmp_seq=3 ttl=63 time=746 ms&lt;br /&gt;
64 bytes from aaaa::212:7404:4:404: icmp_seq=4 ttl=63 time=674 ms&lt;br /&gt;
^C&lt;br /&gt;
--- aaaa::212:7404:4:404 ping statistics ---&lt;br /&gt;
5 packets transmitted, 4 received, 20% packet loss, time 4001ms&lt;br /&gt;
rtt min/avg/max/mdev = 670.230/698.666/746.619/30.514 ms&lt;br /&gt;
user@instant-contiki:~/contiki-2.7$ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The IPv6 address of a node can be checked from the log screen on Cooja. Filter the nodes by their ID&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Node_Address.png]]&lt;br /&gt;
&lt;br /&gt;
You can enter the address of the border router in the web browser. The border router hosts a page which will be displayed on the browser as shown below. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RPL_Browser.png]]&lt;br /&gt;
&lt;br /&gt;
== Common Issues ==&lt;br /&gt;
&lt;br /&gt;
1. Make sure that you enter the IPv6 address properly in the command sudo ./tunslip6 -a 127.0.0.1 aaaa::1/64 . There should be no spaces in aaaa::1/64. Otherwise the code will give unexpected behavior.&amp;lt;br&amp;gt;&lt;br /&gt;
2. When you pause the simulation the SLIP connection is lost. It might not work properly on resuming the simulation. In such cases reload the simulation. Create a fresh SLIP connection and then run the simulation again.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
[https://github.com/njh/contiki/blob/master/cpu/mc1322x/doc/rpl-tutorial.md]  https://github.com/njh/contiki/blob/master/cpu/mc1322x/doc/rpl-tutorial.md &amp;lt;br&amp;gt;&lt;br /&gt;
[http://cnds.eecs.jacobs-university.de/courses/iotlab-2013/cooja.pdf] Using the Contiki Cooja Simulator - Anuj Sehgal&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Programming_Guide&amp;diff=1860</id>
		<title>Contiki Programming Guide</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Programming_Guide&amp;diff=1860"/>
				<updated>2016-11-04T19:05:36Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
•	Contiki  is developed by a group of developers from industry and academia lead by &amp;#039;&amp;#039;&amp;#039;Adam Dunkels&amp;#039;&amp;#039;&amp;#039; from the Swedish Institute of Computer Science. The Contiki team currently  consists  of tens of developers  from &amp;#039;&amp;#039;&amp;#039;SICS, SAP AG, Cisco, Atmel, NewAE and TU  Munich(Technical University of Munich).&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
----&lt;br /&gt;
•	Contiki is &amp;#039;&amp;#039;&amp;#039;multi-tasking&amp;#039;&amp;#039;&amp;#039; operating system, especially designed for microcontrollers with small &amp;#039;&amp;#039;&amp;#039;amount of memory&amp;#039;&amp;#039;&amp;#039;(35KB of ROM and around 3K of RAM), which are used in networked embedded systems and wireless sensor networks.&lt;br /&gt;
----&lt;br /&gt;
•	Contiki is written in the C programming language. &lt;br /&gt;
----&lt;br /&gt;
•	It is freely available as open source under a &amp;#039;&amp;#039;&amp;#039;BSD-style license&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
----&lt;br /&gt;
•	Contiki was the &amp;#039;&amp;#039;&amp;#039;first&amp;#039;&amp;#039;&amp;#039; OS which introduced IP communication in low-power sensor networks&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
Understand the idea of threads and Events for Contiki&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code Review for Protothreads and Events ==&lt;br /&gt;
Define system processes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
procinit(&amp;amp;etimer_process, &amp;amp;mac_process, &amp;amp;tcpip_process);&lt;br /&gt;
#define PROCINIT(...)&lt;br /&gt;
const struct process *prooinit[] = {__VA_ARGS__, NULL}&lt;br /&gt;
void procinit_init(void){&lt;br /&gt;
    int i;&lt;br /&gt;
    for(i = 0; procinit[i] != NULL; ++i){&lt;br /&gt;
        process_start((struct process *)procinit[i], NULL);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void){&lt;br /&gt;
    /*initialize hardware*/&lt;br /&gt;
    intit_lowlevel();&lt;br /&gt;
    clock_init();&lt;br /&gt;
    process_init();&lt;br /&gt;
    procinit_init();&lt;br /&gt;
    autostart_start(autostart_processes);&lt;br /&gt;
    printf(&amp;quot;*****************BOOTING CONTIKI****************\n&amp;quot;);&lt;br /&gt;
    while(1){&lt;br /&gt;
        process_run();&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The process thread in this part&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS_THREAD(tcpip_process, ev, data);&lt;br /&gt;
PROCESS_THREAD(mac_process, ev, data);&lt;br /&gt;
PROCESS_THREAD(etimer_process, ev, data){&lt;br /&gt;
    struct etimer *t, *u;&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    timerlist = NULL;&lt;br /&gt;
    while(1){&lt;br /&gt;
        PROCESS_YIELD();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Start system processes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void&lt;br /&gt;
process_start(struct process *p, cnst char *arg){&lt;br /&gt;
    struct process *q;&lt;br /&gt;
    /*first make sure that we do not try to start a process that is already running*/&lt;br /&gt;
    for(q = process_list; q != p &amp;amp;&amp;amp; q != NULL; q = q-&amp;gt;next);&lt;br /&gt;
    /*If we found the process on the process list, we will bail out*/&lt;br /&gt;
    if(q == p){&lt;br /&gt;
         return;&lt;br /&gt;
    }&lt;br /&gt;
    /*Put on the process list*/&lt;br /&gt;
    p-&amp;gt;next = process_list;&lt;br /&gt;
    process_list = p;&lt;br /&gt;
    p-&amp;gt;state = PROCESS_STATE_RUNNING;&lt;br /&gt;
    PT_INIT(&amp;amp;p-&amp;gt;pt);&lt;br /&gt;
    &lt;br /&gt;
    printf(&amp;quot;process: starting &amp;#039;%s&amp;#039;\n&amp;quot;, p-&amp;gt;name);&lt;br /&gt;
    /*Post a synchronous initialization event to the process*/&lt;br /&gt;
    process_post_synch(p, PROCESS_EVENT_INIT, (process_data_t)arg);&lt;br /&gt;
}&lt;br /&gt;
/*----------------------------------------------------------------------------------*/&lt;br /&gt;
/* PROCESS_POST_SYNCH will execute code between PROCESS_BEGIN(); and PROCESS_YIELD();*/&lt;br /&gt;
PROCESS_THREAD(etimer_process, ev, data){&lt;br /&gt;
    struct etimer *t, *u;&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    timerlist = NULL;&lt;br /&gt;
    while(1){&lt;br /&gt;
        PROCESS_YIELD();&lt;br /&gt;
        if(ev == PROCESS_EVENT_EXITED){&lt;br /&gt;
            struct process *p = data;&lt;br /&gt;
            while(timerlist != NULL &amp;amp;&amp;amp; timerlist -&amp;gt; p == p){&lt;br /&gt;
                timerlist = timerlist -&amp;gt; next;&lt;br /&gt;
            }&lt;br /&gt;
            if(timerlist != NULL){&lt;br /&gt;
                 t = timerlist;&lt;br /&gt;
                 while(t -&amp;gt; next != NULL){&lt;br /&gt;
                     t = timerlist -&amp;gt; next;&lt;br /&gt;
                 }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Start user processes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*PROCINIT(&amp;amp;etimer_process, &amp;amp;mac_process, &amp;amp;tcpip_process);*/&lt;br /&gt;
/*follow by define system processes main function*/&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;temp_measure_cmd_sender, &amp;amp;serial_cmd_process){&lt;br /&gt;
     int i;&lt;br /&gt;
     for(i = 0; processes[i] != NULL; ++i){&lt;br /&gt;
          process_start(processes[i], NULL);&lt;br /&gt;
          PRINTF(&amp;quot;autostart_start: starting process &amp;#039;%s&amp;#039;\n&amp;quot;, processes[i]-&amp;gt;name);&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The process thread in this part&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS_THREAD(temp_measure_cmd_sender, ev, data);&lt;br /&gt;
PROCESS_THREAD(serial_cmd_process, ev, data){&lt;br /&gt;
     PROCESS_BEGIN();&lt;br /&gt;
     while(1){&lt;br /&gt;
         PROCESS_WAIT_EVEN();&lt;br /&gt;
         if(ev = SERIAL_CMD){&lt;br /&gt;
             process_post(&amp;amp;temp_measure_cmd_sender, TEMP_CMD, 0);&lt;br /&gt;
         } &lt;br /&gt;
     }&lt;br /&gt;
     PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Main scheduler loop&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*loop until poll_requested == 1 || nevents &amp;gt; 0*/&lt;br /&gt;
int process_run(void){&lt;br /&gt;
    /*process poll events*/&lt;br /&gt;
    if(pull_requested){&lt;br /&gt;
        do_poll();&lt;br /&gt;
    }&lt;br /&gt;
    /*Process one event from the queue*/&lt;br /&gt;
    do_event();&lt;br /&gt;
    &lt;br /&gt;
    return nevents + poll_requested;    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void do_event(void){&lt;br /&gt;
    /*&lt;br /&gt;
    if there are any events in the queue, take the first one and walk through the&lt;br /&gt;
    list of processes to see if the event should be delivered to any of them. If &lt;br /&gt;
    so, we call the event handler function for the process. We only process one &lt;br /&gt;
    event at a time and call the poll handlers inbetween.&lt;br /&gt;
    */&lt;br /&gt;
    if(nevents &amp;gt;0){&lt;br /&gt;
       ...&lt;br /&gt;
       call_process(receiver, ev, data);  &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Method: POLL&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
ISR(AVR_OUTPUT_COMPARE_INT){&lt;br /&gt;
    ++count;&lt;br /&gt;
    if(etimer_pending()){&lt;br /&gt;
         etimer_request_poll();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void etimer_request_poll(void){&lt;br /&gt;
    process_poll(&amp;amp;etimer_process);&lt;br /&gt;
}&lt;br /&gt;
void process_poll(struct process *p){&lt;br /&gt;
    if(p != NULL){&lt;br /&gt;
        if(p-&amp;gt;state == PROCESS_STATE_RUNNING ||&lt;br /&gt;
           p-&amp;gt;state == PROCESS_STATE_CALLED){&lt;br /&gt;
           p-&amp;gt;needspoll = 1;&lt;br /&gt;
           poll_requested = 1;&lt;br /&gt;
        }   &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int process_run(void){&lt;br /&gt;
    /*process poll events*/&lt;br /&gt;
    if(poll_requested){&lt;br /&gt;
        do_poll();&lt;br /&gt;
    }&lt;br /&gt;
    /*Process one event from the queue*/&lt;br /&gt;
    do_event();&lt;br /&gt;
    return nevents + poll_requested;&lt;br /&gt;
}&lt;br /&gt;
static void do_poll(void){&lt;br /&gt;
    struct process *p;&lt;br /&gt;
    poll_requested = 0;&lt;br /&gt;
    /*Call the processes that needs to be polled*/&lt;br /&gt;
    for(p = process_list; p != NULL; p = p-&amp;gt;next){&lt;br /&gt;
        if(p-&amp;gt;needspoll){&lt;br /&gt;
            p-&amp;gt;state = PROCESS_STATE_RUNNING;&lt;br /&gt;
            p-&amp;gt;needspoll = 0;&lt;br /&gt;
            call_process(p, PROCESS_EVENT_POLL, NULL);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Method: POST&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS_THREAD(etimer_process, ev, data){&lt;br /&gt;
    ...&lt;br /&gt;
    for(t = timerlist; t != NULL; t = t-&amp;gt;next){&lt;br /&gt;
        if(timer_expired(&amp;amp;t-&amp;gt;timer)){&lt;br /&gt;
             if(process_post(t-&amp;gt;p, PROCESS_EVENT_TIMER, t) == PROCESS_ERR_OK)&lt;br /&gt;
             ...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int process_post(struct process *p, process_event_t ev, process_data_t data){&lt;br /&gt;
    ...&lt;br /&gt;
    anum = (fevent + nevents) % PROCESS_CONF_NUMEVENTS;&lt;br /&gt;
    events[snum].ev = ev;&lt;br /&gt;
    events[snum].data = data;&lt;br /&gt;
    events[snum].p = p;&lt;br /&gt;
    ++ nevents;&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
int process_run(void){&lt;br /&gt;
    /*Process poll events*/&lt;br /&gt;
    if(poll_requested){&lt;br /&gt;
        do_poll();&lt;br /&gt;
    }&lt;br /&gt;
    /*Process one event from the queue*/&lt;br /&gt;
    do_event();&lt;br /&gt;
    return nevents + poll_requested;&lt;br /&gt;
}&lt;br /&gt;
static void do_event(void){&lt;br /&gt;
    ...&lt;br /&gt;
    /*&lt;br /&gt;
    if there are any events in the queue, take the first one and walk through the&lt;br /&gt;
    list of processes to see if the event should be delivered to any of them. If &lt;br /&gt;
    so, we call the event handler function for the process. We only process one &lt;br /&gt;
    event at a time and call the poll handlers inbetween.&lt;br /&gt;
    */&lt;br /&gt;
    if(nevents &amp;gt; 0){&lt;br /&gt;
        ...&lt;br /&gt;
        call_process(reveiver, ev, data);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It is clear to see according to the figure 1 &lt;br /&gt;
----&lt;br /&gt;
[[File:1.jpg]]&lt;br /&gt;
figure 1&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Code Style: Names in Contiki&lt;br /&gt;
In Contiki, all names are prefixed with the module name&lt;br /&gt;
(example: process_start(), rime_init(), clock_time(), memb_alloc(), list_add()...)&lt;br /&gt;
Prefix makes it possible to mentally locate all function calls&lt;br /&gt;
All code must abide by this: &lt;br /&gt;
There are a few exceptions in the current code, but those are to be removed in the future&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Code Style: What to avoid&lt;br /&gt;
 -noCamelCase()&lt;br /&gt;
 -No_Capital_letters()&lt;br /&gt;
 -#define EXCEPT_FOR_MACROS()&lt;br /&gt;
----&lt;br /&gt;
Code Sytle: File names&lt;br /&gt;
Contiki uses hyphenated-file-names rather than underscore_in_file_names&lt;br /&gt;
&lt;br /&gt;
== The Motivation – Safe Tiny OS ==&lt;br /&gt;
&lt;br /&gt;
The Safe Tiny OS tool chain is shown in Figure 2. The most immediate benefit of Safe TinyOS was that during its development 4 severe bugs in TinyOS could be found out and were corrected.&lt;br /&gt;
----&lt;br /&gt;
[[File:2.png]]&lt;br /&gt;
figure 2&lt;br /&gt;
----&lt;br /&gt;
Building A Safe Application&lt;br /&gt;
&lt;br /&gt;
To build an application Safe, we have to provide the parameter ‘safe’ in the command line of ‘make’.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 cd $TOSROOT/apps/Blink &lt;br /&gt;
 make micaz safe&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
== Making Safety Optional ==&lt;br /&gt;
=== Implementation Overview ===&lt;br /&gt;
The source code of Contiki consists of nearly 1200 files, including both the OS core and the applications. The OS core itself consists of around 300 files. The work comprises of annotating each pointer access in all these files and recompiling with Deputy. Once the core is free of Safety errors, we can go for the Safety of applications. After this step, we set Deputy as the default compiler of Contiki. Programmers will have to adapt to the Annotations of Deputy, which are very simple and easy to learn.&lt;br /&gt;
----&lt;br /&gt;
The flow graph of Safe Contiki development is given in Figure 3&lt;br /&gt;
----&lt;br /&gt;
[[File:3.jpg]]&lt;br /&gt;
figure 3&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Modifying the Makefiles ===&lt;br /&gt;
The implementation was started by editing the makefiles associated with the ‘native’ processor. The Makefile.native mainly contains definitions for the C compiler used for the native processor. The file is located in contiki-2.x/cpu/native/ directory. The current contents of the 6th and 7th lines are&lt;br /&gt;
 - CC = gcc&lt;br /&gt;
 - LD = gcc&lt;br /&gt;
----&lt;br /&gt;
which indicates that for the native CPU, the compiler and the linker are the same, the gcc. We replaced this with&lt;br /&gt;
 - CC = deputy&lt;br /&gt;
 - LD = deputy&lt;br /&gt;
&lt;br /&gt;
=== A New Argument To Make ===&lt;br /&gt;
As an illustration of how the SAFETY argument is used, the following commands will create the Safe version of the ‘hello-world’ program for the ‘native’ platform.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 cd /home/user/contiki-2.x/examples/hello-world/&lt;br /&gt;
 make TARGET=native SAFETY=yes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Safety is an optional feature; programs are made Unsafe, by default. The following command makes the program without Safety features, for the ‘native’ platform.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
make TARGET=native&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Conditional Making And The gcc -D Flag ===&lt;br /&gt;
In order to make ‘making’ conditional, depending on the value of the variable SAFETY, we further modified the Makefile.native file in the contiki-2.x/cpu/native/ directory.&lt;br /&gt;
Makefile.native is shown below&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
ifeq ($(SAFETY),yes)&lt;br /&gt;
CC = deputy&lt;br /&gt;
LD = deputy&lt;br /&gt;
else&lt;br /&gt;
CC = gcc&lt;br /&gt;
LD = gcc&lt;br /&gt;
CFLAGS += -DNTS=&amp;#039;&amp;#039; -DSAFE=&amp;#039;&amp;#039; \&lt;br /&gt;
-DCOUNT\(x\)=&amp;#039;&amp;#039; \&lt;br /&gt;
-DTC\(x\)=x -DBOUND\(x,y\)=&amp;#039;&amp;#039; \&lt;br /&gt;
-DTRUSTED=&amp;#039;&amp;#039; -DNTDROP\(x\)=x \&lt;br /&gt;
-DNTEXPAND\(x\)=x&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
[1]The Safe TinyOS, 2008. http://docs.tinyos.net/index.php/Safe_TinyOS&lt;br /&gt;
[2]The Contiki OS, http://www.sics.se/contiki/&lt;br /&gt;
[2]Contiki Programming, 2011. http://wenku.baidu.com/view/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Programming_Guide&amp;diff=1859</id>
		<title>Contiki Programming Guide</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Programming_Guide&amp;diff=1859"/>
				<updated>2016-11-04T19:05:14Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
•	Contiki  is developed by a group of developers from industry and academia lead by &amp;#039;&amp;#039;&amp;#039;Adam Dunkels&amp;#039;&amp;#039;&amp;#039; from the Swedish Institute of Computer Science. The Contiki team currently  consists  of tens of developers  from &amp;#039;&amp;#039;&amp;#039;SICS, SAP AG, Cisco, Atmel, NewAE and TU  Munich(Technical University of Munich).&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
----&lt;br /&gt;
•	Contiki is &amp;#039;&amp;#039;&amp;#039;multi-tasking&amp;#039;&amp;#039;&amp;#039; operating system, especially designed for microcontrollers with small &amp;#039;&amp;#039;&amp;#039;amount of memory&amp;#039;&amp;#039;&amp;#039;(35KB of ROM and around 3K of RAM), which are used in networked embedded systems and wireless sensor networks.&lt;br /&gt;
----&lt;br /&gt;
•	Contiki is written in the C programming language. &lt;br /&gt;
----&lt;br /&gt;
•	It is freely available as open source under a &amp;#039;&amp;#039;&amp;#039;BSD-style license&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
----&lt;br /&gt;
•	Contiki was the &amp;#039;&amp;#039;&amp;#039;first&amp;#039;&amp;#039;&amp;#039; OS which introduced IP communication in low-power sensor networks&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
Understand the idea of threads and Events for Contiki&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code Review for Protothreads and Events ==&lt;br /&gt;
Define system processes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
procinit(&amp;amp;etimer_process, &amp;amp;mac_process, &amp;amp;tcpip_process);&lt;br /&gt;
#define PROCINIT(...)&lt;br /&gt;
const struct process *prooinit[] = {__VA_ARGS__, NULL}&lt;br /&gt;
void procinit_init(void){&lt;br /&gt;
    int i;&lt;br /&gt;
    for(i = 0; procinit[i] != NULL; ++i){&lt;br /&gt;
        process_start((struct process *)procinit[i], NULL);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void){&lt;br /&gt;
    /*initialize hardware*/&lt;br /&gt;
    intit_lowlevel();&lt;br /&gt;
    clock_init();&lt;br /&gt;
    process_init();&lt;br /&gt;
    procinit_init();&lt;br /&gt;
    autostart_start(autostart_processes);&lt;br /&gt;
    printf(&amp;quot;*****************BOOTING CONTIKI****************\n&amp;quot;);&lt;br /&gt;
    while(1){&lt;br /&gt;
        process_run();&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The process thread in this part&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS_THREAD(tcpip_process, ev, data);&lt;br /&gt;
PROCESS_THREAD(mac_process, ev, data);&lt;br /&gt;
PROCESS_THREAD(etimer_process, ev, data){&lt;br /&gt;
    struct etimer *t, *u;&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    timerlist = NULL;&lt;br /&gt;
    while(1){&lt;br /&gt;
        PROCESS_YIELD();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Start system processes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void&lt;br /&gt;
process_start(struct process *p, cnst char *arg){&lt;br /&gt;
    struct process *q;&lt;br /&gt;
    /*first make sure that we do not try to start a process that is already running*/&lt;br /&gt;
    for(q = process_list; q != p &amp;amp;&amp;amp; q != NULL; q = q-&amp;gt;next);&lt;br /&gt;
    /*If we found the process on the process list, we will bail out*/&lt;br /&gt;
    if(q == p){&lt;br /&gt;
         return;&lt;br /&gt;
    }&lt;br /&gt;
    /*Put on the process list*/&lt;br /&gt;
    p-&amp;gt;next = process_list;&lt;br /&gt;
    process_list = p;&lt;br /&gt;
    p-&amp;gt;state = PROCESS_STATE_RUNNING;&lt;br /&gt;
    PT_INIT(&amp;amp;p-&amp;gt;pt);&lt;br /&gt;
    &lt;br /&gt;
    printf(&amp;quot;process: starting &amp;#039;%s&amp;#039;\n&amp;quot;, p-&amp;gt;name);&lt;br /&gt;
    /*Post a synchronous initialization event to the process*/&lt;br /&gt;
    process_post_synch(p, PROCESS_EVENT_INIT, (process_data_t)arg);&lt;br /&gt;
}&lt;br /&gt;
/*----------------------------------------------------------------------------------*/&lt;br /&gt;
/* PROCESS_POST_SYNCH will execute code between PROCESS_BEGIN(); and PROCESS_YIELD();*/&lt;br /&gt;
PROCESS_THREAD(etimer_process, ev, data){&lt;br /&gt;
    struct etimer *t, *u;&lt;br /&gt;
    PROCESS_BEGIN();&lt;br /&gt;
    timerlist = NULL;&lt;br /&gt;
    while(1){&lt;br /&gt;
        PROCESS_YIELD();&lt;br /&gt;
        if(ev == PROCESS_EVENT_EXITED){&lt;br /&gt;
            struct process *p = data;&lt;br /&gt;
            while(timerlist != NULL &amp;amp;&amp;amp; timerlist -&amp;gt; p == p){&lt;br /&gt;
                timerlist = timerlist -&amp;gt; next;&lt;br /&gt;
            }&lt;br /&gt;
            if(timerlist != NULL){&lt;br /&gt;
                 t = timerlist;&lt;br /&gt;
                 while(t -&amp;gt; next != NULL){&lt;br /&gt;
                     t = timerlist -&amp;gt; next;&lt;br /&gt;
                 }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Start user processes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*PROCINIT(&amp;amp;etimer_process, &amp;amp;mac_process, &amp;amp;tcpip_process);*/&lt;br /&gt;
/*follow by define system processes main function*/&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;temp_measure_cmd_sender, &amp;amp;serial_cmd_process){&lt;br /&gt;
     int i;&lt;br /&gt;
     for(i = 0; processes[i] != NULL; ++i){&lt;br /&gt;
          process_start(processes[i], NULL);&lt;br /&gt;
          PRINTF(&amp;quot;autostart_start: starting process &amp;#039;%s&amp;#039;\n&amp;quot;, processes[i]-&amp;gt;name);&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The process thread in this part&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS_THREAD(temp_measure_cmd_sender, ev, data);&lt;br /&gt;
PROCESS_THREAD(serial_cmd_process, ev, data){&lt;br /&gt;
     PROCESS_BEGIN();&lt;br /&gt;
     while(1){&lt;br /&gt;
         PROCESS_WAIT_EVEN();&lt;br /&gt;
         if(ev = SERIAL_CMD){&lt;br /&gt;
             process_post(&amp;amp;temp_measure_cmd_sender, TEMP_CMD, 0);&lt;br /&gt;
         } &lt;br /&gt;
     }&lt;br /&gt;
     PROCESS_END();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Main scheduler loop&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*loop until poll_requested == 1 || nevents &amp;gt; 0*/&lt;br /&gt;
int process_run(void){&lt;br /&gt;
    /*process poll events*/&lt;br /&gt;
    if(pull_requested){&lt;br /&gt;
        do_poll();&lt;br /&gt;
    }&lt;br /&gt;
    /*Process one event from the queue*/&lt;br /&gt;
    do_event();&lt;br /&gt;
    &lt;br /&gt;
    return nevents + poll_requested;    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void do_event(void){&lt;br /&gt;
    /*&lt;br /&gt;
    if there are any events in the queue, take the first one and walk through the&lt;br /&gt;
    list of processes to see if the event should be delivered to any of them. If &lt;br /&gt;
    so, we call the event handler function for the process. We only process one &lt;br /&gt;
    event at a time and call the poll handlers inbetween.&lt;br /&gt;
    */&lt;br /&gt;
    if(nevents &amp;gt;0){&lt;br /&gt;
       ...&lt;br /&gt;
       call_process(receiver, ev, data);  &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Method: POLL&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
ISR(AVR_OUTPUT_COMPARE_INT){&lt;br /&gt;
    ++count;&lt;br /&gt;
    if(etimer_pending()){&lt;br /&gt;
         etimer_request_poll();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void etimer_request_poll(void){&lt;br /&gt;
    process_poll(&amp;amp;etimer_process);&lt;br /&gt;
}&lt;br /&gt;
void process_poll(struct process *p){&lt;br /&gt;
    if(p != NULL){&lt;br /&gt;
        if(p-&amp;gt;state == PROCESS_STATE_RUNNING ||&lt;br /&gt;
           p-&amp;gt;state == PROCESS_STATE_CALLED){&lt;br /&gt;
           p-&amp;gt;needspoll = 1;&lt;br /&gt;
           poll_requested = 1;&lt;br /&gt;
        }   &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int process_run(void){&lt;br /&gt;
    /*process poll events*/&lt;br /&gt;
    if(poll_requested){&lt;br /&gt;
        do_poll();&lt;br /&gt;
    }&lt;br /&gt;
    /*Process one event from the queue*/&lt;br /&gt;
    do_event();&lt;br /&gt;
    return nevents + poll_requested;&lt;br /&gt;
}&lt;br /&gt;
static void do_poll(void){&lt;br /&gt;
    struct process *p;&lt;br /&gt;
    poll_requested = 0;&lt;br /&gt;
    /*Call the processes that needs to be polled*/&lt;br /&gt;
    for(p = process_list; p != NULL; p = p-&amp;gt;next){&lt;br /&gt;
        if(p-&amp;gt;needspoll){&lt;br /&gt;
            p-&amp;gt;state = PROCESS_STATE_RUNNING;&lt;br /&gt;
            p-&amp;gt;needspoll = 0;&lt;br /&gt;
            call_process(p, PROCESS_EVENT_POLL, NULL);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Method: POST&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
PROCESS_THREAD(etimer_process, ev, data){&lt;br /&gt;
    ...&lt;br /&gt;
    for(t = timerlist; t != NULL; t = t-&amp;gt;next){&lt;br /&gt;
        if(timer_expired(&amp;amp;t-&amp;gt;timer)){&lt;br /&gt;
             if(process_post(t-&amp;gt;p, PROCESS_EVENT_TIMER, t) == PROCESS_ERR_OK)&lt;br /&gt;
             ...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int process_post(struct process *p, process_event_t ev, process_data_t data){&lt;br /&gt;
    ...&lt;br /&gt;
    anum = (fevent + nevents) % PROCESS_CONF_NUMEVENTS;&lt;br /&gt;
    events[snum].ev = ev;&lt;br /&gt;
    events[snum].data = data;&lt;br /&gt;
    events[snum].p = p;&lt;br /&gt;
    ++ nevents;&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
int process_run(void){&lt;br /&gt;
    /*Process poll events*/&lt;br /&gt;
    if(poll_requested){&lt;br /&gt;
        do_poll();&lt;br /&gt;
    }&lt;br /&gt;
    /*Process one event from the queue*/&lt;br /&gt;
    do_event();&lt;br /&gt;
    return nevents + poll_requested;&lt;br /&gt;
}&lt;br /&gt;
static void do_event(void){&lt;br /&gt;
    ...&lt;br /&gt;
    /*&lt;br /&gt;
    if there are any events in the queue, take the first one and walk through the&lt;br /&gt;
    list of processes to see if the event should be delivered to any of them. If &lt;br /&gt;
    so, we call the event handler function for the process. We only process one &lt;br /&gt;
    event at a time and call the poll handlers inbetween.&lt;br /&gt;
    */&lt;br /&gt;
    if(nevents &amp;gt; 0){&lt;br /&gt;
        ...&lt;br /&gt;
        call_process(reveiver, ev, data);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It is clear to see according to the figure 1 &lt;br /&gt;
----&lt;br /&gt;
[[File:1.jpg]]&lt;br /&gt;
figure 1&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Code Style: Names in Contiki&lt;br /&gt;
In Contiki, all names are prefixed with the module name&lt;br /&gt;
(example: process_start(), rime_init(), clock_time(), memb_alloc(), list_add()...)&lt;br /&gt;
Prefix makes it possible to mentally locate all function calls&lt;br /&gt;
All code must abide by this: &lt;br /&gt;
There are a few exceptions in the current code, but those are to be removed in the future&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
Code Style: What to avoid&lt;br /&gt;
 -noCamelCase()&lt;br /&gt;
 -No_Capital_letters()&lt;br /&gt;
 -#define EXCEPT_FOR_MACROS()&lt;br /&gt;
----&lt;br /&gt;
Code Sytle: File names&lt;br /&gt;
Contiki uses hyphenated-file-names rather than underscore_in_file_names&lt;br /&gt;
&lt;br /&gt;
== The Motivation – Safe Tiny OS ==&lt;br /&gt;
&lt;br /&gt;
The Safe Tiny OS tool chain is shown in Figure 2. The most immediate benefit of Safe TinyOS was that during its development 4 severe bugs in TinyOS could be found out and were corrected.&lt;br /&gt;
----&lt;br /&gt;
[[File:2.png]]&lt;br /&gt;
figure 2&lt;br /&gt;
----&lt;br /&gt;
Building A Safe Application&lt;br /&gt;
&lt;br /&gt;
To build an application Safe, we have to provide the parameter ‘safe’ in the command line of ‘make’.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 cd $TOSROOT/apps/Blink &lt;br /&gt;
 make micaz safe&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
== Making Safety Optional ==&lt;br /&gt;
=== Implementation Overview ===&lt;br /&gt;
The source code of Contiki consists of nearly 1200 files, including both the OS core and the applications. The OS core itself consists of around 300 files. The work comprises of annotating each pointer access in all these files and recompiling with Deputy. Once the core is free of Safety errors, we can go for the Safety of applications. After this step, we set Deputy as the default compiler of Contiki. Programmers will have to adapt to the Annotations of Deputy, which are very simple and easy to learn.&lt;br /&gt;
----&lt;br /&gt;
The flow graph of Safe Contiki development is given in Figure 3&lt;br /&gt;
----&lt;br /&gt;
[[File:3.jpg]]&lt;br /&gt;
figure 3&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Modifying the Makefiles ===&lt;br /&gt;
The implementation was started by editing the makefiles associated with the ‘native’ processor. The Makefile.native mainly contains definitions for the C compiler used for the native processor. The file is located in contiki-2.x/cpu/native/ directory. The current contents of the 6th and 7th lines are&lt;br /&gt;
 - CC = gcc&lt;br /&gt;
 - LD = gcc&lt;br /&gt;
----&lt;br /&gt;
which indicates that for the native CPU, the compiler and the linker are the same, the gcc. We replaced this with&lt;br /&gt;
 - CC = deputy&lt;br /&gt;
 - LD = deputy&lt;br /&gt;
&lt;br /&gt;
=== A New Argument To Make ===&lt;br /&gt;
As an illustration of how the SAFETY argument is used, the following commands will create the Safe version of the ‘hello-world’ program for the ‘native’ platform.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 cd /home/user/contiki-2.x/examples/hello-world/&lt;br /&gt;
 make TARGET=native SAFETY=yes&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Safety is an optional feature; programs are made Unsafe, by default. The following command makes the program without Safety features, for the ‘native’ platform.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
make TARGET=native&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Conditional Making And The gcc -D Flag ===&lt;br /&gt;
In order to make ‘making’ conditional, depending on the value of the variable SAFETY, we further modified the Makefile.native file in the contiki-2.x/cpu/native/ directory.&lt;br /&gt;
Makefile.native is shown below&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
ifeq ($(SAFETY),yes)&lt;br /&gt;
CC = deputy&lt;br /&gt;
LD = deputy&lt;br /&gt;
else&lt;br /&gt;
CC = gcc&lt;br /&gt;
LD = gcc&lt;br /&gt;
CFLAGS += -DNTS=&amp;#039;&amp;#039; -DSAFE=&amp;#039;&amp;#039; \&lt;br /&gt;
-DCOUNT\(x\)=&amp;#039;&amp;#039; \&lt;br /&gt;
-DTC\(x\)=x -DBOUND\(x,y\)=&amp;#039;&amp;#039; \&lt;br /&gt;
-DTRUSTED=&amp;#039;&amp;#039; -DNTDROP\(x\)=x \&lt;br /&gt;
-DNTEXPAND\(x\)=x&lt;br /&gt;
endif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
[1]The Safe TinyOS, 2008. http://docs.tinyos.net/index.php/Safe_TinyOS&lt;br /&gt;
[2]The Contiki OS, http://www.sics.se/contiki/&lt;br /&gt;
[2]Contiki Programming, 2011. http://wenku.baidu.com/view/&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1858</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1858"/>
				<updated>2016-10-24T18:09:11Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* List of Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Main_Page | Back to Main Page]]&lt;br /&gt;
&lt;br /&gt;
== List of Tutorials ==&lt;br /&gt;
&lt;br /&gt;
&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]]&lt;br /&gt;
# [[Timers]]&lt;br /&gt;
# [[CFS-Coffee]]&lt;br /&gt;
# [[Cooja Simulator]]&lt;br /&gt;
# [[Network Stack]]&lt;br /&gt;
# [[RPL UDP]]&lt;br /&gt;
# [[Contiki Shell]]&lt;br /&gt;
&lt;br /&gt;
Need review&lt;br /&gt;
# [[RSS measurement]]&lt;br /&gt;
# [[Contiki Coffee File System]]&lt;br /&gt;
&lt;br /&gt;
Starting&lt;br /&gt;
# [[RPL objective function &amp;amp; simulation using DGRM model in cooja]]&lt;br /&gt;
# [[MAC protocols in ContikiOS]]&lt;br /&gt;
# [[RPL Border Router]]&lt;br /&gt;
# [[REST example running on Cooja and Sky motes]]&lt;br /&gt;
# [[Trickle library]]&lt;br /&gt;
# [[Packetbuffer Basics]]&lt;br /&gt;
# [[Antelope(Database Management System)]]&lt;br /&gt;
# [[Mobility of Nodes in Cooja]]&lt;br /&gt;
# [[Contiki Programming Guide]]&lt;br /&gt;
# [[Analyse of a real 6LoWPAN network using a Contiki-based sniffer module]]&lt;br /&gt;
# [[Build your own application in Contiki]]&lt;br /&gt;
# [[Processes]] Yash&lt;br /&gt;
# [[RPL objective function modification and simulation in cooja]]&lt;br /&gt;
# [[Collect-view Code Details]] Pradipta&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1857</id>
		<title>Contiki Coffee File System</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1857"/>
				<updated>2016-10-24T18:04:55Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Simulation Result */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The tutorial covers the main features of Coffee File System available in ContikiOS 2.7.&amp;lt;br&amp;gt;Contiki provides a set of file systems for using various kinds of storage devices in resource-constrained systems. All of these file systems implement a subset of the Contiki File System (CFS) interface, and two of them provide the full functionality: CFS-POSIX and Coffee[1]. Coffee is used with device equipped with flash memories or EEPROM. Contiki takes care of underlying hardware implementation. Coffee file system will provide a API which is similar to normal C file operations: Open a file, read and write to it and then close it. &amp;lt;br&amp;gt; Due to the restrained resource and affected by the environment, the data transmission will get lost sometimes, which then need to be retransmitted, applying file system in the wireless sensor node will help to make the system become more reliable by store the data in the nodes locally. Since we can store the data in the node locally then we can send multiple data via one transmission, which leads to less number of transmission, then reduce the power consumption.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial you will understand how Coffee File System works and will also learn how to program with the Coffee File System API.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
The source code for Contiki Coffee File System can be found at,&lt;br /&gt;
&lt;br /&gt;
~/contiki/core/cfs/cfs-coffee.h&amp;lt;br&amp;gt;&lt;br /&gt;
~/contiki/core/cfs/cfs-coffee.c&lt;br /&gt;
&lt;br /&gt;
== Coffee File System API ==&lt;br /&gt;
&lt;br /&gt;
=== Memory Organization ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * The protected memory consists of structures that should not be &lt;br /&gt;
 * overwritten during system checkpointing because they may be used by &lt;br /&gt;
 * the checkpointing implementation. These structures need not be &lt;br /&gt;
 * protected if checkpointing is not used.&lt;br /&gt;
 */&lt;br /&gt;
static struct protected_mem_t {&lt;br /&gt;
  struct file coffee_files[COFFEE_MAX_OPEN_FILES];&lt;br /&gt;
  struct file_desc coffee_fd_set[COFFEE_FD_SET_SIZE];&lt;br /&gt;
  coffee_page_t next_free;&lt;br /&gt;
  char gc_wait;&lt;br /&gt;
} protected_mem;&lt;br /&gt;
static struct file * const coffee_files = protected_mem.coffee_files;&lt;br /&gt;
static struct file_desc * const coffee_fd_set = protected_mem.coffee_fd_set;&lt;br /&gt;
static coffee_page_t * const next_free = &amp;amp;protected_mem.next_free;&lt;br /&gt;
static char * const gc_wait = &amp;amp;protected_mem.gc_wait;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:coffee-structure.png]][1]&amp;lt;br&amp;gt;&lt;br /&gt;
Coffee File System organize the file_desc as an array and mark it as a member in the protected_mem_t.&lt;br /&gt;
&lt;br /&gt;
=== get_available_fd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static int&lt;br /&gt;
get_available_fd(void)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_FD_SET_SIZE; i++) {&lt;br /&gt;
    if(coffee_fd_set[i].flags == COFFEE_FD_FREE) {&lt;br /&gt;
      return i;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Contiki is a Linux like system, everything is a file, and the opened file is represented by the file descriptor. The get_available_fd will return the smallest available fd by check the file_desc array in an ascending order, the first one with flag == 0(COFFEE_FD_FREE) is what we want. If all the flags are set, then return -1.&lt;br /&gt;
&lt;br /&gt;
=== find_file ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static struct file *&lt;br /&gt;
find_file(const char *name)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  struct file_header hdr;&lt;br /&gt;
  coffee_page_t page;&lt;br /&gt;
  &lt;br /&gt;
  /* First check if the file metadata is cached. */&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_MAX_OPEN_FILES; i++) {&lt;br /&gt;
    if(FILE_FREE(&amp;amp;coffee_files[i])) {&lt;br /&gt;
      continue;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    read_header(&amp;amp;hdr, coffee_files[i].page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return &amp;amp;coffee_files[i];&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  /* Scan the flash memory sequentially otherwise. */&lt;br /&gt;
  for(page = 0; page &amp;lt; COFFEE_PAGE_COUNT; page = next_file(page, &amp;amp;hdr)) {&lt;br /&gt;
    read_header(&amp;amp;hdr, page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return load_file(page, &amp;amp;hdr);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return NULL;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If the file correspond to the name is still resides in coffee_files[COFFEE_MAX_OPEN_FILES] and the physical file is still valid then it return the pointer to that file, otherwise scan the FLSAH, and cache the file into memory.&lt;br /&gt;
&lt;br /&gt;
=== The CFS Programming Interface ===&lt;br /&gt;
&lt;br /&gt;
==== cfs_open ====&lt;br /&gt;
cf_open is  used to open a file. If it successfully open the file then it returns the file descriptor(fd), otherwise it returns -1.&amp;lt;br&amp;gt;&lt;br /&gt;
cfs_open source code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
cfs_open(const char *name, int flags)&lt;br /&gt;
{&lt;br /&gt;
  int fd;&lt;br /&gt;
  struct file_desc *fdp;&lt;br /&gt;
&lt;br /&gt;
  fd = get_available_fd(); //find the smallest available fd, see section 4.2&lt;br /&gt;
  if(fd &amp;lt; 0) {&lt;br /&gt;
    PRINTF(&amp;quot;Coffee: Failed to allocate a new file descriptor!\n&amp;quot;);&lt;br /&gt;
    return -1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp = &amp;amp;coffee_fd_set[fd];&lt;br /&gt;
  fdp-&amp;gt;flags = 0; //set the fd to FREE&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;file = find_file(name); //find the file corresponding to name(not exist, In flash but not cached, cached)&lt;br /&gt;
&lt;br /&gt;
  /*** if there isn&amp;#039;t any corresponding file, then try to create new file ***/&lt;br /&gt;
  if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
    if((flags &amp;amp; (CFS_READ | CFS_WRITE)) == CFS_READ) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file = reserve(name, page_count(COFFEE_DYN_SIZE), 1, 0);&lt;br /&gt;
    if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = 0; // Since it&amp;#039;s a new created file, the end will be set to 0&lt;br /&gt;
  }&lt;br /&gt;
   /*** find the file,seek for the end of the file***/ &lt;br /&gt;
   else if(fdp-&amp;gt;file-&amp;gt;end == UNKNOWN_OFFSET) {&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = file_end(fdp-&amp;gt;file-&amp;gt;page);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;flags |= flags;&lt;br /&gt;
  fdp-&amp;gt;offset = flags &amp;amp; CFS_APPEND ? fdp-&amp;gt;file-&amp;gt;end : 0; //if the flag is set to APPEND, then the offset is set to the end of the file, otherwise set to 0&lt;br /&gt;
  fdp-&amp;gt;file-&amp;gt;references++; //reference count will increment&lt;br /&gt;
&lt;br /&gt;
  return fd;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
==== cfs_close ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void cfs_close(int fd)&lt;br /&gt;
{&lt;br /&gt;
  if (FD_VALID(fd))&lt;br /&gt;
  {&lt;br /&gt;
    coffee_fd_set[fd].flags = COFFEE_FD_FREE;&lt;br /&gt;
    coffee_fd_set[fd].file-&amp;gt;references--;&lt;br /&gt;
    coffee_fd_set[fd].file = NULL;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#define FD_VALID(fd) ((fd)&amp;gt;= 0 &amp;amp;&amp;amp; (fd)&amp;lt;COFFEE_FD_SET_SIZE &amp;amp;&amp;amp; coffee_fd_set[(fd)].flags!=COFFEE_FD_FREE)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
When an open file is no longer needed, the application should close it by using cfs_close(). By closing a file, the file system can deallocate its internal resources held for the file, and possibly commit any cached data to permanent storage.[1]&amp;lt;br&amp;gt;&lt;br /&gt;
It first make sure fd is valid, then set the flag in this fd_desc to COFFEE_FD_FREE, and then decrease the reference count of that file. Finally set the file_desc point to NULL.&lt;br /&gt;
&lt;br /&gt;
==== cfs_read ====&lt;br /&gt;
cfs_read() fills buf with at most len bytes, starting from the current position in the file that is stored in the file descriptor. It returns the amount of bytes read, or -1 if an error occurs.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_write ====&lt;br /&gt;
cfs_write() writes len bytes from the memory buffer buf into the file, starting from the current position in the file descriptor. The file must have been opened with the CFS_WRITE flag. It returns the amount of bytes written, or -1 if an error occurred.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_seek ====&lt;br /&gt;
cfs_seek() moves the current file position to the position determined by the combination of the offset and the whence. CFS_SEEK_SET tells cfs_seek() to compute the offset from the beginning of the file, i.e., as an absolute offset. CFS_SEEK_CUR specifies that the offset should be compute relative to the current position of the file position. Similarly, CFS_SEEK_END computes the offset in relation to the end of the file, and can be used to move beyond the end if the file system implementation allows it. Negative offset values are accepted by both CFS_SEEK_CUR and CFS_SEEK_END, if the program wishes to move the file position backwards from the base that is indicated by the whence parameter. cfs_seek() returns the new absolute file position upon success, or -1 if the file pointer could not be moved to the requested position.[1]&lt;br /&gt;
==== cfs_remove ====&lt;br /&gt;
cfs_remove remove the file correspond to the name. It first find the file by find_file(name). After that invoke remove_by_page to delete the file.&lt;br /&gt;
&lt;br /&gt;
== Coding With Coffee API   ==&lt;br /&gt;
Modify the code provided by Contiki.&amp;lt;br&amp;gt;&lt;br /&gt;
Open contiki-2.7/examples/sky/example-coffee.c, then rewrite the file_test function.&amp;lt;br&amp;gt;&lt;br /&gt;
The Idea is based on Zane D. Purvis&amp;#039;s Coffee filesystem example.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2011, 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;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs-coffee.h&amp;quot;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_coffee_process, &amp;quot;Coffee example&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_coffee_process);&lt;br /&gt;
#define FILENAME &amp;quot;test&amp;quot;&lt;br /&gt;
/* Formatting is needed if the storage device is in an unknown state; &lt;br /&gt;
   e.g., when using Coffee on the storage device for the first time. */&lt;br /&gt;
#ifndef NEED_FORMATTING&lt;br /&gt;
#define NEED_FORMATTING 0&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
static int&lt;br /&gt;
file_test(const char *filename, char *msg)&lt;br /&gt;
{&lt;br /&gt;
	int fd;&lt;br /&gt;
	int r;&lt;br /&gt;
	char message[32];&lt;br /&gt;
	char buf[64];&lt;br /&gt;
	strncpy(message, &amp;quot;First Message&amp;quot;, sizeof(message) - 1);&lt;br /&gt;
	message[sizeof(message) - 1] = &amp;#039;\0&amp;#039;;&lt;br /&gt;
	strcpy(buf,message);&lt;br /&gt;
	/*First message is to test if the write will succeed*/&lt;br /&gt;
	printf(&amp;quot;Write Test: Will write \&amp;quot;%s\&amp;quot; to file \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf,FILENAME);&lt;br /&gt;
&lt;br /&gt;
  /* Obtain a file descriptor for the file, capable of handling both &lt;br /&gt;
     reads and writes. */&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  /*Write message to Filesystem*/&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,&lt;br /&gt;
				(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Write Test: Successfully wrote \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; wrote %d bytes\n &amp;quot;,message,FILENAME,r);&lt;br /&gt;
&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_read(fd, buf, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
      /* compare with the original message to see if the message was read &lt;br /&gt;
      correctly, if it reads fail then it will print fail*/&lt;br /&gt;
	printf(&amp;quot;Read Test: Read \&amp;quot;%s\&amp;quot; from \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf, FILENAME);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
     /*Append test */&lt;br /&gt;
	strcpy(message,&amp;quot;Append Something&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Append Test: Successfully \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; \n &amp;quot;,message,FILENAME);&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read First Part \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
       /*seek test*/&lt;br /&gt;
	if(cfs_seek(fd, sizeof(message), CFS_SEEK_SET) == -1) {&lt;br /&gt;
		printf(&amp;quot;seek failed\n&amp;quot;);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  //cfs_seek(fd, sizeof(message), CFS_SEEK_SET);&lt;br /&gt;
    /*if the seek fails then the second message will not &lt;br /&gt;
    be the same as the last message write to the file*/&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read Second Part: \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
  /* Release the internal resources held by Coffee for&lt;br /&gt;
     the file descriptor. */&lt;br /&gt;
	cfs_remove(FILENAME);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd != -1) {&lt;br /&gt;
		printf(&amp;quot;ERROR: could read from memory\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;Successfully removed file\n&amp;quot;);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&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;
#if NEED_FORMATTING&lt;br /&gt;
  cfs_coffee_format();&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
  /* Ensure that we will be working with a new file. */&lt;br /&gt;
  cfs_remove(FILENAME);&lt;br /&gt;
&lt;br /&gt;
  if(file_test(FILENAME, &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;
  printf(&amp;quot;test succeed\n&amp;quot;);&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;
== Simulation Result  ==&lt;br /&gt;
&lt;br /&gt;
[[File:result.png|850px]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can see that Coffee File System works well.&lt;br /&gt;
&lt;br /&gt;
== General Issues ==&lt;br /&gt;
1. Use sizeof() instead strlen() in the strncpy() function.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Remember to include string.h, otherwise when you compile it will generate warnings.&lt;br /&gt;
&lt;br /&gt;
==Reference ==&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/File-systems] - Zane D. Purvis, &amp;quot;Coffee filesystem&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-example] - Zane D. Purvis, &amp;quot;Coffee filesystem example&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Zhikun Liu&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1856</id>
		<title>Contiki Coffee File System</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1856"/>
				<updated>2016-10-13T19:47:05Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Source Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The tutorial covers the main features of Coffee File System available in ContikiOS 2.7.&amp;lt;br&amp;gt;Contiki provides a set of file systems for using various kinds of storage devices in resource-constrained systems. All of these file systems implement a subset of the Contiki File System (CFS) interface, and two of them provide the full functionality: CFS-POSIX and Coffee[1]. Coffee is used with device equipped with flash memories or EEPROM. Contiki takes care of underlying hardware implementation. Coffee file system will provide a API which is similar to normal C file operations: Open a file, read and write to it and then close it. &amp;lt;br&amp;gt; Due to the restrained resource and affected by the environment, the data transmission will get lost sometimes, which then need to be retransmitted, applying file system in the wireless sensor node will help to make the system become more reliable by store the data in the nodes locally. Since we can store the data in the node locally then we can send multiple data via one transmission, which leads to less number of transmission, then reduce the power consumption.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial you will understand how Coffee File System works and will also learn how to program with the Coffee File System API.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
The source code for Contiki Coffee File System can be found at,&lt;br /&gt;
&lt;br /&gt;
~/contiki/core/cfs/cfs-coffee.h&amp;lt;br&amp;gt;&lt;br /&gt;
~/contiki/core/cfs/cfs-coffee.c&lt;br /&gt;
&lt;br /&gt;
== Coffee File System API ==&lt;br /&gt;
&lt;br /&gt;
=== Memory Organization ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * The protected memory consists of structures that should not be &lt;br /&gt;
 * overwritten during system checkpointing because they may be used by &lt;br /&gt;
 * the checkpointing implementation. These structures need not be &lt;br /&gt;
 * protected if checkpointing is not used.&lt;br /&gt;
 */&lt;br /&gt;
static struct protected_mem_t {&lt;br /&gt;
  struct file coffee_files[COFFEE_MAX_OPEN_FILES];&lt;br /&gt;
  struct file_desc coffee_fd_set[COFFEE_FD_SET_SIZE];&lt;br /&gt;
  coffee_page_t next_free;&lt;br /&gt;
  char gc_wait;&lt;br /&gt;
} protected_mem;&lt;br /&gt;
static struct file * const coffee_files = protected_mem.coffee_files;&lt;br /&gt;
static struct file_desc * const coffee_fd_set = protected_mem.coffee_fd_set;&lt;br /&gt;
static coffee_page_t * const next_free = &amp;amp;protected_mem.next_free;&lt;br /&gt;
static char * const gc_wait = &amp;amp;protected_mem.gc_wait;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:coffee-structure.png]][1]&amp;lt;br&amp;gt;&lt;br /&gt;
Coffee File System organize the file_desc as an array and mark it as a member in the protected_mem_t.&lt;br /&gt;
&lt;br /&gt;
=== get_available_fd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static int&lt;br /&gt;
get_available_fd(void)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_FD_SET_SIZE; i++) {&lt;br /&gt;
    if(coffee_fd_set[i].flags == COFFEE_FD_FREE) {&lt;br /&gt;
      return i;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Contiki is a Linux like system, everything is a file, and the opened file is represented by the file descriptor. The get_available_fd will return the smallest available fd by check the file_desc array in an ascending order, the first one with flag == 0(COFFEE_FD_FREE) is what we want. If all the flags are set, then return -1.&lt;br /&gt;
&lt;br /&gt;
=== find_file ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static struct file *&lt;br /&gt;
find_file(const char *name)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  struct file_header hdr;&lt;br /&gt;
  coffee_page_t page;&lt;br /&gt;
  &lt;br /&gt;
  /* First check if the file metadata is cached. */&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_MAX_OPEN_FILES; i++) {&lt;br /&gt;
    if(FILE_FREE(&amp;amp;coffee_files[i])) {&lt;br /&gt;
      continue;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    read_header(&amp;amp;hdr, coffee_files[i].page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return &amp;amp;coffee_files[i];&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  /* Scan the flash memory sequentially otherwise. */&lt;br /&gt;
  for(page = 0; page &amp;lt; COFFEE_PAGE_COUNT; page = next_file(page, &amp;amp;hdr)) {&lt;br /&gt;
    read_header(&amp;amp;hdr, page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return load_file(page, &amp;amp;hdr);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return NULL;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If the file correspond to the name is still resides in coffee_files[COFFEE_MAX_OPEN_FILES] and the physical file is still valid then it return the pointer to that file, otherwise scan the FLSAH, and cache the file into memory.&lt;br /&gt;
&lt;br /&gt;
=== The CFS Programming Interface ===&lt;br /&gt;
&lt;br /&gt;
==== cfs_open ====&lt;br /&gt;
cf_open is  used to open a file. If it successfully open the file then it returns the file descriptor(fd), otherwise it returns -1.&amp;lt;br&amp;gt;&lt;br /&gt;
cfs_open source code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
cfs_open(const char *name, int flags)&lt;br /&gt;
{&lt;br /&gt;
  int fd;&lt;br /&gt;
  struct file_desc *fdp;&lt;br /&gt;
&lt;br /&gt;
  fd = get_available_fd(); //find the smallest available fd, see section 4.2&lt;br /&gt;
  if(fd &amp;lt; 0) {&lt;br /&gt;
    PRINTF(&amp;quot;Coffee: Failed to allocate a new file descriptor!\n&amp;quot;);&lt;br /&gt;
    return -1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp = &amp;amp;coffee_fd_set[fd];&lt;br /&gt;
  fdp-&amp;gt;flags = 0; //set the fd to FREE&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;file = find_file(name); //find the file corresponding to name(not exist, In flash but not cached, cached)&lt;br /&gt;
&lt;br /&gt;
  /*** if there isn&amp;#039;t any corresponding file, then try to create new file ***/&lt;br /&gt;
  if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
    if((flags &amp;amp; (CFS_READ | CFS_WRITE)) == CFS_READ) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file = reserve(name, page_count(COFFEE_DYN_SIZE), 1, 0);&lt;br /&gt;
    if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = 0; // Since it&amp;#039;s a new created file, the end will be set to 0&lt;br /&gt;
  }&lt;br /&gt;
   /*** find the file,seek for the end of the file***/ &lt;br /&gt;
   else if(fdp-&amp;gt;file-&amp;gt;end == UNKNOWN_OFFSET) {&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = file_end(fdp-&amp;gt;file-&amp;gt;page);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;flags |= flags;&lt;br /&gt;
  fdp-&amp;gt;offset = flags &amp;amp; CFS_APPEND ? fdp-&amp;gt;file-&amp;gt;end : 0; //if the flag is set to APPEND, then the offset is set to the end of the file, otherwise set to 0&lt;br /&gt;
  fdp-&amp;gt;file-&amp;gt;references++; //reference count will increment&lt;br /&gt;
&lt;br /&gt;
  return fd;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
==== cfs_close ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void cfs_close(int fd)&lt;br /&gt;
{&lt;br /&gt;
  if (FD_VALID(fd))&lt;br /&gt;
  {&lt;br /&gt;
    coffee_fd_set[fd].flags = COFFEE_FD_FREE;&lt;br /&gt;
    coffee_fd_set[fd].file-&amp;gt;references--;&lt;br /&gt;
    coffee_fd_set[fd].file = NULL;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#define FD_VALID(fd) ((fd)&amp;gt;= 0 &amp;amp;&amp;amp; (fd)&amp;lt;COFFEE_FD_SET_SIZE &amp;amp;&amp;amp; coffee_fd_set[(fd)].flags!=COFFEE_FD_FREE)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
When an open file is no longer needed, the application should close it by using cfs_close(). By closing a file, the file system can deallocate its internal resources held for the file, and possibly commit any cached data to permanent storage.[1]&amp;lt;br&amp;gt;&lt;br /&gt;
It first make sure fd is valid, then set the flag in this fd_desc to COFFEE_FD_FREE, and then decrease the reference count of that file. Finally set the file_desc point to NULL.&lt;br /&gt;
&lt;br /&gt;
==== cfs_read ====&lt;br /&gt;
cfs_read() fills buf with at most len bytes, starting from the current position in the file that is stored in the file descriptor. It returns the amount of bytes read, or -1 if an error occurs.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_write ====&lt;br /&gt;
cfs_write() writes len bytes from the memory buffer buf into the file, starting from the current position in the file descriptor. The file must have been opened with the CFS_WRITE flag. It returns the amount of bytes written, or -1 if an error occurred.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_seek ====&lt;br /&gt;
cfs_seek() moves the current file position to the position determined by the combination of the offset and the whence. CFS_SEEK_SET tells cfs_seek() to compute the offset from the beginning of the file, i.e., as an absolute offset. CFS_SEEK_CUR specifies that the offset should be compute relative to the current position of the file position. Similarly, CFS_SEEK_END computes the offset in relation to the end of the file, and can be used to move beyond the end if the file system implementation allows it. Negative offset values are accepted by both CFS_SEEK_CUR and CFS_SEEK_END, if the program wishes to move the file position backwards from the base that is indicated by the whence parameter. cfs_seek() returns the new absolute file position upon success, or -1 if the file pointer could not be moved to the requested position.[1]&lt;br /&gt;
==== cfs_remove ====&lt;br /&gt;
cfs_remove remove the file correspond to the name. It first find the file by find_file(name). After that invoke remove_by_page to delete the file.&lt;br /&gt;
&lt;br /&gt;
== Coding With Coffee API   ==&lt;br /&gt;
Modify the code provided by Contiki.&amp;lt;br&amp;gt;&lt;br /&gt;
Open contiki-2.7/examples/sky/example-coffee.c, then rewrite the file_test function.&amp;lt;br&amp;gt;&lt;br /&gt;
The Idea is based on Zane D. Purvis&amp;#039;s Coffee filesystem example.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2011, 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;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs-coffee.h&amp;quot;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_coffee_process, &amp;quot;Coffee example&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_coffee_process);&lt;br /&gt;
#define FILENAME &amp;quot;test&amp;quot;&lt;br /&gt;
/* Formatting is needed if the storage device is in an unknown state; &lt;br /&gt;
   e.g., when using Coffee on the storage device for the first time. */&lt;br /&gt;
#ifndef NEED_FORMATTING&lt;br /&gt;
#define NEED_FORMATTING 0&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
static int&lt;br /&gt;
file_test(const char *filename, char *msg)&lt;br /&gt;
{&lt;br /&gt;
	int fd;&lt;br /&gt;
	int r;&lt;br /&gt;
	char message[32];&lt;br /&gt;
	char buf[64];&lt;br /&gt;
	strncpy(message, &amp;quot;First Message&amp;quot;, sizeof(message) - 1);&lt;br /&gt;
	message[sizeof(message) - 1] = &amp;#039;\0&amp;#039;;&lt;br /&gt;
	strcpy(buf,message);&lt;br /&gt;
	/*First message is to test if the write will succeed*/&lt;br /&gt;
	printf(&amp;quot;Write Test: Will write \&amp;quot;%s\&amp;quot; to file \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf,FILENAME);&lt;br /&gt;
&lt;br /&gt;
  /* Obtain a file descriptor for the file, capable of handling both &lt;br /&gt;
     reads and writes. */&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  /*Write message to Filesystem*/&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,&lt;br /&gt;
				(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Write Test: Successfully wrote \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; wrote %d bytes\n &amp;quot;,message,FILENAME,r);&lt;br /&gt;
&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_read(fd, buf, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
      /* compare with the original message to see if the message was read &lt;br /&gt;
      correctly, if it reads fail then it will print fail*/&lt;br /&gt;
	printf(&amp;quot;Read Test: Read \&amp;quot;%s\&amp;quot; from \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf, FILENAME);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
     /*Append test */&lt;br /&gt;
	strcpy(message,&amp;quot;Append Something&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Append Test: Successfully \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; \n &amp;quot;,message,FILENAME);&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read First Part \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
       /*seek test*/&lt;br /&gt;
	if(cfs_seek(fd, sizeof(message), CFS_SEEK_SET) == -1) {&lt;br /&gt;
		printf(&amp;quot;seek failed\n&amp;quot;);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  //cfs_seek(fd, sizeof(message), CFS_SEEK_SET);&lt;br /&gt;
    /*if the seek fails then the second message will not &lt;br /&gt;
    be the same as the last message write to the file*/&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read Second Part: \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
  /* Release the internal resources held by Coffee for&lt;br /&gt;
     the file descriptor. */&lt;br /&gt;
	cfs_remove(FILENAME);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd != -1) {&lt;br /&gt;
		printf(&amp;quot;ERROR: could read from memory\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;Successfully removed file\n&amp;quot;);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&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;
#if NEED_FORMATTING&lt;br /&gt;
  cfs_coffee_format();&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
  /* Ensure that we will be working with a new file. */&lt;br /&gt;
  cfs_remove(FILENAME);&lt;br /&gt;
&lt;br /&gt;
  if(file_test(FILENAME, &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;
  printf(&amp;quot;test succeed\n&amp;quot;);&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;
== Simulation Result  ==&lt;br /&gt;
[[File:result.png|850px]]&amp;lt;br&amp;gt;&lt;br /&gt;
We can see that Coffee File System works well.&lt;br /&gt;
&lt;br /&gt;
== General Issues ==&lt;br /&gt;
1. Use sizeof() instead strlen() in the strncpy() function.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Remember to include string.h, otherwise when you compile it will generate warnings.&lt;br /&gt;
&lt;br /&gt;
==Reference ==&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/File-systems] - Zane D. Purvis, &amp;quot;Coffee filesystem&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-example] - Zane D. Purvis, &amp;quot;Coffee filesystem example&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Zhikun Liu&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1855</id>
		<title>Contiki Coffee File System</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1855"/>
				<updated>2016-10-13T19:42:02Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* You Will Learn */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The tutorial covers the main features of Coffee File System available in ContikiOS 2.7.&amp;lt;br&amp;gt;Contiki provides a set of file systems for using various kinds of storage devices in resource-constrained systems. All of these file systems implement a subset of the Contiki File System (CFS) interface, and two of them provide the full functionality: CFS-POSIX and Coffee[1]. Coffee is used with device equipped with flash memories or EEPROM. Contiki takes care of underlying hardware implementation. Coffee file system will provide a API which is similar to normal C file operations: Open a file, read and write to it and then close it. &amp;lt;br&amp;gt; Due to the restrained resource and affected by the environment, the data transmission will get lost sometimes, which then need to be retransmitted, applying file system in the wireless sensor node will help to make the system become more reliable by store the data in the nodes locally. Since we can store the data in the node locally then we can send multiple data via one transmission, which leads to less number of transmission, then reduce the power consumption.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial you will understand how Coffee File System works and will also learn how to program with the Coffee File System API.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/cfs/cfs-coffee.h&amp;lt;br&amp;gt;&lt;br /&gt;
~/contiki-2.7/core/cfs/cfs-coffee.c&lt;br /&gt;
&lt;br /&gt;
== Coffee File System API ==&lt;br /&gt;
&lt;br /&gt;
=== Memory Organization ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * The protected memory consists of structures that should not be &lt;br /&gt;
 * overwritten during system checkpointing because they may be used by &lt;br /&gt;
 * the checkpointing implementation. These structures need not be &lt;br /&gt;
 * protected if checkpointing is not used.&lt;br /&gt;
 */&lt;br /&gt;
static struct protected_mem_t {&lt;br /&gt;
  struct file coffee_files[COFFEE_MAX_OPEN_FILES];&lt;br /&gt;
  struct file_desc coffee_fd_set[COFFEE_FD_SET_SIZE];&lt;br /&gt;
  coffee_page_t next_free;&lt;br /&gt;
  char gc_wait;&lt;br /&gt;
} protected_mem;&lt;br /&gt;
static struct file * const coffee_files = protected_mem.coffee_files;&lt;br /&gt;
static struct file_desc * const coffee_fd_set = protected_mem.coffee_fd_set;&lt;br /&gt;
static coffee_page_t * const next_free = &amp;amp;protected_mem.next_free;&lt;br /&gt;
static char * const gc_wait = &amp;amp;protected_mem.gc_wait;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:coffee-structure.png]][1]&amp;lt;br&amp;gt;&lt;br /&gt;
Coffee File System organize the file_desc as an array and mark it as a member in the protected_mem_t.&lt;br /&gt;
&lt;br /&gt;
=== get_available_fd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static int&lt;br /&gt;
get_available_fd(void)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_FD_SET_SIZE; i++) {&lt;br /&gt;
    if(coffee_fd_set[i].flags == COFFEE_FD_FREE) {&lt;br /&gt;
      return i;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Contiki is a Linux like system, everything is a file, and the opened file is represented by the file descriptor. The get_available_fd will return the smallest available fd by check the file_desc array in an ascending order, the first one with flag == 0(COFFEE_FD_FREE) is what we want. If all the flags are set, then return -1.&lt;br /&gt;
&lt;br /&gt;
=== find_file ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static struct file *&lt;br /&gt;
find_file(const char *name)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  struct file_header hdr;&lt;br /&gt;
  coffee_page_t page;&lt;br /&gt;
  &lt;br /&gt;
  /* First check if the file metadata is cached. */&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_MAX_OPEN_FILES; i++) {&lt;br /&gt;
    if(FILE_FREE(&amp;amp;coffee_files[i])) {&lt;br /&gt;
      continue;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    read_header(&amp;amp;hdr, coffee_files[i].page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return &amp;amp;coffee_files[i];&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  /* Scan the flash memory sequentially otherwise. */&lt;br /&gt;
  for(page = 0; page &amp;lt; COFFEE_PAGE_COUNT; page = next_file(page, &amp;amp;hdr)) {&lt;br /&gt;
    read_header(&amp;amp;hdr, page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return load_file(page, &amp;amp;hdr);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return NULL;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If the file correspond to the name is still resides in coffee_files[COFFEE_MAX_OPEN_FILES] and the physical file is still valid then it return the pointer to that file, otherwise scan the FLSAH, and cache the file into memory.&lt;br /&gt;
&lt;br /&gt;
=== The CFS Programming Interface ===&lt;br /&gt;
&lt;br /&gt;
==== cfs_open ====&lt;br /&gt;
cf_open is  used to open a file. If it successfully open the file then it returns the file descriptor(fd), otherwise it returns -1.&amp;lt;br&amp;gt;&lt;br /&gt;
cfs_open source code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
cfs_open(const char *name, int flags)&lt;br /&gt;
{&lt;br /&gt;
  int fd;&lt;br /&gt;
  struct file_desc *fdp;&lt;br /&gt;
&lt;br /&gt;
  fd = get_available_fd(); //find the smallest available fd, see section 4.2&lt;br /&gt;
  if(fd &amp;lt; 0) {&lt;br /&gt;
    PRINTF(&amp;quot;Coffee: Failed to allocate a new file descriptor!\n&amp;quot;);&lt;br /&gt;
    return -1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp = &amp;amp;coffee_fd_set[fd];&lt;br /&gt;
  fdp-&amp;gt;flags = 0; //set the fd to FREE&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;file = find_file(name); //find the file corresponding to name(not exist, In flash but not cached, cached)&lt;br /&gt;
&lt;br /&gt;
  /*** if there isn&amp;#039;t any corresponding file, then try to create new file ***/&lt;br /&gt;
  if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
    if((flags &amp;amp; (CFS_READ | CFS_WRITE)) == CFS_READ) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file = reserve(name, page_count(COFFEE_DYN_SIZE), 1, 0);&lt;br /&gt;
    if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = 0; // Since it&amp;#039;s a new created file, the end will be set to 0&lt;br /&gt;
  }&lt;br /&gt;
   /*** find the file,seek for the end of the file***/ &lt;br /&gt;
   else if(fdp-&amp;gt;file-&amp;gt;end == UNKNOWN_OFFSET) {&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = file_end(fdp-&amp;gt;file-&amp;gt;page);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;flags |= flags;&lt;br /&gt;
  fdp-&amp;gt;offset = flags &amp;amp; CFS_APPEND ? fdp-&amp;gt;file-&amp;gt;end : 0; //if the flag is set to APPEND, then the offset is set to the end of the file, otherwise set to 0&lt;br /&gt;
  fdp-&amp;gt;file-&amp;gt;references++; //reference count will increment&lt;br /&gt;
&lt;br /&gt;
  return fd;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
==== cfs_close ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void cfs_close(int fd)&lt;br /&gt;
{&lt;br /&gt;
  if (FD_VALID(fd))&lt;br /&gt;
  {&lt;br /&gt;
    coffee_fd_set[fd].flags = COFFEE_FD_FREE;&lt;br /&gt;
    coffee_fd_set[fd].file-&amp;gt;references--;&lt;br /&gt;
    coffee_fd_set[fd].file = NULL;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#define FD_VALID(fd) ((fd)&amp;gt;= 0 &amp;amp;&amp;amp; (fd)&amp;lt;COFFEE_FD_SET_SIZE &amp;amp;&amp;amp; coffee_fd_set[(fd)].flags!=COFFEE_FD_FREE)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
When an open file is no longer needed, the application should close it by using cfs_close(). By closing a file, the file system can deallocate its internal resources held for the file, and possibly commit any cached data to permanent storage.[1]&amp;lt;br&amp;gt;&lt;br /&gt;
It first make sure fd is valid, then set the flag in this fd_desc to COFFEE_FD_FREE, and then decrease the reference count of that file. Finally set the file_desc point to NULL.&lt;br /&gt;
&lt;br /&gt;
==== cfs_read ====&lt;br /&gt;
cfs_read() fills buf with at most len bytes, starting from the current position in the file that is stored in the file descriptor. It returns the amount of bytes read, or -1 if an error occurs.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_write ====&lt;br /&gt;
cfs_write() writes len bytes from the memory buffer buf into the file, starting from the current position in the file descriptor. The file must have been opened with the CFS_WRITE flag. It returns the amount of bytes written, or -1 if an error occurred.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_seek ====&lt;br /&gt;
cfs_seek() moves the current file position to the position determined by the combination of the offset and the whence. CFS_SEEK_SET tells cfs_seek() to compute the offset from the beginning of the file, i.e., as an absolute offset. CFS_SEEK_CUR specifies that the offset should be compute relative to the current position of the file position. Similarly, CFS_SEEK_END computes the offset in relation to the end of the file, and can be used to move beyond the end if the file system implementation allows it. Negative offset values are accepted by both CFS_SEEK_CUR and CFS_SEEK_END, if the program wishes to move the file position backwards from the base that is indicated by the whence parameter. cfs_seek() returns the new absolute file position upon success, or -1 if the file pointer could not be moved to the requested position.[1]&lt;br /&gt;
==== cfs_remove ====&lt;br /&gt;
cfs_remove remove the file correspond to the name. It first find the file by find_file(name). After that invoke remove_by_page to delete the file.&lt;br /&gt;
&lt;br /&gt;
== Coding With Coffee API   ==&lt;br /&gt;
Modify the code provided by Contiki.&amp;lt;br&amp;gt;&lt;br /&gt;
Open contiki-2.7/examples/sky/example-coffee.c, then rewrite the file_test function.&amp;lt;br&amp;gt;&lt;br /&gt;
The Idea is based on Zane D. Purvis&amp;#039;s Coffee filesystem example.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2011, 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;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs-coffee.h&amp;quot;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_coffee_process, &amp;quot;Coffee example&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_coffee_process);&lt;br /&gt;
#define FILENAME &amp;quot;test&amp;quot;&lt;br /&gt;
/* Formatting is needed if the storage device is in an unknown state; &lt;br /&gt;
   e.g., when using Coffee on the storage device for the first time. */&lt;br /&gt;
#ifndef NEED_FORMATTING&lt;br /&gt;
#define NEED_FORMATTING 0&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
static int&lt;br /&gt;
file_test(const char *filename, char *msg)&lt;br /&gt;
{&lt;br /&gt;
	int fd;&lt;br /&gt;
	int r;&lt;br /&gt;
	char message[32];&lt;br /&gt;
	char buf[64];&lt;br /&gt;
	strncpy(message, &amp;quot;First Message&amp;quot;, sizeof(message) - 1);&lt;br /&gt;
	message[sizeof(message) - 1] = &amp;#039;\0&amp;#039;;&lt;br /&gt;
	strcpy(buf,message);&lt;br /&gt;
	/*First message is to test if the write will succeed*/&lt;br /&gt;
	printf(&amp;quot;Write Test: Will write \&amp;quot;%s\&amp;quot; to file \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf,FILENAME);&lt;br /&gt;
&lt;br /&gt;
  /* Obtain a file descriptor for the file, capable of handling both &lt;br /&gt;
     reads and writes. */&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  /*Write message to Filesystem*/&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,&lt;br /&gt;
				(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Write Test: Successfully wrote \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; wrote %d bytes\n &amp;quot;,message,FILENAME,r);&lt;br /&gt;
&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_read(fd, buf, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
      /* compare with the original message to see if the message was read &lt;br /&gt;
      correctly, if it reads fail then it will print fail*/&lt;br /&gt;
	printf(&amp;quot;Read Test: Read \&amp;quot;%s\&amp;quot; from \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf, FILENAME);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
     /*Append test */&lt;br /&gt;
	strcpy(message,&amp;quot;Append Something&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Append Test: Successfully \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; \n &amp;quot;,message,FILENAME);&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read First Part \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
       /*seek test*/&lt;br /&gt;
	if(cfs_seek(fd, sizeof(message), CFS_SEEK_SET) == -1) {&lt;br /&gt;
		printf(&amp;quot;seek failed\n&amp;quot;);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  //cfs_seek(fd, sizeof(message), CFS_SEEK_SET);&lt;br /&gt;
    /*if the seek fails then the second message will not &lt;br /&gt;
    be the same as the last message write to the file*/&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read Second Part: \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
  /* Release the internal resources held by Coffee for&lt;br /&gt;
     the file descriptor. */&lt;br /&gt;
	cfs_remove(FILENAME);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd != -1) {&lt;br /&gt;
		printf(&amp;quot;ERROR: could read from memory\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;Successfully removed file\n&amp;quot;);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&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;
#if NEED_FORMATTING&lt;br /&gt;
  cfs_coffee_format();&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
  /* Ensure that we will be working with a new file. */&lt;br /&gt;
  cfs_remove(FILENAME);&lt;br /&gt;
&lt;br /&gt;
  if(file_test(FILENAME, &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;
  printf(&amp;quot;test succeed\n&amp;quot;);&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;
== Simulation Result  ==&lt;br /&gt;
[[File:result.png|850px]]&amp;lt;br&amp;gt;&lt;br /&gt;
We can see that Coffee File System works well.&lt;br /&gt;
&lt;br /&gt;
== General Issues ==&lt;br /&gt;
1. Use sizeof() instead strlen() in the strncpy() function.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Remember to include string.h, otherwise when you compile it will generate warnings.&lt;br /&gt;
&lt;br /&gt;
==Reference ==&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/File-systems] - Zane D. Purvis, &amp;quot;Coffee filesystem&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-example] - Zane D. Purvis, &amp;quot;Coffee filesystem example&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Zhikun Liu&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1854</id>
		<title>Contiki Coffee File System</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1854"/>
				<updated>2016-10-13T19:41:06Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* You Will Learn */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The tutorial covers the main features of Coffee File System available in ContikiOS 2.7.&amp;lt;br&amp;gt;Contiki provides a set of file systems for using various kinds of storage devices in resource-constrained systems. All of these file systems implement a subset of the Contiki File System (CFS) interface, and two of them provide the full functionality: CFS-POSIX and Coffee[1]. Coffee is used with device equipped with flash memories or EEPROM. Contiki takes care of underlying hardware implementation. Coffee file system will provide a API which is similar to normal C file operations: Open a file, read and write to it and then close it. &amp;lt;br&amp;gt; Due to the restrained resource and affected by the environment, the data transmission will get lost sometimes, which then need to be retransmitted, applying file system in the wireless sensor node will help to make the system become more reliable by store the data in the nodes locally. Since we can store the data in the node locally then we can send multiple data via one transmission, which leads to less number of transmission, then reduce the power consumption.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial you are going to understand how the Coffee File System works and will also learn how to program with the Coffee File System API.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/cfs/cfs-coffee.h&amp;lt;br&amp;gt;&lt;br /&gt;
~/contiki-2.7/core/cfs/cfs-coffee.c&lt;br /&gt;
&lt;br /&gt;
== Coffee File System API ==&lt;br /&gt;
&lt;br /&gt;
=== Memory Organization ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * The protected memory consists of structures that should not be &lt;br /&gt;
 * overwritten during system checkpointing because they may be used by &lt;br /&gt;
 * the checkpointing implementation. These structures need not be &lt;br /&gt;
 * protected if checkpointing is not used.&lt;br /&gt;
 */&lt;br /&gt;
static struct protected_mem_t {&lt;br /&gt;
  struct file coffee_files[COFFEE_MAX_OPEN_FILES];&lt;br /&gt;
  struct file_desc coffee_fd_set[COFFEE_FD_SET_SIZE];&lt;br /&gt;
  coffee_page_t next_free;&lt;br /&gt;
  char gc_wait;&lt;br /&gt;
} protected_mem;&lt;br /&gt;
static struct file * const coffee_files = protected_mem.coffee_files;&lt;br /&gt;
static struct file_desc * const coffee_fd_set = protected_mem.coffee_fd_set;&lt;br /&gt;
static coffee_page_t * const next_free = &amp;amp;protected_mem.next_free;&lt;br /&gt;
static char * const gc_wait = &amp;amp;protected_mem.gc_wait;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:coffee-structure.png]][1]&amp;lt;br&amp;gt;&lt;br /&gt;
Coffee File System organize the file_desc as an array and mark it as a member in the protected_mem_t.&lt;br /&gt;
&lt;br /&gt;
=== get_available_fd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static int&lt;br /&gt;
get_available_fd(void)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_FD_SET_SIZE; i++) {&lt;br /&gt;
    if(coffee_fd_set[i].flags == COFFEE_FD_FREE) {&lt;br /&gt;
      return i;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Contiki is a Linux like system, everything is a file, and the opened file is represented by the file descriptor. The get_available_fd will return the smallest available fd by check the file_desc array in an ascending order, the first one with flag == 0(COFFEE_FD_FREE) is what we want. If all the flags are set, then return -1.&lt;br /&gt;
&lt;br /&gt;
=== find_file ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static struct file *&lt;br /&gt;
find_file(const char *name)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  struct file_header hdr;&lt;br /&gt;
  coffee_page_t page;&lt;br /&gt;
  &lt;br /&gt;
  /* First check if the file metadata is cached. */&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_MAX_OPEN_FILES; i++) {&lt;br /&gt;
    if(FILE_FREE(&amp;amp;coffee_files[i])) {&lt;br /&gt;
      continue;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    read_header(&amp;amp;hdr, coffee_files[i].page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return &amp;amp;coffee_files[i];&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  /* Scan the flash memory sequentially otherwise. */&lt;br /&gt;
  for(page = 0; page &amp;lt; COFFEE_PAGE_COUNT; page = next_file(page, &amp;amp;hdr)) {&lt;br /&gt;
    read_header(&amp;amp;hdr, page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return load_file(page, &amp;amp;hdr);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return NULL;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If the file correspond to the name is still resides in coffee_files[COFFEE_MAX_OPEN_FILES] and the physical file is still valid then it return the pointer to that file, otherwise scan the FLSAH, and cache the file into memory.&lt;br /&gt;
&lt;br /&gt;
=== The CFS Programming Interface ===&lt;br /&gt;
&lt;br /&gt;
==== cfs_open ====&lt;br /&gt;
cf_open is  used to open a file. If it successfully open the file then it returns the file descriptor(fd), otherwise it returns -1.&amp;lt;br&amp;gt;&lt;br /&gt;
cfs_open source code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
cfs_open(const char *name, int flags)&lt;br /&gt;
{&lt;br /&gt;
  int fd;&lt;br /&gt;
  struct file_desc *fdp;&lt;br /&gt;
&lt;br /&gt;
  fd = get_available_fd(); //find the smallest available fd, see section 4.2&lt;br /&gt;
  if(fd &amp;lt; 0) {&lt;br /&gt;
    PRINTF(&amp;quot;Coffee: Failed to allocate a new file descriptor!\n&amp;quot;);&lt;br /&gt;
    return -1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp = &amp;amp;coffee_fd_set[fd];&lt;br /&gt;
  fdp-&amp;gt;flags = 0; //set the fd to FREE&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;file = find_file(name); //find the file corresponding to name(not exist, In flash but not cached, cached)&lt;br /&gt;
&lt;br /&gt;
  /*** if there isn&amp;#039;t any corresponding file, then try to create new file ***/&lt;br /&gt;
  if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
    if((flags &amp;amp; (CFS_READ | CFS_WRITE)) == CFS_READ) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file = reserve(name, page_count(COFFEE_DYN_SIZE), 1, 0);&lt;br /&gt;
    if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = 0; // Since it&amp;#039;s a new created file, the end will be set to 0&lt;br /&gt;
  }&lt;br /&gt;
   /*** find the file,seek for the end of the file***/ &lt;br /&gt;
   else if(fdp-&amp;gt;file-&amp;gt;end == UNKNOWN_OFFSET) {&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = file_end(fdp-&amp;gt;file-&amp;gt;page);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;flags |= flags;&lt;br /&gt;
  fdp-&amp;gt;offset = flags &amp;amp; CFS_APPEND ? fdp-&amp;gt;file-&amp;gt;end : 0; //if the flag is set to APPEND, then the offset is set to the end of the file, otherwise set to 0&lt;br /&gt;
  fdp-&amp;gt;file-&amp;gt;references++; //reference count will increment&lt;br /&gt;
&lt;br /&gt;
  return fd;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
==== cfs_close ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void cfs_close(int fd)&lt;br /&gt;
{&lt;br /&gt;
  if (FD_VALID(fd))&lt;br /&gt;
  {&lt;br /&gt;
    coffee_fd_set[fd].flags = COFFEE_FD_FREE;&lt;br /&gt;
    coffee_fd_set[fd].file-&amp;gt;references--;&lt;br /&gt;
    coffee_fd_set[fd].file = NULL;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#define FD_VALID(fd) ((fd)&amp;gt;= 0 &amp;amp;&amp;amp; (fd)&amp;lt;COFFEE_FD_SET_SIZE &amp;amp;&amp;amp; coffee_fd_set[(fd)].flags!=COFFEE_FD_FREE)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
When an open file is no longer needed, the application should close it by using cfs_close(). By closing a file, the file system can deallocate its internal resources held for the file, and possibly commit any cached data to permanent storage.[1]&amp;lt;br&amp;gt;&lt;br /&gt;
It first make sure fd is valid, then set the flag in this fd_desc to COFFEE_FD_FREE, and then decrease the reference count of that file. Finally set the file_desc point to NULL.&lt;br /&gt;
&lt;br /&gt;
==== cfs_read ====&lt;br /&gt;
cfs_read() fills buf with at most len bytes, starting from the current position in the file that is stored in the file descriptor. It returns the amount of bytes read, or -1 if an error occurs.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_write ====&lt;br /&gt;
cfs_write() writes len bytes from the memory buffer buf into the file, starting from the current position in the file descriptor. The file must have been opened with the CFS_WRITE flag. It returns the amount of bytes written, or -1 if an error occurred.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_seek ====&lt;br /&gt;
cfs_seek() moves the current file position to the position determined by the combination of the offset and the whence. CFS_SEEK_SET tells cfs_seek() to compute the offset from the beginning of the file, i.e., as an absolute offset. CFS_SEEK_CUR specifies that the offset should be compute relative to the current position of the file position. Similarly, CFS_SEEK_END computes the offset in relation to the end of the file, and can be used to move beyond the end if the file system implementation allows it. Negative offset values are accepted by both CFS_SEEK_CUR and CFS_SEEK_END, if the program wishes to move the file position backwards from the base that is indicated by the whence parameter. cfs_seek() returns the new absolute file position upon success, or -1 if the file pointer could not be moved to the requested position.[1]&lt;br /&gt;
==== cfs_remove ====&lt;br /&gt;
cfs_remove remove the file correspond to the name. It first find the file by find_file(name). After that invoke remove_by_page to delete the file.&lt;br /&gt;
&lt;br /&gt;
== Coding With Coffee API   ==&lt;br /&gt;
Modify the code provided by Contiki.&amp;lt;br&amp;gt;&lt;br /&gt;
Open contiki-2.7/examples/sky/example-coffee.c, then rewrite the file_test function.&amp;lt;br&amp;gt;&lt;br /&gt;
The Idea is based on Zane D. Purvis&amp;#039;s Coffee filesystem example.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2011, 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;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs-coffee.h&amp;quot;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_coffee_process, &amp;quot;Coffee example&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_coffee_process);&lt;br /&gt;
#define FILENAME &amp;quot;test&amp;quot;&lt;br /&gt;
/* Formatting is needed if the storage device is in an unknown state; &lt;br /&gt;
   e.g., when using Coffee on the storage device for the first time. */&lt;br /&gt;
#ifndef NEED_FORMATTING&lt;br /&gt;
#define NEED_FORMATTING 0&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
static int&lt;br /&gt;
file_test(const char *filename, char *msg)&lt;br /&gt;
{&lt;br /&gt;
	int fd;&lt;br /&gt;
	int r;&lt;br /&gt;
	char message[32];&lt;br /&gt;
	char buf[64];&lt;br /&gt;
	strncpy(message, &amp;quot;First Message&amp;quot;, sizeof(message) - 1);&lt;br /&gt;
	message[sizeof(message) - 1] = &amp;#039;\0&amp;#039;;&lt;br /&gt;
	strcpy(buf,message);&lt;br /&gt;
	/*First message is to test if the write will succeed*/&lt;br /&gt;
	printf(&amp;quot;Write Test: Will write \&amp;quot;%s\&amp;quot; to file \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf,FILENAME);&lt;br /&gt;
&lt;br /&gt;
  /* Obtain a file descriptor for the file, capable of handling both &lt;br /&gt;
     reads and writes. */&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  /*Write message to Filesystem*/&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,&lt;br /&gt;
				(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Write Test: Successfully wrote \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; wrote %d bytes\n &amp;quot;,message,FILENAME,r);&lt;br /&gt;
&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_read(fd, buf, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
      /* compare with the original message to see if the message was read &lt;br /&gt;
      correctly, if it reads fail then it will print fail*/&lt;br /&gt;
	printf(&amp;quot;Read Test: Read \&amp;quot;%s\&amp;quot; from \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf, FILENAME);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
     /*Append test */&lt;br /&gt;
	strcpy(message,&amp;quot;Append Something&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Append Test: Successfully \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; \n &amp;quot;,message,FILENAME);&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read First Part \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
       /*seek test*/&lt;br /&gt;
	if(cfs_seek(fd, sizeof(message), CFS_SEEK_SET) == -1) {&lt;br /&gt;
		printf(&amp;quot;seek failed\n&amp;quot;);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  //cfs_seek(fd, sizeof(message), CFS_SEEK_SET);&lt;br /&gt;
    /*if the seek fails then the second message will not &lt;br /&gt;
    be the same as the last message write to the file*/&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read Second Part: \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
  /* Release the internal resources held by Coffee for&lt;br /&gt;
     the file descriptor. */&lt;br /&gt;
	cfs_remove(FILENAME);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd != -1) {&lt;br /&gt;
		printf(&amp;quot;ERROR: could read from memory\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;Successfully removed file\n&amp;quot;);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&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;
#if NEED_FORMATTING&lt;br /&gt;
  cfs_coffee_format();&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
  /* Ensure that we will be working with a new file. */&lt;br /&gt;
  cfs_remove(FILENAME);&lt;br /&gt;
&lt;br /&gt;
  if(file_test(FILENAME, &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;
  printf(&amp;quot;test succeed\n&amp;quot;);&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;
== Simulation Result  ==&lt;br /&gt;
[[File:result.png|850px]]&amp;lt;br&amp;gt;&lt;br /&gt;
We can see that Coffee File System works well.&lt;br /&gt;
&lt;br /&gt;
== General Issues ==&lt;br /&gt;
1. Use sizeof() instead strlen() in the strncpy() function.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Remember to include string.h, otherwise when you compile it will generate warnings.&lt;br /&gt;
&lt;br /&gt;
==Reference ==&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/File-systems] - Zane D. Purvis, &amp;quot;Coffee filesystem&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-example] - Zane D. Purvis, &amp;quot;Coffee filesystem example&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Zhikun Liu&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1853</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1853"/>
				<updated>2016-10-07T19:07:31Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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]]&lt;br /&gt;
# [[Timers]]&lt;br /&gt;
# [[CFS-Coffee]]&lt;br /&gt;
# [[Cooja Simulator]]&lt;br /&gt;
# [[Network Stack]]&lt;br /&gt;
# [[RPL UDP]]&lt;br /&gt;
# [[Contiki Shell]]&lt;br /&gt;
&lt;br /&gt;
Need review&lt;br /&gt;
# [[RSS measurement]]&lt;br /&gt;
&lt;br /&gt;
Starting&lt;br /&gt;
# [[RPL objective function &amp;amp; simulation using DGRM model in cooja]]&lt;br /&gt;
# [[MAC protocols in ContikiOS]]&lt;br /&gt;
# [[RPL Border Router]]&lt;br /&gt;
# [[REST example running on Cooja and Sky motes]]&lt;br /&gt;
# [[Trickle library]]&lt;br /&gt;
# [[Packetbuffer Basics]]&lt;br /&gt;
# [[Antelope(Database Management System)]]&lt;br /&gt;
# [[Mobility of Nodes in Cooja]]&lt;br /&gt;
# [[Contiki Coffee File System]]&lt;br /&gt;
# [[Contiki Programming Guide]]&lt;br /&gt;
# [[Analyse of a real 6LoWPAN network using a Contiki-based sniffer module]]&lt;br /&gt;
# [[Build your own application in Contiki]]&lt;br /&gt;
# [[Processes]] Yash&lt;br /&gt;
# [[RPL objective function modification and simulation in cooja]]&lt;br /&gt;
# [[Collect-view Code Details]] Pradipta&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1852</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1852"/>
				<updated>2016-10-07T19:04:39Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Understanding the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values for every packet received in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
The functions of some code snippets are mentioned below,&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in &amp;#039;&amp;#039;&amp;#039;recv()&amp;#039;&amp;#039;&amp;#039; function, see page 49 at http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin, Samarth Pai&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1851</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1851"/>
				<updated>2016-10-07T19:02:49Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Understanding the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values for every packet received in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
The functions of some code snippets are mentioned below,&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt; collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;code&amp;gt; etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in &amp;#039;&amp;#039;&amp;#039;recv()&amp;#039;&amp;#039;&amp;#039; function, see page 49 at http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin, Samarth Pai&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1850</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1850"/>
				<updated>2016-10-07T18:51:04Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* 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;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values for every packet received in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1849</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1849"/>
				<updated>2016-10-07T18:50:41Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Step 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values for every packet received in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1848</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1848"/>
				<updated>2016-10-07T18:50:13Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Step 5 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1847</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1847"/>
				<updated>2016-10-07T18:50:00Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Step 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
Note: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1846</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1846"/>
				<updated>2016-10-07T18:49:36Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Step 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
Note: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
Note: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI values in the mote output window. These values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1845</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1845"/>
				<updated>2016-10-07T18:48:42Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Step 7 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
Note: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select the number of motes required in the network. You may select any number of motes but for simplicity we are considering only 2 motes.&lt;br /&gt;
&lt;br /&gt;
Note: We are uploading the same firmware on both the motes, one acting as Transmitter and the other as Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
The &amp;#039;Mote Output&amp;#039; window gives real time information of the events occurring in the simulation process.&lt;br /&gt;
&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

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

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

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1842</id>
		<title>RSS measurement</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RSS_measurement&amp;diff=1842"/>
				<updated>2016-10-07T18:43:21Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* 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;
Radio Signal Strength (RSS) refers to the transmitter power output as received by a reference antenna (i.e. receiver) placed at a distance from the transmitting antenna.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to measure the Radio Signal Strength received by a Tmote Sky module. The tutorial has two nodes, a transmitter and a receiver. The receiver node continuously receives packets from the transmitting node, measures its signal strength and displays the RSS value of the packet received.&lt;br /&gt;
&lt;br /&gt;
A step-by-step description of the simulation process and the C source code can be found in the subsequent sections.&lt;br /&gt;
&lt;br /&gt;
== RSS Measurement using Cooja Simulator ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
Run &amp;#039;ant&amp;#039; to start Cooja. Create New Simulation and let us say we name our simulation as &amp;quot;RSS&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_1.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
Add motes to the simulation. Go to Motes-&amp;gt; Add motes-&amp;gt; Create a new mote type-&amp;gt; and select Sky Mote to be added to the network.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_2.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 3 ===&lt;br /&gt;
Browse and select the firmware.&lt;br /&gt;
&lt;br /&gt;
Note: You have to create a .c file for RSS measurement and the source code can be found in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_3.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 4 ===&lt;br /&gt;
Compile the firmware.&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_4.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 5 ===&lt;br /&gt;
Select number of motes. You can select any number of motes, but for simplicity we are considering only 2 motes. Note: We are uploading the same firmware on both the motes, one acting as a Transmitter and the other as a Receiver.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_5.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
=== Step 6 ===&lt;br /&gt;
Start the simulation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_6.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Step 7 ===&lt;br /&gt;
You can see the RSSI value in the mote output window. These RSSI values are in &amp;#039;&amp;#039;&amp;#039;dBm&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:RSS_7.png|center|800px]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;HEADER FILES&amp;gt;&lt;br /&gt;
&lt;br /&gt;
static struct collect_conn tc;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_collect_process, &amp;quot;RSS Measurement&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_collect_process);&lt;br /&gt;
&lt;br /&gt;
static void recv(const rimeaddr_t *originator, uint8_t seqno, uint8_t hops)&lt;br /&gt;
{&lt;br /&gt;
  static signed char rss;&lt;br /&gt;
  static signed char rss_val;&lt;br /&gt;
  static signed char rss_offset;&lt;br /&gt;
  printf(&amp;quot;Sink got message from %d.%d, seqno %d, hops %d: len %d &amp;#039;%s&amp;#039;\n&amp;quot;,originator-&amp;gt;u8[0], originator-&amp;gt;u8[1],seqno, hops,packetbuf_datalen(),&lt;br /&gt;
         (char *)packetbuf_dataptr());&lt;br /&gt;
  rss_val = cc2420_last_rssi;&lt;br /&gt;
  rss_offset=-45;&lt;br /&gt;
  rss=rss_val + rss_offset;&lt;br /&gt;
  printf(&amp;quot;RSSI of Last Packet Received is %d\n&amp;quot;,rss);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static const struct collect_callbacks callbacks = { recv };&lt;br /&gt;
&lt;br /&gt;
PROCESS_THREAD(example_collect_process, ev, data)&lt;br /&gt;
{&lt;br /&gt;
  static struct etimer periodic;&lt;br /&gt;
  static struct etimer et;&lt;br /&gt;
  &lt;br /&gt;
  PROCESS_BEGIN();&lt;br /&gt;
&lt;br /&gt;
  collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&lt;br /&gt;
&lt;br /&gt;
  if(rimeaddr_node_addr.u8[0] == 1 &amp;amp;&amp;amp; rimeaddr_node_addr.u8[1] == 0) &lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;I am sink\n&amp;quot;);&lt;br /&gt;
    collect_set_sink(&amp;amp;tc, 1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* Allow some time for the network to settle. */&lt;br /&gt;
  etimer_set(&amp;amp;et, 120 * CLOCK_SECOND);&lt;br /&gt;
  PROCESS_WAIT_UNTIL(etimer_expired(&amp;amp;et));&lt;br /&gt;
&lt;br /&gt;
  while(1) &lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
    /* Send a packet every 1 seconds. */&lt;br /&gt;
    if(etimer_expired(&amp;amp;periodic)) &lt;br /&gt;
    {&lt;br /&gt;
      etimer_set(&amp;amp;periodic, CLOCK_SECOND * 1 );&lt;br /&gt;
      etimer_set(&amp;amp;et, random_rand() % (CLOCK_SECOND * 1));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    PROCESS_WAIT_EVENT();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    if(etimer_expired(&amp;amp;et)) &lt;br /&gt;
    {&lt;br /&gt;
      static rimeaddr_t oldparent;&lt;br /&gt;
      const rimeaddr_t *parent;&lt;br /&gt;
      if(rimeaddr_node_addr.u8[0] != 1 )&lt;br /&gt;
      {&lt;br /&gt;
        printf(&amp;quot;Sending\n&amp;quot;);&lt;br /&gt;
        packetbuf_clear();&lt;br /&gt;
        packetbuf_set_datalen(sprintf(packetbuf_dataptr(),&amp;quot;%s&amp;quot;, &amp;quot;Fight On&amp;quot;) + 1);&lt;br /&gt;
        collect_send(&amp;amp;tc, 15);&lt;br /&gt;
&lt;br /&gt;
        parent = collect_parent(&amp;amp;tc);&lt;br /&gt;
        if(!rimeaddr_cmp(parent, &amp;amp;oldparent)) &lt;br /&gt;
        {&lt;br /&gt;
           if(!rimeaddr_cmp(&amp;amp;oldparent, &amp;amp;rimeaddr_null))&lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 0\n&amp;quot;, oldparent.u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           if(!rimeaddr_cmp(parent, &amp;amp;rimeaddr_null)) &lt;br /&gt;
           {&lt;br /&gt;
              printf(&amp;quot;#L %d 1\n&amp;quot;, parent-&amp;gt;u8[0]);&lt;br /&gt;
           }&lt;br /&gt;
           &lt;br /&gt;
           rimeaddr_copy(&amp;amp;oldparent, parent);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  } //end of while&lt;br /&gt;
&lt;br /&gt;
  PROCESS_END();&lt;br /&gt;
} //end of process thread&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Understanding the Code ==&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;1-static const struct collect_callbacks callbacks = { recv };&amp;lt;/code&amp;gt;&lt;br /&gt;
callbacks = { recv } calls the recv() function when a packet is received.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;2-collect_open(&amp;amp;tc, 130, COLLECT_ROUTER, &amp;amp;callbacks);&amp;lt;/code&amp;gt;&lt;br /&gt;
Opens a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;3-collect_set_sink(&amp;amp;tc, 1);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sets the node as sink. Note that we are setting node 1.0 as the sink here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;4-collect_send(&amp;amp;tc, 15);&amp;lt;/code&amp;gt;&lt;br /&gt;
Sends data through the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
::&amp;lt;code&amp;gt;5-etimer_set(&amp;amp;et, CLOCK_SECOND * 1);&amp;lt;/code&amp;gt; &lt;br /&gt;
This will set the timer to repeat the iterations every 1 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;6-if(rimeaddr_node_addr.u8[0] != 1 )&amp;lt;/code&amp;gt;&lt;br /&gt;
This if condition will work only for the source nodes i.e. node id != 1.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand the calculations performed in recv() function, see page 49 on this link http://web.stanford.edu/class/cs244e/papers/cc2420.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Edited by : Nitin&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

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

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

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1838</id>
		<title>Contiki Coffee File System</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Coffee_File_System&amp;diff=1838"/>
				<updated>2016-10-04T21:07:10Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The tutorial covers the main features of Coffee File System available in ContikiOS 2.7.&amp;lt;br&amp;gt;Contiki provides a set of file systems for using various kinds of storage devices in resource-constrained systems. All of these file systems implement a subset of the Contiki File System (CFS) interface, and two of them provide the full functionality: CFS-POSIX and Coffee[1]. Coffee is used with device equipped with flash memories or EEPROM. Contiki takes care of underlying hardware implementation. Coffee file system will provide a API which is similar to normal C file operations: Open a file, read and write to it and then close it. &amp;lt;br&amp;gt; Due to the restrained resource and affected by the environment, the data transmission will get lost sometimes, which then need to be retransmitted, applying file system in the wireless sensor node will help to make the system become more reliable by store the data in the nodes locally. Since we can store the data in the node locally then we can send multiple data via one transmission, which leads to less number of transmission, then reduce the power consumption.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial you are going  to understand how the Coffee file system works. And get to know how to program with the coffee file system API.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/cfs/cfs-coffee.h&amp;lt;br&amp;gt;&lt;br /&gt;
~/contiki-2.7/core/cfs/cfs-coffee.c&lt;br /&gt;
&lt;br /&gt;
== Coffee File System API ==&lt;br /&gt;
&lt;br /&gt;
=== Memory Organization ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * The protected memory consists of structures that should not be &lt;br /&gt;
 * overwritten during system checkpointing because they may be used by &lt;br /&gt;
 * the checkpointing implementation. These structures need not be &lt;br /&gt;
 * protected if checkpointing is not used.&lt;br /&gt;
 */&lt;br /&gt;
static struct protected_mem_t {&lt;br /&gt;
  struct file coffee_files[COFFEE_MAX_OPEN_FILES];&lt;br /&gt;
  struct file_desc coffee_fd_set[COFFEE_FD_SET_SIZE];&lt;br /&gt;
  coffee_page_t next_free;&lt;br /&gt;
  char gc_wait;&lt;br /&gt;
} protected_mem;&lt;br /&gt;
static struct file * const coffee_files = protected_mem.coffee_files;&lt;br /&gt;
static struct file_desc * const coffee_fd_set = protected_mem.coffee_fd_set;&lt;br /&gt;
static coffee_page_t * const next_free = &amp;amp;protected_mem.next_free;&lt;br /&gt;
static char * const gc_wait = &amp;amp;protected_mem.gc_wait;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:coffee-structure.png]][1]&amp;lt;br&amp;gt;&lt;br /&gt;
Coffee File System organize the file_desc as an array and mark it as a member in the protected_mem_t.&lt;br /&gt;
&lt;br /&gt;
=== get_available_fd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static int&lt;br /&gt;
get_available_fd(void)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_FD_SET_SIZE; i++) {&lt;br /&gt;
    if(coffee_fd_set[i].flags == COFFEE_FD_FREE) {&lt;br /&gt;
      return i;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Contiki is a Linux like system, everything is a file, and the opened file is represented by the file descriptor. The get_available_fd will return the smallest available fd by check the file_desc array in an ascending order, the first one with flag == 0(COFFEE_FD_FREE) is what we want. If all the flags are set, then return -1.&lt;br /&gt;
&lt;br /&gt;
=== find_file ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static struct file *&lt;br /&gt;
find_file(const char *name)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  struct file_header hdr;&lt;br /&gt;
  coffee_page_t page;&lt;br /&gt;
  &lt;br /&gt;
  /* First check if the file metadata is cached. */&lt;br /&gt;
  for(i = 0; i &amp;lt; COFFEE_MAX_OPEN_FILES; i++) {&lt;br /&gt;
    if(FILE_FREE(&amp;amp;coffee_files[i])) {&lt;br /&gt;
      continue;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    read_header(&amp;amp;hdr, coffee_files[i].page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return &amp;amp;coffee_files[i];&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  /* Scan the flash memory sequentially otherwise. */&lt;br /&gt;
  for(page = 0; page &amp;lt; COFFEE_PAGE_COUNT; page = next_file(page, &amp;amp;hdr)) {&lt;br /&gt;
    read_header(&amp;amp;hdr, page);&lt;br /&gt;
    if(HDR_ACTIVE(hdr) &amp;amp;&amp;amp; !HDR_LOG(hdr) &amp;amp;&amp;amp; strcmp(name, hdr.name) == 0) {&lt;br /&gt;
      return load_file(page, &amp;amp;hdr);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return NULL;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If the file correspond to the name is still resides in coffee_files[COFFEE_MAX_OPEN_FILES] and the physical file is still valid then it return the pointer to that file, otherwise scan the FLSAH, and cache the file into memory.&lt;br /&gt;
&lt;br /&gt;
=== The CFS Programming Interface ===&lt;br /&gt;
&lt;br /&gt;
==== cfs_open ====&lt;br /&gt;
cf_open is  used to open a file. If it successfully open the file then it returns the file descriptor(fd), otherwise it returns -1.&amp;lt;br&amp;gt;&lt;br /&gt;
cfs_open source code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int&lt;br /&gt;
cfs_open(const char *name, int flags)&lt;br /&gt;
{&lt;br /&gt;
  int fd;&lt;br /&gt;
  struct file_desc *fdp;&lt;br /&gt;
&lt;br /&gt;
  fd = get_available_fd(); //find the smallest available fd, see section 4.2&lt;br /&gt;
  if(fd &amp;lt; 0) {&lt;br /&gt;
    PRINTF(&amp;quot;Coffee: Failed to allocate a new file descriptor!\n&amp;quot;);&lt;br /&gt;
    return -1;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp = &amp;amp;coffee_fd_set[fd];&lt;br /&gt;
  fdp-&amp;gt;flags = 0; //set the fd to FREE&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;file = find_file(name); //find the file corresponding to name(not exist, In flash but not cached, cached)&lt;br /&gt;
&lt;br /&gt;
  /*** if there isn&amp;#039;t any corresponding file, then try to create new file ***/&lt;br /&gt;
  if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
    if((flags &amp;amp; (CFS_READ | CFS_WRITE)) == CFS_READ) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file = reserve(name, page_count(COFFEE_DYN_SIZE), 1, 0);&lt;br /&gt;
    if(fdp-&amp;gt;file == NULL) {&lt;br /&gt;
      return -1;&lt;br /&gt;
    }&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = 0; // Since it&amp;#039;s a new created file, the end will be set to 0&lt;br /&gt;
  }&lt;br /&gt;
   /*** find the file,seek for the end of the file***/ &lt;br /&gt;
   else if(fdp-&amp;gt;file-&amp;gt;end == UNKNOWN_OFFSET) {&lt;br /&gt;
    fdp-&amp;gt;file-&amp;gt;end = file_end(fdp-&amp;gt;file-&amp;gt;page);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  fdp-&amp;gt;flags |= flags;&lt;br /&gt;
  fdp-&amp;gt;offset = flags &amp;amp; CFS_APPEND ? fdp-&amp;gt;file-&amp;gt;end : 0; //if the flag is set to APPEND, then the offset is set to the end of the file, otherwise set to 0&lt;br /&gt;
  fdp-&amp;gt;file-&amp;gt;references++; //reference count will increment&lt;br /&gt;
&lt;br /&gt;
  return fd;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
==== cfs_close ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void cfs_close(int fd)&lt;br /&gt;
{&lt;br /&gt;
  if (FD_VALID(fd))&lt;br /&gt;
  {&lt;br /&gt;
    coffee_fd_set[fd].flags = COFFEE_FD_FREE;&lt;br /&gt;
    coffee_fd_set[fd].file-&amp;gt;references--;&lt;br /&gt;
    coffee_fd_set[fd].file = NULL;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#define FD_VALID(fd) ((fd)&amp;gt;= 0 &amp;amp;&amp;amp; (fd)&amp;lt;COFFEE_FD_SET_SIZE &amp;amp;&amp;amp; coffee_fd_set[(fd)].flags!=COFFEE_FD_FREE)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
When an open file is no longer needed, the application should close it by using cfs_close(). By closing a file, the file system can deallocate its internal resources held for the file, and possibly commit any cached data to permanent storage.[1]&amp;lt;br&amp;gt;&lt;br /&gt;
It first make sure fd is valid, then set the flag in this fd_desc to COFFEE_FD_FREE, and then decrease the reference count of that file. Finally set the file_desc point to NULL.&lt;br /&gt;
&lt;br /&gt;
==== cfs_read ====&lt;br /&gt;
cfs_read() fills buf with at most len bytes, starting from the current position in the file that is stored in the file descriptor. It returns the amount of bytes read, or -1 if an error occurs.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_write ====&lt;br /&gt;
cfs_write() writes len bytes from the memory buffer buf into the file, starting from the current position in the file descriptor. The file must have been opened with the CFS_WRITE flag. It returns the amount of bytes written, or -1 if an error occurred.[1]&lt;br /&gt;
&lt;br /&gt;
==== cfs_seek ====&lt;br /&gt;
cfs_seek() moves the current file position to the position determined by the combination of the offset and the whence. CFS_SEEK_SET tells cfs_seek() to compute the offset from the beginning of the file, i.e., as an absolute offset. CFS_SEEK_CUR specifies that the offset should be compute relative to the current position of the file position. Similarly, CFS_SEEK_END computes the offset in relation to the end of the file, and can be used to move beyond the end if the file system implementation allows it. Negative offset values are accepted by both CFS_SEEK_CUR and CFS_SEEK_END, if the program wishes to move the file position backwards from the base that is indicated by the whence parameter. cfs_seek() returns the new absolute file position upon success, or -1 if the file pointer could not be moved to the requested position.[1]&lt;br /&gt;
==== cfs_remove ====&lt;br /&gt;
cfs_remove remove the file correspond to the name. It first find the file by find_file(name). After that invoke remove_by_page to delete the file.&lt;br /&gt;
&lt;br /&gt;
== Coding With Coffee API   ==&lt;br /&gt;
Modify the code provided by Contiki.&amp;lt;br&amp;gt;&lt;br /&gt;
Open contiki-2.7/examples/sky/example-coffee.c, then rewrite the file_test function.&amp;lt;br&amp;gt;&lt;br /&gt;
The Idea is based on Zane D. Purvis&amp;#039;s Coffee filesystem example.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2011, 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;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;quot;contiki.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs.h&amp;quot;&lt;br /&gt;
#include &amp;quot;cfs/cfs-coffee.h&amp;quot;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PROCESS(example_coffee_process, &amp;quot;Coffee example&amp;quot;);&lt;br /&gt;
AUTOSTART_PROCESSES(&amp;amp;example_coffee_process);&lt;br /&gt;
#define FILENAME &amp;quot;test&amp;quot;&lt;br /&gt;
/* Formatting is needed if the storage device is in an unknown state; &lt;br /&gt;
   e.g., when using Coffee on the storage device for the first time. */&lt;br /&gt;
#ifndef NEED_FORMATTING&lt;br /&gt;
#define NEED_FORMATTING 0&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
static int&lt;br /&gt;
file_test(const char *filename, char *msg)&lt;br /&gt;
{&lt;br /&gt;
	int fd;&lt;br /&gt;
	int r;&lt;br /&gt;
	char message[32];&lt;br /&gt;
	char buf[64];&lt;br /&gt;
	strncpy(message, &amp;quot;First Message&amp;quot;, sizeof(message) - 1);&lt;br /&gt;
	message[sizeof(message) - 1] = &amp;#039;\0&amp;#039;;&lt;br /&gt;
	strcpy(buf,message);&lt;br /&gt;
	/*First message is to test if the write will succeed*/&lt;br /&gt;
	printf(&amp;quot;Write Test: Will write \&amp;quot;%s\&amp;quot; to file \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf,FILENAME);&lt;br /&gt;
&lt;br /&gt;
  /* Obtain a file descriptor for the file, capable of handling both &lt;br /&gt;
     reads and writes. */&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  /*Write message to Filesystem*/&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,&lt;br /&gt;
				(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Write Test: Successfully wrote \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; wrote %d bytes\n &amp;quot;,message,FILENAME,r);&lt;br /&gt;
&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_read(fd, buf, sizeof(message));&lt;br /&gt;
	if(r != sizeof(message)) {&lt;br /&gt;
		printf(&amp;quot;failed to write %d bytes to %s\n&amp;quot;,(int)sizeof(message), FILENAME);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
      /* compare with the original message to see if the message was read &lt;br /&gt;
      correctly, if it reads fail then it will print fail*/&lt;br /&gt;
	printf(&amp;quot;Read Test: Read \&amp;quot;%s\&amp;quot; from \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf, FILENAME);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
     /*Append test */&lt;br /&gt;
	strcpy(message,&amp;quot;Append Something&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_WRITE | CFS_APPEND | CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	r = cfs_write(fd, message, sizeof(message));&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
	printf(&amp;quot;Append Test: Successfully \&amp;quot;%s\&amp;quot; to \&amp;quot;%s\&amp;quot; \n &amp;quot;,message,FILENAME);&lt;br /&gt;
	strcpy(buf,&amp;quot;fail&amp;quot;);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd &amp;lt; 0) {&lt;br /&gt;
		printf(&amp;quot;failed to open %s\n&amp;quot;, FILENAME);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read First Part \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
       /*seek test*/&lt;br /&gt;
	if(cfs_seek(fd, sizeof(message), CFS_SEEK_SET) == -1) {&lt;br /&gt;
		printf(&amp;quot;seek failed\n&amp;quot;);&lt;br /&gt;
		cfs_close(fd);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
  //cfs_seek(fd, sizeof(message), CFS_SEEK_SET);&lt;br /&gt;
    /*if the seek fails then the second message will not &lt;br /&gt;
    be the same as the last message write to the file*/&lt;br /&gt;
	cfs_read(fd,buf,sizeof(message));&lt;br /&gt;
	printf(&amp;quot;Read Second Part: \&amp;quot;%s\&amp;quot;\n&amp;quot;,buf);&lt;br /&gt;
	cfs_close(fd);&lt;br /&gt;
  /* Release the internal resources held by Coffee for&lt;br /&gt;
     the file descriptor. */&lt;br /&gt;
	cfs_remove(FILENAME);&lt;br /&gt;
	fd = cfs_open(FILENAME, CFS_READ);&lt;br /&gt;
	if(fd != -1) {&lt;br /&gt;
		printf(&amp;quot;ERROR: could read from memory\n&amp;quot;);&lt;br /&gt;
		return 0;&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;Successfully removed file\n&amp;quot;);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&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;
#if NEED_FORMATTING&lt;br /&gt;
  cfs_coffee_format();&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
  /* Ensure that we will be working with a new file. */&lt;br /&gt;
  cfs_remove(FILENAME);&lt;br /&gt;
&lt;br /&gt;
  if(file_test(FILENAME, &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;
  printf(&amp;quot;test succeed\n&amp;quot;);&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;
== Simulation Result  ==&lt;br /&gt;
[[File:result.png|850px]]&amp;lt;br&amp;gt;&lt;br /&gt;
We can see that Coffee File System works well.&lt;br /&gt;
&lt;br /&gt;
== General Issues ==&lt;br /&gt;
1. Use sizeof() instead strlen() in the strncpy() function.&amp;lt;br&amp;gt;&lt;br /&gt;
2. Remember to include string.h, otherwise when you compile it will generate warnings.&lt;br /&gt;
&lt;br /&gt;
==Reference ==&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/File-systems] - Zane D. Purvis, &amp;quot;Coffee filesystem&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-example] - Zane D. Purvis, &amp;quot;Coffee filesystem example&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Zhikun Liu&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

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

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

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

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

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1814</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1814"/>
				<updated>2016-09-22T22:46:11Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Issues you might face */&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;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The goal of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
The tutorial gives detailed description on 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;
&lt;br /&gt;
The source code and header files for Contiki Shell can be found in the following folder,&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following path has the example-shell project,&lt;br /&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;
&lt;br /&gt;
The sky-shell project can be found at, &lt;br /&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 the possible shell_xx_init()&amp;#039;s are used in the firmware image of Contiki shell. This will result in compilation failure. By Trial and error method, figure out 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; While running Contiki serial shell, garbage values might be displayed in the shell due to invalid data or commands. In such cases either reboot the serial shell using the &amp;#039;reboot&amp;#039; command 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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1813</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1813"/>
				<updated>2016-09-22T22:43:56Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Issues you might face */&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;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The goal of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
The tutorial gives detailed description on 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;
&lt;br /&gt;
The source code and header files for Contiki Shell can be found in the following folder,&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following path has the example-shell project,&lt;br /&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;
&lt;br /&gt;
The sky-shell project can be found at, &lt;br /&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; While running Contiki serial shell, garbage values might be displayed in the shell due to invalid data or commands. In such cases either reboot the serial shell using the &amp;#039;reboot&amp;#039; command 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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1812</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1812"/>
				<updated>2016-09-22T22:42:44Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Issues you might face */&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;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The goal of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
The tutorial gives detailed description on 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;
&lt;br /&gt;
The source code and header files for Contiki Shell can be found in the following folder,&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following path has the example-shell project,&lt;br /&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;
&lt;br /&gt;
The sky-shell project can be found at, &lt;br /&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; While running Contiki serial shell, garbage values might be displayed in the shell due to invalid data or commands. 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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1811</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1811"/>
				<updated>2016-09-22T22:40:38Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Source Code and Example Projects */&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;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The goal of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
The tutorial gives detailed description on 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;
&lt;br /&gt;
The source code and header files for Contiki Shell can be found in the following folder,&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039; ~/contiki-2.7/apps/shell &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following path has the example-shell project,&lt;br /&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;
&lt;br /&gt;
The sky-shell project can be found at, &lt;br /&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1810</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1810"/>
				<updated>2016-09-22T22:33:22Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* You will learn */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The goal of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&lt;br /&gt;
&lt;br /&gt;
== You will learn ==&lt;br /&gt;
&lt;br /&gt;
The tutorial gives detailed description on 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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1809</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1809"/>
				<updated>2016-09-22T22:31:22Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Objective */&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;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The goal of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1808</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1808"/>
				<updated>2016-09-22T22:30:56Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Objective */&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;
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;
The various instances of shells provided in Contiki are:&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; and &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;
The aim of the tutorial is to familiarize the user with the various shells provided in the Contiki operating system.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will learn how to install Contiki Shell, the various Contiki shell commands and their usage.&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1807</id>
		<title>Contiki Shell</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&amp;diff=1807"/>
				<updated>2016-09-22T22:24:06Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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;
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;
The various instances of shells provided in Contiki are:&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; and &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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1806</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1806"/>
				<updated>2016-09-22T22:20:21Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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;
# [[RPL UDP]] Jiahao Liang&lt;br /&gt;
# [[Contiki Shell]] Abhilash Nagaraj Hegde&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;
# [[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 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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1805</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1805"/>
				<updated>2016-09-10T00:07:39Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The motes output and debug messages generated can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&lt;br /&gt;
&lt;br /&gt;
The output messages saved in the file can later be used to make observations and plot graphs according to the objective of the experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Edited by: Jiahao Liang, Samarth Pai&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1804</id>
		<title>Network Stack</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Network_Stack&amp;diff=1804"/>
				<updated>2016-09-10T00:06:03Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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;br /&gt;
&lt;br /&gt;
Edited by: Mugdhe, Samarth Pai&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1803</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1803"/>
				<updated>2016-09-10T00:02:38Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Cooja Simulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The motes output and debug messages generated can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&lt;br /&gt;
&lt;br /&gt;
The output messages saved in the file can later be used to make observations and plot graphs according to the objective of the experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1802</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1802"/>
				<updated>2016-09-09T23:59:57Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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;
# [[RPL UDP]] Jiahao Liang&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;
# [[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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1801</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1801"/>
				<updated>2016-09-08T23:05:50Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: Undo revision 1800 by Paisamar (talk)&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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1800</id>
		<title>Contiki tutorials</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=Contiki_tutorials&amp;diff=1800"/>
				<updated>2016-09-08T23:05:07Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: &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>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1799</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1799"/>
				<updated>2016-09-07T00:25:10Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Cooja Simulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The motes output and debug messages generated can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&lt;br /&gt;
&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1798</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1798"/>
				<updated>2016-09-07T00:11:17Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Cooja Simulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Watch Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The motes output and debug messages can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&amp;lt;br&amp;gt;&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1797</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1797"/>
				<updated>2016-09-07T00:10:27Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Cooja Simulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki-2.7/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Watch Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The motes output and debug messages can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&amp;lt;br&amp;gt;&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1796</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1796"/>
				<updated>2016-09-07T00:09:47Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* Sends packet */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki-2.7/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Watch Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The motes output and debug messages can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&amp;lt;br&amp;gt;&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1795</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1795"/>
				<updated>2016-09-07T00:09:30Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* receives and processes incoming packet */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Receives and Processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki-2.7/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Watch Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The motes output and debug messages can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&amp;lt;br&amp;gt;&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1794</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1794"/>
				<updated>2016-09-07T00:08:56Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* create UDP connection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Set up a UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===receives and processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki-2.7/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Watch Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The motes output and debug messages can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&amp;lt;br&amp;gt;&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	<entry>
		<id>http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1793</id>
		<title>RPL UDP</title>
		<link rel="alternate" type="text/html" href="http://anrg.usc.edu/contiki/index.php?title=RPL_UDP&amp;diff=1793"/>
				<updated>2016-09-07T00:08:02Z</updated>
		
		<summary type="html">&lt;p&gt;Paisamar: /* UDP Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RPL is the IPv6 Routing Protocol for Low-power and Lossy Networks (LLNs).  LLNs are a class of network in which both the routers and their interconnect are constrained.  LLN routers typically operate with constraints on processing power, memory, and energy. RPL provides a mechanism whereby multipoint-to-point traffic from devices inside the LLN towards a central control point as well  as point-to-multipoint traffic from the central control point to the devices inside the LLN are supported.  Support for point-to-point traffic is also available.&lt;br /&gt;
&lt;br /&gt;
In this example, UDP is implemented on top of RPL. A LLN is comprised of a UDP server, which accepts available packets, and several UDP clients, which send packets periodically to server through single-hop or multi-hops.&lt;br /&gt;
&lt;br /&gt;
== You Will Learn ==&lt;br /&gt;
&lt;br /&gt;
Through this tutorial, you will learn the basic idea of RPL and operate UDP communications with ease without manipulating lower layer functions.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-server.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/examples/ipv6/rpl-udp/udp-client.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.c&lt;br /&gt;
&lt;br /&gt;
~/contiki-2.7/core/net/tcpip.h&lt;br /&gt;
&lt;br /&gt;
== RPL Basics ==&lt;br /&gt;
&lt;br /&gt;
[[File:contiki_stacks.jpg|200px|right|frame|Contiki Layers]]&lt;br /&gt;
&lt;br /&gt;
RPL was designed with the objective to meet the requirements spelled out in [https://tools.ietf.org/html/rfc5867 RFC5867], [https://tools.ietf.org/html/rfc5826 RFC5826], [https://tools.ietf.org/html/rfc5673 RFC5673], and [https://tools.ietf.org/html/rfc5548 RFC5548].&lt;br /&gt;
&lt;br /&gt;
In order to be useful in a wide range of LLN application domains, RPL separates packet processing and forwarding from the routing optimization objective.  Examples of such objectives includes minimizing energy, minimizing latency, or satisfying constraints. A RPL implementation, in support of a particular LLN application, will include the necessary Objective Function(s) as required by the application.&lt;br /&gt;
&lt;br /&gt;
RPL operations require bidirectional links.  In some LLN scenarios, those links may exhibit asymmetric properties.  It is required that the reachability of a router be verified before the router can be used as a parent.  RPL expects an external mechanism to be triggered during the parent selection phase in order to verify link properties and neighbor reachability.  &lt;br /&gt;
&lt;br /&gt;
RPL also expects an external mechanism to access and transport some control information, referred to as the &amp;quot;RPL Packet Information&amp;quot;, in data packets.   RPL provides a mechanism to disseminate information over the  dynamically formed network topology.  This dissemination enables minimal configuration in the nodes, allowing nodes to operate mostly  autonomously.  &lt;br /&gt;
&lt;br /&gt;
In particular, RPL may disseminate IPv6 Neighbor Discovery (ND) information such as the [https://tools.ietf.org/html/rfc4861 RFC4861] Prefix Information Option (PIO) and the [https://tools.ietf.org/html/rfc4191 RFC4191] Route Information Option (RIO).  ND information that is  disseminated by RPL conserves all its original semantics for router to host, with limited extensions for router to router, though it is not to be confused with routing advertisements and it is never to be  directly redistributed in another routing protocol.  A RPL node often combines host and router behaviors.  As a host, it will process the options as specified in [https://tools.ietf.org/html/rfc4191 RFC4191], [https://tools.ietf.org/html/rfc4861 RFC4861], [https://tools.ietf.org/html/rfc4862 RFC4862], and  [https://tools.ietf.org/html/rfc6275 RFC6275].  As a router, the RPL node may advertise the information from the options as required for the specific link.&lt;br /&gt;
&lt;br /&gt;
For further information, please refer to [https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== UDP Server ==&lt;br /&gt;
[[File:udp_server.jpg|200px|right|thumb|Flow chart for UDP server]]&lt;br /&gt;
In the example, UDP server does three tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Initializes RPL DAG;&lt;br /&gt;
&lt;br /&gt;
2. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
3. Waits for packets from client, receives and print them on stdout.&lt;br /&gt;
&lt;br /&gt;
=== Initialize RPL DAG===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
// check whether the ADDR_MANUAL was set succefuly or not&lt;br /&gt;
uip_ds6_addr_add(&amp;amp;ipaddr, 0, ADDR_MANUAL); &lt;br /&gt;
root_if = uip_ds6_addr_lookup(&amp;amp;ipaddr);&lt;br /&gt;
if(root_if != NULL) {&lt;br /&gt;
  rpl_dag_t *dag;&lt;br /&gt;
  //set the ip adress of server as the root of initial DAG &lt;br /&gt;
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&amp;amp;ipaddr);&lt;br /&gt;
  uip_ip6addr(&amp;amp;ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);&lt;br /&gt;
  rpl_set_prefix(dag, &amp;amp;ipaddr, 64);&lt;br /&gt;
  PRINTF(&amp;quot;created a new RPL dag\n&amp;quot;);&lt;br /&gt;
} else {&lt;br /&gt;
  PRINTF(&amp;quot;failed to create a new RPL DAG\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===create UDP connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//create new UDP connection to client&amp;#039;s port&lt;br /&gt;
server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);&lt;br /&gt;
if(server_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
//bing the connection to server&amp;#039;s local port&lt;br /&gt;
udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a server connection with remote address &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;server_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;, UIP_HTONS(server_conn-&amp;gt;lport),&lt;br /&gt;
       UIP_HTONS(server_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===receives and processes incoming packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  //if there is packet available&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  } else if (ev == sensors_event &amp;amp;&amp;amp; data == &amp;amp;button_sensor) {&lt;br /&gt;
    PRINTF(&amp;quot;Initiaing global repair\n&amp;quot;);&lt;br /&gt;
    rpl_repair_root(RPL_DEFAULT_INSTANCE);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//call this function if packet available&lt;br /&gt;
static void&lt;br /&gt;
tcpip_handler(void)&lt;br /&gt;
{&lt;br /&gt;
  char *appdata;&lt;br /&gt;
&lt;br /&gt;
  if(uip_newdata()) {&lt;br /&gt;
    appdata = (char *)uip_appdata;&lt;br /&gt;
    appdata[uip_datalen()] = 0;&lt;br /&gt;
    //print the data of packet&lt;br /&gt;
    PRINTF(&amp;quot;DATA recv &amp;#039;%s&amp;#039; from &amp;quot;, appdata);&lt;br /&gt;
    PRINTF(&amp;quot;%d&amp;quot;,&lt;br /&gt;
           UIP_IP_BUF-&amp;gt;srcipaddr.u8[sizeof(UIP_IP_BUF-&amp;gt;srcipaddr.u8) - 1]);&lt;br /&gt;
    PRINTF(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UDP Client ==&lt;br /&gt;
&lt;br /&gt;
[[File:udp_client.png|200px|right|thumb|Flow chart for UDP client]]&lt;br /&gt;
In the example, UDP server does two tasks primarily. &lt;br /&gt;
&lt;br /&gt;
1. Sets up UPD connection;&lt;br /&gt;
&lt;br /&gt;
2. Sends packet to UDP server periodically.&lt;br /&gt;
&lt;br /&gt;
=== Sets up UPD connection ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* new connection with remote host */&lt;br /&gt;
client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); &lt;br /&gt;
if(client_conn == NULL) {&lt;br /&gt;
  PRINTF(&amp;quot;No UDP connection available, exiting the process!\n&amp;quot;);&lt;br /&gt;
  PROCESS_EXIT();&lt;br /&gt;
}&lt;br /&gt;
udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); &lt;br /&gt;
&lt;br /&gt;
PRINTF(&amp;quot;Created a connection with the server &amp;quot;);&lt;br /&gt;
PRINT6ADDR(&amp;amp;client_conn-&amp;gt;ripaddr);&lt;br /&gt;
PRINTF(&amp;quot; local/remote port %u/%u\n&amp;quot;,&lt;br /&gt;
UIP_HTONS(client_conn-&amp;gt;lport), UIP_HTONS(client_conn-&amp;gt;rport));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sends packet ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//set time interval by SEND_INTERVAL&lt;br /&gt;
etimer_set(&amp;amp;periodic, SEND_INTERVAL);&lt;br /&gt;
while(1) {&lt;br /&gt;
  PROCESS_YIELD();&lt;br /&gt;
  if(ev == tcpip_event) {&lt;br /&gt;
    tcpip_handler();&lt;br /&gt;
  }&lt;br /&gt;
  //send packet every SEND_INTERVAL&lt;br /&gt;
  if(etimer_expired(&amp;amp;periodic)) {&lt;br /&gt;
    etimer_reset(&amp;amp;periodic);&lt;br /&gt;
    ctimer_set(&amp;amp;backoff_timer, SEND_TIME, send_packet, NULL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void&lt;br /&gt;
send_packet(void *ptr)&lt;br /&gt;
{&lt;br /&gt;
  static int seq_id;&lt;br /&gt;
  char buf[MAX_PAYLOAD_LEN];&lt;br /&gt;
&lt;br /&gt;
  seq_id++;&lt;br /&gt;
  PRINTF(&amp;quot;DATA send to %d &amp;#039;Hello %d&amp;#039;\n&amp;quot;,&lt;br /&gt;
         server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id);&lt;br /&gt;
  sprintf(buf, &amp;quot;Hello %d from the client&amp;quot;, seq_id);&lt;br /&gt;
  //send packet through client_conn to UDP server&lt;br /&gt;
  uip_udp_packet_sendto(client_conn, buf, strlen(buf),&lt;br /&gt;
                        &amp;amp;server_ipaddr, UIP_HTONS(UDP_SERVER_PORT));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Cooja Simulation ==&lt;br /&gt;
&lt;br /&gt;
The DGRM model is used.&lt;br /&gt;
&lt;br /&gt;
The following are the steps to form a new simulation:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; Please refer to the [[Cooja Simulator]] tutorial page for an introduction and detailed description on how to use the simulator.&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Start Cooja&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
To start the simulator, Go to Contiki folder and navigate to /tools/cooja directory and run &amp;quot;ant&amp;quot; to start the simulator&lt;br /&gt;
&lt;br /&gt;
  sudo ant run&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Open an existing simulation file&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In the GUI, select File-&amp;gt;Open simulation-&amp;gt;Browse..&lt;br /&gt;
&lt;br /&gt;
After the dialogue shows up, Open home/contiki-2.7/examples/ipv6/rpl-udp/rpl-udp.csc&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;: If compile error shows up, please run&lt;br /&gt;
 $ cd contiki-2.7/examples/ipv6/rpl-udp&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
[[File:opensim.png|center|border|500px|Open an existing simulation]]&lt;br /&gt;
&lt;br /&gt;
You are suppose to see the simulation showing up like this.&lt;br /&gt;
&lt;br /&gt;
[[File:siminterface.png|center|border|500px|Simulation interface]]&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Run Simulation&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Run the simulation by using the &amp;#039;&amp;#039;Start&amp;#039;&amp;#039; option in the &amp;#039;&amp;#039;Simulation Control&amp;#039;&amp;#039; window. This will initiate the motes and allocate all with a new Rime address and other initialization processes. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;Watch Output&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The motes output and debug messages can be seen in the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; window. You can filter the output based on the node &amp;#039;&amp;#039;ID:node_id&amp;#039;&amp;#039; to watch a particular node. You can also watch particular debug messages by filtering them. The other useful functions of the &amp;#039;&amp;#039;Motes Output&amp;#039;&amp;#039; are &amp;#039;&amp;#039;File, Edit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;View&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;File&amp;#039;&amp;#039; option helps in saving the output to a file. The &amp;#039;&amp;#039;Edit&amp;#039;&amp;#039; has the option of copying the output - either full or a particular selected messages. You can also clear the messages using the &amp;#039;&amp;#039;Clear all messages&amp;#039;&amp;#039; option.&amp;lt;br&amp;gt;&lt;br /&gt;
You can use these messages saved in file to make observations and plot graphs according to the objective of your experiment.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:simioutput.png|center|border|500px|Simulation output]]&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[https://tools.ietf.org/html/rfc6550 &amp;#039;&amp;#039;&amp;#039;RFC 6550&amp;#039;&amp;#039;&amp;#039;], &amp;quot;RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Contiki_tutorials | Back to Contiki Tutorials]]&lt;/div&gt;</summary>
		<author><name>Paisamar</name></author>	</entry>

	</feed>