http://anrg.usc.edu/contiki/api.php?action=feedcontributions&user=Hegdea&feedformat=atomContiki - User contributions [en]2024-03-28T14:40:16ZUser contributionsMediaWiki 1.26.2http://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1649Contiki Shell2014-11-27T03:36:41Z<p>Hegdea: /* Issues you might face */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
<p>'''Other Commands'''</p><br />
<p>1)'''ps''': 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.</p><br />
<p>2)'''kill <command>''': stop a specific command. </p><br />
<p>3)'''killall''': stop all running commands.</p><br />
<p>4)'''reboot''': this command reboots the mote. </p><br />
<p>5)'''collect-view-data''': provides sensor data, power consumption, network stats for the sky mote. </p><br />
<p>6)'''powertrace''': this gives the power profile of the mote. ''' </p><br />
<p>'''Examples'''</p><br />
<br />
----------------------------<br />
<p>This command lists all the running processes </p><br />
<p>ps</p><br />
<pre>5.0: Contiki> <br />
ps<br />
SEND 3 bytes<br />
Processes:<br />
ps<br />
Shell server<br />
Shell<br />
Contiki serial shell<br />
Serial driver<br />
CC2420 driver<br />
Sensors<br />
Ctimer process<br />
Event timer<br />
5.0: Contiki></pre><br />
---------------------------<br />
<p> This command reboots the shell </p><br />
<p>time|binprint</p><br />
<p>reboot</p><br />
<p> After rebooting print time, to see the restart of the mote time </p><br />
<p>time|binprint</p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 34454 38458 0 65535 0 269 <br />
5.0: Contiki> <br />
reboot<br />
SEND 7 bytes<br />
Rebooting the node in four seconds...<br />
Rime started with address 5.0<br />
MAC 05:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 5.<br />
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26<br />
Starting 'Sky Contiki shell'<br />
5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 2736 45115 0 65535 0 21 <br />
5.0: Contiki> </pre><br />
---------------------------<br />
<p> This command prints out the collect view data for the mote </p><br />
<p> 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]</p><br />
<p>collect-view-data | binprint</p><br />
<pre>5.0: Contiki> <br />
collect-view-data | binprint<br />
SEND 20 bytes<br />
SEND 9 bytes<br />
22 26024 0 1672 50278 0 269 0 128 0 6 0 2075 1 6 3 65535 65535 0 0 0 0 <br />
5.0: Contiki> </pre><br />
--------------------------<br />
<p>This commands prints the power profile of the mote. </p><br />
<p>powertrace</p><br />
<pre>5.0: Contiki> <br />
powertrace<br />
SEND 11 bytes<br />
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%)<br />
5.0: Contiki></pre><br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<p>Now create a new project mySky-shell under ~/contiki-2.7/examples </p><br />
<p>Add this source file mySky-shell.c in the project </p><br />
<source lang ="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific My Contiki shell <br />
* Base code reference: sky-shell.c<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
//#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(mysky_shell_process, "My Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&mysky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(mysky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
shell_try_init();<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<p>Add this Makefile in the project</p><br />
<br />
<source lang ="c"><br />
CONTIKI_PROJECT = mySky-shell<br />
all: $(CONTIKI_PROJECT)<br />
<br />
APPS = serial-shell powertrace collect-view<br />
CONTIKI = ../..<br />
<br />
include $(CONTIKI)/Makefile.include<br />
-include /home/user/nes/testbed-scripts/Makefile.include<br />
<br />
</source><br />
<br />
<p>Add another Makefile.target to the project </p><br />
<source lang ="c"><br />
TARGET = sky<br />
</source><br />
<br />
<p>compile the project</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget</pre><br />
<p>After successful compilation, you will see the following messages on the command prompt</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget<br />
msp430-objcopy mySky-shell.sky -O ihex mySky-shell.ihex<br />
make IHEXFILE=mySky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
46214 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
saving Makefile.target<br />
rm mySky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/mySky-shell$</pre><br />
<p>Login in to the mote using the following command</p><br />
<pre>make login</pre><br />
<p>After logging into the mote, you will see the shell prompt as seen below</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
��{/#��3�#���#<br />
</pre><br />
<p>Hit Enter, too see shell prompt and Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
blinkAllOnce: blink all LEDs one time<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
echo2: echoes back entered text twice<br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
</pre><br />
<p>Lets execute the two new shell commands added to the shell</p><br />
<pre>5.0: Contiki> <br />
echo2 Trojan<br />
SEND 13 bytes<br />
TrojanTrojan<br />
5.0: Contiki></pre><br />
<br />
<p>blinkAllOnce command will blink all LED's exactly once one by one</p><br />
<pre>5.0: Contiki> <br />
blinkAllOnce<br />
SEND 13 bytes<br />
5.0: Contiki> </pre><br />
<br />
<p>Voila! There it is blinking of LEDs, Notice it ?</p><br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as part of your Contiki Shell.</p><br />
<p>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.</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1648Contiki Shell2014-11-27T03:34:19Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
<p>'''Other Commands'''</p><br />
<p>1)'''ps''': 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.</p><br />
<p>2)'''kill <command>''': stop a specific command. </p><br />
<p>3)'''killall''': stop all running commands.</p><br />
<p>4)'''reboot''': this command reboots the mote. </p><br />
<p>5)'''collect-view-data''': provides sensor data, power consumption, network stats for the sky mote. </p><br />
<p>6)'''powertrace''': this gives the power profile of the mote. ''' </p><br />
<p>'''Examples'''</p><br />
<br />
----------------------------<br />
<p>This command lists all the running processes </p><br />
<p>ps</p><br />
<pre>5.0: Contiki> <br />
ps<br />
SEND 3 bytes<br />
Processes:<br />
ps<br />
Shell server<br />
Shell<br />
Contiki serial shell<br />
Serial driver<br />
CC2420 driver<br />
Sensors<br />
Ctimer process<br />
Event timer<br />
5.0: Contiki></pre><br />
---------------------------<br />
<p> This command reboots the shell </p><br />
<p>time|binprint</p><br />
<p>reboot</p><br />
<p> After rebooting print time, to see the restart of the mote time </p><br />
<p>time|binprint</p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 34454 38458 0 65535 0 269 <br />
5.0: Contiki> <br />
reboot<br />
SEND 7 bytes<br />
Rebooting the node in four seconds...<br />
Rime started with address 5.0<br />
MAC 05:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 5.<br />
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26<br />
Starting 'Sky Contiki shell'<br />
5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 2736 45115 0 65535 0 21 <br />
5.0: Contiki> </pre><br />
---------------------------<br />
<p> This command prints out the collect view data for the mote </p><br />
<p> 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]</p><br />
<p>collect-view-data | binprint</p><br />
<pre>5.0: Contiki> <br />
collect-view-data | binprint<br />
SEND 20 bytes<br />
SEND 9 bytes<br />
22 26024 0 1672 50278 0 269 0 128 0 6 0 2075 1 6 3 65535 65535 0 0 0 0 <br />
5.0: Contiki> </pre><br />
--------------------------<br />
<p>This commands prints the power profile of the mote. </p><br />
<p>powertrace</p><br />
<pre>5.0: Contiki> <br />
powertrace<br />
SEND 11 bytes<br />
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%)<br />
5.0: Contiki></pre><br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<p>Now create a new project mySky-shell under ~/contiki-2.7/examples </p><br />
<p>Add this source file mySky-shell.c in the project </p><br />
<source lang ="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific My Contiki shell <br />
* Base code reference: sky-shell.c<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
//#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(mysky_shell_process, "My Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&mysky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(mysky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
shell_try_init();<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<p>Add this Makefile in the project</p><br />
<br />
<source lang ="c"><br />
CONTIKI_PROJECT = mySky-shell<br />
all: $(CONTIKI_PROJECT)<br />
<br />
APPS = serial-shell powertrace collect-view<br />
CONTIKI = ../..<br />
<br />
include $(CONTIKI)/Makefile.include<br />
-include /home/user/nes/testbed-scripts/Makefile.include<br />
<br />
</source><br />
<br />
<p>Add another Makefile.target to the project </p><br />
<source lang ="c"><br />
TARGET = sky<br />
</source><br />
<br />
<p>compile the project</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget</pre><br />
<p>After successful compilation, you will see the following messages on the command prompt</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget<br />
msp430-objcopy mySky-shell.sky -O ihex mySky-shell.ihex<br />
make IHEXFILE=mySky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
46214 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
saving Makefile.target<br />
rm mySky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/mySky-shell$</pre><br />
<p>Login in to the mote using the following command</p><br />
<pre>make login</pre><br />
<p>After logging into the mote, you will see the shell prompt as seen below</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
��{/#��3�#���#<br />
</pre><br />
<p>Hit Enter, too see shell prompt and Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
blinkAllOnce: blink all LEDs one time<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
echo2: echoes back entered text twice<br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
</pre><br />
<p>Lets execute the two new shell commands added to the shell</p><br />
<pre>5.0: Contiki> <br />
echo2 Trojan<br />
SEND 13 bytes<br />
TrojanTrojan<br />
5.0: Contiki></pre><br />
<br />
<p>blinkAllOnce command will blink all LED's exactly once one by one</p><br />
<pre>5.0: Contiki> <br />
blinkAllOnce<br />
SEND 13 bytes<br />
5.0: Contiki> </pre><br />
<br />
<p>Voila! There it is blinking of LEDs, Notice it ?</p><br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1562Contiki Shell2014-11-12T22:12:43Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
<p>'''Other Commands'''</p><br />
<p>1)'''ps''': 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.</p><br />
<p>2)'''kill <command>''': stop a specific command. </p><br />
<p>3)'''killall''': stop all running commands.</p><br />
<p>4)'''reboot''': this command reboots the mote. </p><br />
<p>5)'''collect-view-data''': provides sensor data, power consumption, network stats for the sky mote. </p><br />
<p>6)'''powertrace''': this gives the power profile of the mote. ''' </p><br />
<p>'''Examples'''</p><br />
<br />
----------------------------<br />
<p>This command lists all the running processes </p><br />
<p>ps</p><br />
<pre>5.0: Contiki> <br />
ps<br />
SEND 3 bytes<br />
Processes:<br />
ps<br />
Shell server<br />
Shell<br />
Contiki serial shell<br />
Serial driver<br />
CC2420 driver<br />
Sensors<br />
Ctimer process<br />
Event timer<br />
5.0: Contiki></pre><br />
---------------------------<br />
<p> This command reboots the shell </p><br />
<p>time|binprint</p><br />
<p>reboot</p><br />
<p> After rebooting print time, to see the restart of the mote time </p><br />
<p>time|binprint</p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 34454 38458 0 65535 0 269 <br />
5.0: Contiki> <br />
reboot<br />
SEND 7 bytes<br />
Rebooting the node in four seconds...<br />
Rime started with address 5.0<br />
MAC 05:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 5.<br />
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26<br />
Starting 'Sky Contiki shell'<br />
5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 2736 45115 0 65535 0 21 <br />
5.0: Contiki> </pre><br />
---------------------------<br />
<p> This command prints out the collect view data for the mote </p><br />
<p> 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]</p><br />
<p>collect-view-data | binprint</p><br />
<pre>5.0: Contiki> <br />
collect-view-data | binprint<br />
SEND 20 bytes<br />
SEND 9 bytes<br />
22 26024 0 1672 50278 0 269 0 128 0 6 0 2075 1 6 3 65535 65535 0 0 0 0 <br />
5.0: Contiki> </pre><br />
--------------------------<br />
<p>This commands prints the power profile of the mote. </p><br />
<p>powertrace</p><br />
<pre>5.0: Contiki> <br />
powertrace<br />
SEND 11 bytes<br />
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%)<br />
5.0: Contiki></pre><br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<p>Now create a new project mySky-shell under ~/contiki-2.7/examples </p><br />
<p>Add this source file mySky-shell.c in the project </p><br />
<source lang ="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific My Contiki shell <br />
* Base code reference: sky-shell.c<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
//#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(mysky_shell_process, "My Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&mysky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(mysky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
shell_try_init();<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<p>Add this Makefile in the project</p><br />
<br />
<source lang ="c"><br />
CONTIKI_PROJECT = mySky-shell<br />
all: $(CONTIKI_PROJECT)<br />
<br />
APPS = serial-shell powertrace collect-view<br />
CONTIKI = ../..<br />
<br />
include $(CONTIKI)/Makefile.include<br />
-include /home/user/nes/testbed-scripts/Makefile.include<br />
<br />
</source><br />
<br />
<p>Add another Makefile.target to the project </p><br />
<source lang ="c"><br />
TARGET = sky<br />
</source><br />
<br />
<p>compile the project</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget</pre><br />
<p>After successful compilation, you will see the following messages on the command prompt</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget<br />
msp430-objcopy mySky-shell.sky -O ihex mySky-shell.ihex<br />
make IHEXFILE=mySky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
46214 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
saving Makefile.target<br />
rm mySky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/mySky-shell$</pre><br />
<p>Login in to the mote using the following command</p><br />
<pre>make login</pre><br />
<p>After logging into the mote, you will see the shell prompt as seen below</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
��{/#��3�#���#<br />
</pre><br />
<p>Hit Enter, too see shell prompt and Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
blinkAllOnce: blink all LEDs one time<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
echo2: echoes back entered text twice<br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
</pre><br />
<p>Lets execute the two new shell commands added to the shell</p><br />
<pre>5.0: Contiki> <br />
echo2 Trojan<br />
SEND 13 bytes<br />
TrojanTrojan<br />
5.0: Contiki></pre><br />
<br />
<p>blinkAllOnce command will blink all LED's exactly once one by one</p><br />
<pre>5.0: Contiki> <br />
blinkAllOnce<br />
SEND 13 bytes<br />
5.0: Contiki> </pre><br />
<br />
<p>Voila! There it is blinking of LEDs, Notice it ?</p><br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1561Contiki Shell2014-11-12T22:09:48Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
<p>'''Other Commands'''</p><br />
<p>1)'''ps''': 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.</p><br />
<p>2)'''kill <command>''': stop a specific command. </p><br />
<p>3)'''killall''': stop all running commands.</p><br />
<p>4)'''reboot''': this command reboots the mote. </p><br />
<p>5)'''collect-view-data''': provides sensor data, power consumption, network stats for the sky mote. </p><br />
<p>'''Examples'''</p><br />
<br />
----------------------------<br />
<p>This command lists all the running processes </p><br />
<p>ps</p><br />
<pre>5.0: Contiki> <br />
ps<br />
SEND 3 bytes<br />
Processes:<br />
ps<br />
Shell server<br />
Shell<br />
Contiki serial shell<br />
Serial driver<br />
CC2420 driver<br />
Sensors<br />
Ctimer process<br />
Event timer<br />
5.0: Contiki></pre><br />
---------------------------<br />
<p> This command reboots the shell </p><br />
<p>time|binprint</p><br />
<p>reboot</p><br />
<p> After rebooting print time, to see the restart of the mote time </p><br />
<p>time|binprint</p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 34454 38458 0 65535 0 269 <br />
5.0: Contiki> <br />
reboot<br />
SEND 7 bytes<br />
Rebooting the node in four seconds...<br />
Rime started with address 5.0<br />
MAC 05:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 5.<br />
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26<br />
Starting 'Sky Contiki shell'<br />
5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 2736 45115 0 65535 0 21 <br />
5.0: Contiki> <br />
</pre><br />
---------------------------<br />
<p> This command prints out the collect view data for the mote </p><br />
<p> 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]</p><br />
</p>collect-view-data | binprint</p><br />
<pre>5.0: Contiki> <br />
collect-view-data | binprint<br />
SEND 20 bytes<br />
SEND 9 bytes<br />
22 26024 0 1672 50278 0 269 0 128 0 6 0 2075 1 6 3 65535 65535 0 0 0 0 <br />
5.0: Contiki> </pre><br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<p>Now create a new project mySky-shell under ~/contiki-2.7/examples </p><br />
<p>Add this source file mySky-shell.c in the project </p><br />
<source lang ="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific My Contiki shell <br />
* Base code reference: sky-shell.c<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
//#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(mysky_shell_process, "My Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&mysky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(mysky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
shell_try_init();<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<p>Add this Makefile in the project</p><br />
<br />
<source lang ="c"><br />
CONTIKI_PROJECT = mySky-shell<br />
all: $(CONTIKI_PROJECT)<br />
<br />
APPS = serial-shell powertrace collect-view<br />
CONTIKI = ../..<br />
<br />
include $(CONTIKI)/Makefile.include<br />
-include /home/user/nes/testbed-scripts/Makefile.include<br />
<br />
</source><br />
<br />
<p>Add another Makefile.target to the project </p><br />
<source lang ="c"><br />
TARGET = sky<br />
</source><br />
<br />
<p>compile the project</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget</pre><br />
<p>After successful compilation, you will see the following messages on the command prompt</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget<br />
msp430-objcopy mySky-shell.sky -O ihex mySky-shell.ihex<br />
make IHEXFILE=mySky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
46214 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
saving Makefile.target<br />
rm mySky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/mySky-shell$</pre><br />
<p>Login in to the mote using the following command</p><br />
<pre>make login</pre><br />
<p>After logging into the mote, you will see the shell prompt as seen below</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
��{/#��3�#���#<br />
</pre><br />
<p>Hit Enter, too see shell prompt and Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
blinkAllOnce: blink all LEDs one time<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
echo2: echoes back entered text twice<br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
</pre><br />
<p>Lets execute the two new shell commands added to the shell</p><br />
<pre>5.0: Contiki> <br />
echo2 Trojan<br />
SEND 13 bytes<br />
TrojanTrojan<br />
5.0: Contiki></pre><br />
<br />
<p>blinkAllOnce command will blink all LED's exactly once one by one</p><br />
<pre>5.0: Contiki> <br />
blinkAllOnce<br />
SEND 13 bytes<br />
5.0: Contiki> </pre><br />
<br />
<p>Voila! There it is blinking of LEDs, Notice it ?</p><br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1560Contiki Shell2014-11-12T21:50:21Z<p>Hegdea: /* An example project for creating your own Shell with your commands */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<p>Now create a new project mySky-shell under ~/contiki-2.7/examples </p><br />
<p>Add this source file mySky-shell.c in the project </p><br />
<source lang ="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific My Contiki shell <br />
* Base code reference: sky-shell.c<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
//#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(mysky_shell_process, "My Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&mysky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(mysky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
shell_try_init();<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<p>Add this Makefile in the project</p><br />
<br />
<source lang ="c"><br />
CONTIKI_PROJECT = mySky-shell<br />
all: $(CONTIKI_PROJECT)<br />
<br />
APPS = serial-shell powertrace collect-view<br />
CONTIKI = ../..<br />
<br />
include $(CONTIKI)/Makefile.include<br />
-include /home/user/nes/testbed-scripts/Makefile.include<br />
<br />
</source><br />
<br />
<p>Add another Makefile.target to the project </p><br />
<source lang ="c"><br />
TARGET = sky<br />
</source><br />
<br />
<p>compile the project</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget</pre><br />
<p>After successful compilation, you will see the following messages on the command prompt</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget<br />
msp430-objcopy mySky-shell.sky -O ihex mySky-shell.ihex<br />
make IHEXFILE=mySky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
46214 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/mySky-shell'<br />
saving Makefile.target<br />
rm mySky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/mySky-shell$</pre><br />
<p>Login in to the mote using the following command</p><br />
<pre>make login</pre><br />
<p>After logging into the mote, you will see the shell prompt as seen below</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
��{/#��3�#���#<br />
</pre><br />
<p>Hit Enter, too see shell prompt and Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
blinkAllOnce: blink all LEDs one time<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
echo2: echoes back entered text twice<br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
</pre><br />
<p>Lets execute the two new shell commands added to the shell</p><br />
<pre>5.0: Contiki> <br />
echo2 Trojan<br />
SEND 13 bytes<br />
TrojanTrojan<br />
5.0: Contiki></pre><br />
<br />
<p>blinkAllOnce command will blink all LED's exactly once one by one</p><br />
<pre>5.0: Contiki> <br />
blinkAllOnce<br />
SEND 13 bytes<br />
5.0: Contiki> </pre><br />
<br />
<p>Voila! There it is blinking of LEDs, Notice it ?</p><br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1488Contiki Shell2014-11-09T07:58:02Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<p>Now create a new project mySky-shell under ~/contiki-2.7/examples </p><br />
<p>Add this source file mySky-shell.c in the project </p><br />
<source lang ="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific My Contiki shell <br />
* Base code reference: sky-shell.c<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
//#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(mysky_shell_process, "My Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&mysky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(mysky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
shell_try_init();<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<p>Add this Makefile in the project</p><br />
<br />
<source lang ="c"><br />
CONTIKI_PROJECT = mySky-shell<br />
all: $(CONTIKI_PROJECT)<br />
<br />
APPS = serial-shell powertrace collect-view<br />
CONTIKI = ../..<br />
<br />
include $(CONTIKI)/Makefile.include<br />
-include /home/user/nes/testbed-scripts/Makefile.include<br />
<br />
</source><br />
<br />
<p>Add another Makefile.target to the project </p><br />
<source lang ="c"><br />
TARGET = sky<br />
</source><br />
<br />
<p>compile the project</p><br />
<pre>user@instant-contiki:~/contiki-2.7/examples/mySky-shell$ make TARGET=sky mySky-shell.upload savetarget</pre><br />
<pre>make login</pre><br />
<p>Type help on the shell prompt. You will see the two new commands, echo2 and blinkAllonce</p><br />
<p>Execute them</p><br />
<p> </p><br />
<br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1483Contiki Shell2014-11-09T07:49:44Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<p>''' Two new shell commands are created'''</p><br />
<p>'''echo2''': This shell command echoes the text twice back onto the shell prompt </p><br />
<p> '''blinkAllOnce''': This shell command is used to make each of the LED's (Red,Blu,Green) blink once each. </p><br />
<p>Once the shell commands are created they are registered with the Contiki Shell using shell_try_init() </p><br />
<br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p>Make the changes in Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' to include shell-try-example.c in shell_src </p><br />
<pre>shell_src = shell.c shell-reboot.c \<br />
shell-vars.c shell-ps.c shell-rime.c shell-sendtest.c \<br />
shell-blink.c shell-text.c shell-try-example.c shell-time.c \<br />
shell-file.c shell-netfile.c shell-run.c \<br />
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \<br />
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \<br />
shell-wget.c shell-httpd.c shell-irc.c \<br />
shell-checkpoint.c shell-power.c \<br />
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \<br />
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \<br />
shell-rime-unicast.c \<br />
shell-base64.c \<br />
shell-netperf.c shell-memdebug.c \<br />
shell-powertrace.c shell-collect-view.c shell-crc.c</pre><br />
<br />
<br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1481Contiki Shell2014-11-09T07:41:47Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<p>Place the following two files in this path ''' ~/contiki-2.7/apps/shell '''<\p><br />
<p>1)shell-try-example.c</p><br />
<p>2)shell-try-example.h</p><br />
<br />
<p>Source code: shell-try-example.c</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.c<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include <ctype.h><br />
#include <stdio.h><br />
#include <string.h><br />
#include "dev/leds.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_echo2_process, "echo2");<br />
SHELL_COMMAND(echo2_command,<br />
"echo2",<br />
"echo2: echoes back entered text twice",<br />
&shell_echo2_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(shell_echo2_process, ev, data)<br />
{<br />
<br />
PROCESS_BEGIN();<br />
<br />
/* Echo the data back twice */<br />
shell_output(&echo2_command, data, (int)strlen(data), data, (int)strlen(data));<br />
<br />
PROCESS_END();<br />
}<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(shell_blinkAllOnce_process, "blinkAllOnce");<br />
SHELL_COMMAND(blinkAllOnce_command,<br />
"blinkAllOnce",<br />
"blinkAllOnce: blink all LEDs one time",<br />
&shell_blinkAllOnce_process);<br />
/*---------------------------------------------------------------------------*/<br />
<br />
PROCESS_THREAD(shell_blinkAllOnce_process, ev, data)<br />
{ <br />
static struct etimer etimer;<br />
<br />
PROCESS_EXITHANDLER(leds_off(LEDS_ALL);)<br />
<br />
PROCESS_BEGIN();<br />
<br />
etimer_set(&etimer, CLOCK_SECOND/2);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_RED);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_GREEN);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_on(LEDS_BLUE);<br />
<br />
etimer_reset(&etimer);<br />
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));<br />
leds_off(LEDS_BLUE);<br />
<br />
PROCESS_END();<br />
}<br />
<br />
<br />
/*---------------------------------------------------------------------------*/<br />
void<br />
shell_try_init(void)<br />
{<br />
shell_register_command(&echo2_command);<br />
shell_register_command(&blinkAllOnce_command);<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>Header: shell-try-example.h</p><br />
<source lang ="c"><br />
/**<br />
* \file shell-try-example.h<br />
* try Example Contiki shell command<br />
* \author<br />
* Abhilash Hegde <hegdea@usc.edu><br />
*/<br />
<br />
#ifndef __SHELL_TRY_H__<br />
#define __SHELL_TRY_H__<br />
<br />
#include "shell.h"<br />
<br />
void shell_try_init(void);<br />
<br />
#endif /* __SHELL_TRY_H__ */<br />
</source><br />
<br />
<p> </p><br />
<br />
<br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'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()'s that can be registered as pert of your Contiki Shell.</p><br />
<p>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</p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1477Contiki Shell2014-11-09T07:32:47Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. serial_shell_init() invokes the serial contiki shell</p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
<br />
== Issues you might face ==<br />
<br />
<p> You may run out of memory on the mote, when more than possible shell_xx_init()'s are used in your firmware image of Contiki shell. This will result in compilation failure such as seen below. By Trial and error figure what would be a reasonable set of shell_xx_init()'s that can be registered as pert of your Contiki Shell</p><br />
<p> </p><br />
<p> </p><br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1463Contiki Shell2014-11-09T07:26:29Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p></p><br />
'''senseconv''': convert 'sense' data to human readable format.<p></p><br />
'''nodeid''': 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.<p></p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p></p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p></p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' </p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. </p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' </p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
<br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1459Contiki Shell2014-11-09T07:24:50Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
<p>Step1: Write a shell-your-cmdfile.c and shell-your-cmdfile.h files and place them in ''' ~/contiki-2.7/apps/shell ''' <\p><br />
<p>Step2: Add the shell-your-cmdfile.c for compilation in the shell_src var of Makefile.shell located in ''' ~/contiki-2.7/apps/shell ''' <\p><br />
<p>Shell.c has all the basic code blocks to build your own shell command. <\p><br />
<br />
<p>'''Example skeleton of code in shell-your-cmdfile.c to create your own shell command''' <\p><br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
<br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1452Contiki Shell2014-11-09T07:17:11Z<p>Hegdea: /* Feedback */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
Write a shell-your-cmd.c and shell-your-cmd.h files and place them in <br />
<br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials.</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning. </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1451Contiki Shell2014-11-09T07:16:29Z<p>Hegdea: /* References */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
Write a shell-your-cmd.c and shell-your-cmd.h files and place them in <br />
<br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1450Contiki Shell2014-11-09T07:15:34Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
Write a shell-your-cmd.c and shell-your-cmd.h files and place them in <br />
<br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
== References ==<br />
<p>http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<\p><br />
<p>http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<\p><br />
<p>http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<\p><br />
<p>http://contiki.sourceforge.net/docs/2.6/a01796.html<\p><br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1448Contiki Shell2014-11-09T07:14:30Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
Write a shell-your-cmd.c and shell-your-cmd.h files and place them in <br />
<br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
== References ==<br />
http://www.bithappens.se/blog/2012/07/01/contiki-debugging-in-cooja/<br />
http://ai.vub.ac.be/Robotics/wiki/index.php/Some_cool_demos<br />
http://www.nairaland.com/1167922/step-by-step-method-writing-contiki-programs<br />
http://contiki.sourceforge.net/docs/2.6/a01796.html<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1444Contiki Shell2014-11-09T07:10:54Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------<br />
<br />
== How to write your own Shell commands ==<br />
<br />
Write a shell-your-cmd.c and shell-your-cmd.h files and place them in <br />
<br />
<source lang="c"><br />
PROCESS(multiplyNums_process, "Multiply two numbers");<br />
SHELL_COMMAND(mulNum_command, "mn", "mn: Multiply two numbers", &multiplyNums_process);<br />
/* --------------------------------- */<br />
PROCESS_THREAD(multiplyNums_process, ev, data) {<br />
PROCESS_BEGIN();<br />
// ...<br />
// ...<br />
PROCESS_END();<br />
}<br />
.....<br />
.....<br />
shell_register_command(&mulNum_command);<br />
</source><br />
<br />
== An example project for creating your own Shell with your commands ==<br />
<br />
<br />
== References ==<br />
<br />
<br />
== Feedback ==<br />
<p>Please post your feedback here for any further improvements to tutorials</p><br />
<p>Comments Welcome :)</p><br />
<p>Hope you had a great time learning </p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1441Contiki Shell2014-11-09T07:06:02Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5</p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------<br />
<p>'''6) Power Related Commands:'''</p><br />
<br />
<p>'''power''': print power profile</p><br />
<p>'''energy''': print energy profile</p><br />
<p>'''powerconv''': convert power profile to human readable output</p><br />
<p>'''shell-power.c''' : This file holds all the power related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_power_init()''': This function is used to register power related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>Following power commands prints the power profile of sensor node in human readable format </p><br />
<p>power | powerconv</p><br />
<pre>5.0: Contiki> <br />
power | powerconv<br />
SEND 18 bytes<br />
CPU 3% LPM 8% tx 0% rx 0% idle tx 0% idle rx 0% tot 719 uW<br />
5.0: Contiki> </p><br />
----------------------------<br />
<p> Experiment </p><br />
<p>echo change power to 0 | append powfile.log </p><br />
<p>txpower 0 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 3 | append powfile.log </p><br />
<p>txpower 3 | binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 10 | append powfile.log </p><br />
<p>txpower 10| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>echo change power to 31 | append powfile.log </p><br />
<p>txpower 31| binprint | power | powerconv | append powfile.log </p><br />
<p>repeat 2 1 {power | powerconv} | append powfile.log </p><br />
<p>read powfile.log 0 40 </p><br />
<pre>5.0: Contiki> <br />
echo change power to 0 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
change power to 0<br />
5.0: Contiki> <br />
txpower 0 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2043 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2073 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2046 uW<br />
5.0: Contiki> <br />
txpower 3 | binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2150 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 10 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 10<br />
5.0: Contiki> <br />
txpower 10| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2148 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2099 uW<br />
5.0: Contiki> <br />
echo change power to 31 | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 5 bytes<br />
change power to 31<br />
5.0: Contiki> <br />
txpower 31| binprint | power | powerconv | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2071 uW<br />
5.0: Contiki> <br />
repeat 2 1 {power | powerconv} | append powfile.log<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
CPU 3% LPM 96% tx 0% rx 0% idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> <br />
read powfile.log 0 40<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
change power to 0CPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2043 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2073 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2046 uWCPU<br />
3% LPM 96% tx 0% rx 0% idle tx 0% idle <br />
rx 0% tot 2150 uWCPU 3% LPM 96% tx 0% rx<br />
0% idle tx 0% idle rx 0% tot 2099 uWcha<br />
nge power to 10CPU 3% LPM 96% tx 0% rx 0<br />
% idle tx 0% idle rx 0% tot 2148 uWCPU 3<br />
% LPM 96% tx 0% rx 0% idle tx 0% idle rx<br />
0% tot 2099 uWchange power to 31CPU 3% <br />
LPM 96% tx 0% rx 0% idle tx 0% idle rx 0<br />
% tot 2071 uWCPU 3% LPM 96% tx 0% rx 0% <br />
idle tx 0% idle rx 0% tot 2086 uW<br />
5.0: Contiki> </pre><br />
----------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1432Contiki Shell2014-11-09T06:53:51Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''5) LED Related Commands:'''</p><br />
<p>'''blink [num]''': blink LEDs ([num] times)</p><br />
<p>'''shell-blink.c''' : This file holds all the LED blink related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_blink_init()''': This function is used to register LED blink related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
----------------------------<br />
<p>LED's blink 5 times</p><br />
<p>blink 5<p><br />
<pre>5.0: Contiki> <br />
blink 5<br />
SEND 8 bytes<br />
5.0: Contiki></pre><br />
----------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1428Contiki Shell2014-11-09T06:50:24Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>set nodeid</p><br />
<p>nodeid 5 </p><br />
<pre>5.0: Contiki> <br />
nodeid 5<br />
SEND 9 bytes<br />
Node ID: 5<br />
5.0: Contiki></pre><br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1422Contiki Shell2014-11-09T06:45:17Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------<br />
<p> This set of commands prints the sensor data in human readable format</p><br />
<p>sense|senseconv</p><br />
<pre>5.0: Contiki> <br />
sense|senseconv<br />
SEND 16 bytes<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the txpower as 5, which is being set </p><br />
<p>Print format: msglen power</p><br />
<p>txpower 5 | binprint</p><br />
<pre>5.0: Contiki> <br />
txpower 5 | binprint<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
1 5 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p> Following command prints out the rfchannel as 15, which is being set </p><br />
<p>Print format: msglen channelno</p><br />
<p>rfchannel 15| binprint</p><br />
<pre>5.0: Contiki> <br />
rfchannel 15| binprint<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
1 15 <br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>Following command outputs the sensor measurements every time step 4 times and appends to a file </p><br />
<p>repeat 4 1 {sense | senseconv | append logfile.txt}</p><br />
<p>read logfile.txt 0 36</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {sense | senseconv | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 12 bytes<br />
Light 1 5<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 11<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 8<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 2<br />
Voltage 2.5<br />
Light 1 4<br />
Light 2 13<br />
Temperature 615.7<br />
Relative humidity 2650<br />
RSSI 0<br />
Voltage 2.5<br />
5.0: Contiki> <br />
read logfile.txt 0 36<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
Light 1 5Light 2 13Temperature 615.7<br />
Relative humidity 2650RSSI 11Voltage<br />
2.5Light 1 4Light 2 13Temperature 6<br />
15.7Relative humidity 2650RSSI 8Volt<br />
age 2.5Light 1 4Light 2 13Temperatur<br />
e 615.7Relative humidity 2650RSSI 2V<br />
oltage 2.5Light 1 4Light 2 13Tempera<br />
ture 615.7Relative humidity 2650RSSI<br />
0Voltage 2.5<br />
5.0: Contiki></pre><br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1393Contiki Shell2014-11-09T06:33:17Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
'''4) Sky mote Related Commands:'''<p></p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1389Contiki Shell2014-11-09T06:31:46Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>'''4) Sky mote Related Commands:'''</p><br />
'''sense''': print out sensor data.<p><\p><br />
'''senseconv''': convert 'sense' data to human readable format.<p><\p><br />
'''nodeid''': 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.<p><\p><br />
'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<p><\p><br />
'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<p><\p><br />
<br />
'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell.<p></p><br />
'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.<p></p><br />
<br />
'''Examples'''<p></p><br />
<br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1388Contiki Shell2014-11-09T06:30:08Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>'''4) Sky mote Related Commands:'''</p><br />
<p>'''sense''': print out sensor data<\p><br />
<p>'''senseconv''': convert 'sense' data to human readable format.<\p><br />
<p>'''nodeid''': 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.<\p><br />
<p>'''txpower <power>''': change CC2420 transmission power (0 - 31).If no power was given on the command line, we print out the current power.<\p><br />
<p>'''rfchannel <channel>''': change CC2420 radio channel (11 - 26).If no channel was given on the command line, we print out thecurrent channel.<\p><br />
<br />
<p>'''shell-sky.c''' : This file holds all the sky mote related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_sky_init()''': This function is used to register sky mote related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1380Contiki Shell2014-11-09T06:23:17Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p><br />
<br />
---------------------------------------------<br />
<p> Following command echos the text and is written to a file </p><br />
<p>echo howdy? | write msg.txt</p><br />
<p>echo hi! | write hi.txt</p><br />
<p>read msg.txt 0 6 </p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
echo howdy? | write msg.txt<br />
SEND 20 bytes<br />
SEND 8 bytes<br />
howdy?<br />
5.0: Contiki> <br />
echo hi! | write hi.txt<br />
SEND 20 bytes<br />
SEND 4 bytes<br />
hi!<br />
5.0: Contiki> <br />
read msg.txt 0 6 <br />
SEND 18 bytes<br />
howdy?<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
Total size: 67<br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>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 </p><br />
<p>repeat 4 1 {echo hey | append logfile.txt}</p><br />
<p>read logfile.txt 0 3</p><br />
<p>ls</p><br />
<p>rm msg.txt</p><br />
<p>rm hi.txt</p><br />
<p>rm logfile.txt</p><br />
<p>ls</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hey | append logfile.txt}<br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 3 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
read logfile.txt 0 3<br />
SEND 20 bytes<br />
SEND 1 bytes<br />
hey<br />
hey<br />
hey<br />
hey<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
6 msg.txt<br />
3 hi.txt<br />
12 logfile.txt<br />
Total size: 79<br />
5.0: Contiki> <br />
rm msg.txt<br />
SEND 11 bytes<br />
5.0: Contiki> <br />
rm hi.txt<br />
SEND 10 bytes<br />
5.0: Contiki> <br />
rm logfile.txt<br />
SEND 15 bytes<br />
5.0: Contiki> <br />
ls<br />
SEND 3 bytes<br />
58 <br />
Total size: 58<br />
5.0: Contiki></pre><br />
----------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1374Contiki Shell2014-11-09T06:05:09Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>'''ls''': list files</p><br />
<p>'''write <filename>''': write to file. To write a string of character to a file.</p><br />
<p>'''read <filename> [offset] [block size]''': 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. </p><br />
<p>'''append <filename>''': append to file.</p><br />
<p>'''rm <filename>''': remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1368Contiki Shell2014-11-09T05:48:22Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------<br />
<p>'''3) File System Related Commands:'''</p><br />
<p>ls: list files</p><br />
<p>write <filename>: write to file. To write a string of character to a file.</p><br />
<p>read <filename> [offset] [block size]: read from a file, with the offset and the block size as options. <br />
The offset is the number of characters that must be skipped before reading the file, starting from 0. <br />
The block size options separates the output of the read functions in blocks of size block size.<br />
<p>append <filename>: append to file.</p><br />
<p>rm <filename>: remove the file named filename.</p><br />
<br />
<p>'''shell-file.c''' : This file holds all the file system related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_file_init()''': This function is used to register file system related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1366Contiki Shell2014-11-09T05:43:28Z<p>Hegdea: /* Objective */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I enjoyed working with the Contiki Shell, I hope at the end you have a good learning:)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1363Contiki Shell2014-11-09T05:38:04Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
---------------------------------------------<br />
<p>prints hello 4 times every 1 time step and immediately gets back to prompt and runs the command in the background</p><br />
<p>repeat 4 1 {echo hello} &</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
repeat 4 1 {echo hello} &<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
5.0: Contiki> <br />
hello<br />
hello<br />
hello<br />
hello<br />
<br />
SEND 1 bytes<br />
5.0: Contiki></pre><br />
---------------------------------------------</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1358Contiki Shell2014-11-09T05:34:38Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime from the time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre><br />
---------------------------------------------<br />
<br />
<p>Following command will print the time elapsed every sec for 100 secs</p><br />
<p>time | repeat 20 1 {time | binprint}</p><br />
<pre>5.0: Contiki> <br />
time | repeat 20 1 {time | binprint}<br />
SEND 20 bytes<br />
SEND 17 bytes<br />
�z�^z���<br />
5.0: Contiki> <br />
6 35963 31502 0 65535 0 251 <br />
6 36090 64068 0 65535 0 252 <br />
6 36218 31300 0 65535 0 253 <br />
6 36346 64068 0 65535 0 254 <br />
6 36474 31300 0 65535 0 255 <br />
6 36602 64068 0 65535 0 256 <br />
6 36730 31300 0 65535 0 257 <br />
6 36858 64068 0 65535 0 258 <br />
6 36986 31300 0 65535 0 259 <br />
6 37114 64068 0 65535 0 260 <br />
6 37242 31300 0 65535 0 261 <br />
6 37370 64068 0 65535 0 262 <br />
6 37498 31300 0 65535 0 263 <br />
6 37626 64068 0 65535 0 264 <br />
6 37754 31300 0 65535 0 265 <br />
6 37882 64068 0 65535 0 266 <br />
6 38010 31300 0 65535 0 267 <br />
6 38138 64068 0 65535 0 268 <br />
6 38266 31300 0 65535 0 269 <br />
6 38394 64068 0 65535 0 270</pre><br />
<p>Press Cntrl+Return to get the shell prompt back after output is printed.</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1356Contiki Shell2014-11-09T05:29:30Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>Following command will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>Following command will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre><br />
----------------------------------------------<br />
<p>Following command will print time elapsed every one sec, after waiting for randomtime since time was reset to 0 secs.</p><br />
<p>time 0 | randwait 10 {repeat 10 1 {time | binprint}}</p><br />
<pre>5.0: Contiki> <br />
time 0 | randwait 10 {repeat 10 1 {time | binprint}} <br />
SEND 20 bytes<br />
SEND 20 bytes<br />
SEND 13 bytes<br />
5.0: Contiki> <br />
6 4870 1641 0 65535 0 9 <br />
6 4998 34372 0 65535 0 10 <br />
6 5126 1604 0 65535 0 11 <br />
6 5254 34372 0 65535 0 12 <br />
6 5382 1605 0 65535 0 13 <br />
6 5510 34372 0 65535 0 14 <br />
6 5638 1604 0 65535 0 15 <br />
6 5766 34372 0 65535 0 16 <br />
6 5894 1604 0 65535 0 17 <br />
6 6022 34372 0 65535 0 18</pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1355Contiki Shell2014-11-09T05:24:30Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>This will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : [len] [clock] [rtimer] [timesynch] [timesynch] [authority] time[1] time[0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre><br />
--------------------------------------------<br />
<p>This will set the current time on mote to 66000 secs after 1970.</p><br />
<p>Since 66000 > 65536 , time[0] overflows and time[1] has the order bits </p><br />
<p>time 66000 | binprint </p><br />
<pre> 5.0: Contiki> <br />
time 66000 | binprint<br />
SEND 20 bytes<br />
SEND 2 bytes<br />
6 39554 33340 0 65535 1 464 <br />
5.0: Contiki></pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1349Contiki Shell2014-11-09T05:19:31Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p><br />
-------------------------------------------<br />
<p>This will set the current time on mote to 10 secs after 1970.</p><br />
<p>That it forces the time to be set to a value given.</p><br />
<p>format of print : len clock rtimer timesynch timesynch_authority time[1] time [0]</p><br />
<p>time 10 | binprint </p><br />
<pre>5.0: Contiki> <br />
time 10 | binprint<br />
SEND 19 bytes<br />
6 59950 11844 0 65535 0 10 <br />
5.0: Contiki></pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1347Contiki Shell2014-11-09T05:14:43Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<p></p><br />
time [seconds]''': output time in binary format, or set time in seconds since 1970.<p></p><br />
'''repeat <num> <time> <command>''': run a command every time seconds.<p></p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<p></p><br />
'''timestamp''': prepend a timestamp to data.<p></p><br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<p></p><br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<p></p><br />
'''Examples'''<p></p><br />
<p></p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1346Contiki Shell2014-11-09T05:13:11Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
'''2) Time related Shell commands'''<br />
time [seconds]''': output time in binary format, or set time in seconds since 1970.<br />
'''repeat <num> <time> <command>''': run a command every time seconds.<br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<br />
'''timestamp''': prepend a timestamp to data.<br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<br />
'''Examples'''</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1344Contiki Shell2014-11-09T05:11:15Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>''': print <text></p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
<p>'''2) Time related Shell commands'''</p><br />
<p>'''time [seconds]''': output time in binary format, or set time in seconds since 1970.</p><br />
<p>'''repeat <num> <time> <command>''': run a command every time seconds.</p><br />
<p>'''randwait <maxtime> <command>''': wait for a random time before running a command.</p><br />
<p>'''timestamp''': prepend a timestamp to data.</p><br />
<br />
<p>'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1340Contiki Shell2014-11-09T05:08:19Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>: print <text>'''</p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size''': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre><br />
------------------------------------------<br />
<p>'''2) Time related Shell commands'''</p><br />
<p>'''time [seconds]''': output time in binary format, or set time in seconds since 1970.</p><br />
<p>'''repeat <num> <time> <command>''': run a command every time seconds.</p><br />
<p>'''randwait <maxtime> <command>''': wait for a random time before running a command.</p><br />
<p>'''timestamp''': prepend a timestamp to data.</p><br />
<br />
<p>'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</p><br />
<br />
<p>'''Examples'''</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1337Contiki Shell2014-11-09T05:05:46Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''echo <text>: print <text>'''</p><br />
<p>'''binprint''': print binary data in decimal format</p><br />
<p>'''hd''': print binary data in hexadecimal format</p><br />
<p>'''size'': print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press Cntrl+Return<br />
<p>hello world</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press Cntrl+Return<br />
<p>trojan for life!</p><br />
Press Cntrl+Return to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1333Contiki Shell2014-11-09T05:01:58Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>echo <text>: print <text></p><br />
<p>binprint: print binary data in decimal format</p><br />
<p>hd: print binary data in hexadecimal format</p><br />
<p>size: print the size of the input</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>The following commands prints time data in decimal format.</p><br />
<p>2943 secs have elapsed since the mote was last power up.</p><br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>The following command prints data in hexadecimal format.</p><br />
<p>hd</p><br />
Press CNTRL+RETURN<br />
<p>hello world</p><br />
Press CNTRL+RETURN to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>The following command prints size of the data.</p><br />
<p>size</p><br />
Press CNTRL+RETURN<br />
<p>trojan for life!</p><br />
Press CNTRL+RETURN to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1332Contiki Shell2014-11-09T04:57:56Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
------------------------------------------<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre><br />
------------------------------------------<br />
<p>time | binprint </p><br />
<pre>5.0: Contiki> <br />
time | binprint<br />
SEND 16 bytes<br />
6 49032 34883 0 65535 0 2943 <br />
5.0: Contiki> <br />
</pre><br />
------------------------------------------<br />
<p>hd</p><br />
Press CNTRL+RETURN<br />
<p>hello world</p><br />
Press CNTRL+RETURN to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
hd<br />
SEND 3 bytes<br />
hello world<br />
SEND 12 bytes<br />
0x6568 0x6c6c 0x206f 0x6f77 0x6c72 </pre><br />
------------------------------------------<br />
<p>size</p><br />
Press CNTRL+RETURN<br />
<p>trojan for life!</p><br />
Press CNTRL+RETURN to get the shell prompt back.<br />
<pre>5.0: Contiki> <br />
size<br />
SEND 5 bytes<br />
trojan for life!<br />
SEND 17 bytes<br />
<br />
SEND 1 bytes<br />
16<br />
5.0: Contiki> </pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1331Contiki Shell2014-11-09T04:49:13Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>Contiki Shell Commands</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p><br />
<br />
'''Examples'''<br />
<br />
<p>echo carpe diem!</p><br />
<pre>5.0: Contiki> <br />
echo carpe diem!<br />
SEND 17 bytes<br />
carpe diem!<br />
5.0: Contiki></pre></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1330Contiki Shell2014-11-09T04:46:05Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<pre>'''Contiki Shell Commands'''</pre><br />
<br />
<br />
<p>'''1) Text Related Commands:'''</p><br />
<p>'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1329Contiki Shell2014-11-09T04:44:43Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<p>'''Contiki Shell Commands'''</p><br />
---------------------------<br />
<br />
1) Text Related Commands:<br />
'''shell-text.c''' : This file holds all the text related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_text_init()''': This function is used to register text related shell commands with the Contiki Shell.</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1328Contiki Shell2014-11-09T04:41:16Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<p>'''Contiki Shell Commands'''</p><br />
---------------------------<br />
<br />
'''1) Time related Shell commands'''<br />
time [seconds]: output time in binary format, or set time in seconds since 1970.<br />
repeat <num> <time> <command>: run a command every time seconds.<br />
randwait <maxtime> <command>: wait for a random time before running a command.<br />
timestamp: prepend a timestamp to data.<br />
<br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.<br />
<br />
'''Examples'''</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1325Contiki Shell2014-11-09T04:38:56Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
'''<p>Contiki Shell Commands</p>'''<br />
---------------------------<br />
<br />
<p>1) Time related Shell commands</p><br />
<p>time [seconds]: output time in binary format, or set time in seconds since 1970.</p><br />
<p>repeat <num> <time> <command>: run a command every time seconds.</p><br />
<p>randwait <maxtime> <command>: wait for a random time before running a command.</p><br />
<p>timestamp: prepend a timestamp to data.</p><br />
<br />
'''<p>shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
'''<p>shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</p><br />
<br />
'''<p>Examples'''</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1324Contiki Shell2014-11-09T04:36:30Z<p>Hegdea: </p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
<p>Everyone needs help at some point in time, don't we? So let'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 :) </p><br />
<br />
<p>You should see a list of all available shell commands as shown below:</p><br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
<p>Lets, go ahead and do the simplest first! echo :)</p><br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<p>'''Contiki Shell Commands'''</p><br />
---------------------------<br />
<br />
<p>1) Time related Shell commands</p><br />
<p>time [seconds]: output time in binary format, or set time in seconds since 1970.</p><br />
<p>repeat <num> <time> <command>: run a command every time seconds.</p><br />
<p>randwait <maxtime> <command>: wait for a random time before running a command.</p><br />
<p>timestamp: prepend a timestamp to data.</p><br />
<br />
<p>'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1323Contiki Shell2014-11-09T04:34:42Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
Everyone needs help at some point in time, don't we? So let'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 :) <br />
<br />
You should see a list of all available shell commands as shown below:<br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
Lets, go ahead and do the simplest first! echo :)<br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
<p>'''Contiki Shell Commands'''</p><br />
---------------------------<br />
<br />
<p>1) Time related Shell commands</p><br />
<p>time [seconds]: output time in binary format, or set time in seconds since 1970.</p><br />
<p>repeat <num> <time> <command>: run a command every time seconds.</p><br />
<p>randwait <maxtime> <command>: wait for a random time before running a command.</p><br />
<p>timestamp: prepend a timestamp to data.</p><br />
<br />
<p>'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell</p><br />
<p>'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</p></div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1322Contiki Shell2014-11-09T04:33:18Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
Everyone needs help at some point in time, don't we? So let'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 :) <br />
<br />
You should see a list of all available shell commands as shown below:<br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
Lets, go ahead and do the simplest first! echo :)<br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
'''Contiki Shell Commands'''<br />
---------------------------<br />
<br />
1) Time related Shell commands<br />
<p>time [seconds]: output time in binary format, or set time in seconds since 1970.</p><br />
<p>repeat <num> <time> <command>: run a command every time seconds.</p><br />
<p>randwait <maxtime> <command>: wait for a random time before running a command.</p><br />
<p>timestamp: prepend a timestamp to data.</p><br />
<br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1321Contiki Shell2014-11-09T04:29:52Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
Everyone needs help at some point in time, don't we? So let'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 :) <br />
<br />
You should see a list of all available shell commands as shown below:<br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
Lets, go ahead and do the simplest first! echo :)<br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
'''Contiki Shell Commands'''<br />
---------------------------<br />
<br />
'''1) Time related Shell commands'''<br />
<p>time [seconds]: output time in binary format, or set time in seconds since 1970.</p><br />
<p>repeat <num> <time> <command>: run a command every time seconds.</p><br />
<p>randwait <maxtime> <command>: wait for a random time before running a command.</p><br />
<p>timestamp: prepend a timestamp to data.</p><br />
<br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1319Contiki Shell2014-11-09T04:28:28Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
Everyone needs help at some point in time, don't we? So let'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 :) <br />
<br />
You should see a list of all available shell commands as shown below:<br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
Lets, go ahead and do the simplest first! echo :)<br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
'''Contiki Shell Commands'''<br />
---------------------------<br />
<br />
'''1) Time related Shell commands'''<br />
<p>time [seconds]: output time in binary format, or set time in seconds since 1970.</p><br />
<p>repeat <num> <time> <command>: run a command every time seconds. </p><br />
randwait <maxtime> <command>: wait for a random time before running a command.<br />
timestamp: prepend a timestamp to data.<br />
<br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</div>Hegdeahttp://anrg.usc.edu/contiki/index.php?title=Contiki_Shell&diff=1318Contiki Shell2014-11-09T04:27:11Z<p>Hegdea: /* Contiki Shell Commands, their usage and Contiki shell programming */</p>
<hr />
<div>[[Contiki_tutorials | Back to Contiki Tutorials]]<br />
<br />
__TOC__<br />
<br />
<br />
== Introduction ==<br />
<br />
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. <br />
<br />
Below are the various instances of shells provided in Contiki:<br />
<p>1) '''example-shell''': 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.</p><br />
<p>2) '''sky-shell''': 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.</p> <br />
<p>3) '''sky-shell-exec''': This shell is a further thinned out version and has features such as the exec command allowing to load and execute ELF files.</p><br />
<p>4) '''sky-shell-webserver''': 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.</p><br />
<br />
In this tutorial, we will run the shell over a USB serial connection and will focus on '''example-shell''', '''sky-shell''' provided in Contiki source.<br />
<br />
== Objective ==<br />
<br />
<p>At the end of this tutorial, goal is to make you at ease with the Contiki shell.</p><br />
I fell in love with the Contiki Shell, I hope at the end you will too :)<br />
<br />
== You will learn ==<br />
<br />
In this tutorial you will learn about the following topics:<br />
<p>1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.</p><br />
<p>2) Various Contiki Shell Commands, their usage and Contiki shell programming.</p><br />
<p>3) How to create your own Shell Commands.</p><br />
<p>4) How to create your own Shell for Contiki through an example project.</p><br />
<p>5) You get to execute various fun examples and understand the Contiki shell along the way.</p><br />
<p>6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.</p><br />
<br />
Sounds exciting ? Game for it ? Let's begin then!<br />
<br />
== Source Code and Example Projects ==<br />
<p>Let's figure out where the source code for shell is in Contiki </p><br />
<br />
<p>This folder has all the source and headers for the Contiki Shell </p><br />
''' ~/contiki-2.7/apps/shell '''<br />
<p> This folder has the example-shell project </p><br />
''' ~/contiki-2.7/examples/example-shell '''<br />
<p> This folder has the sky-shell project </p><br />
'''~/contiki-2.7/examples/sky-shell '''<br />
<br />
== How to Compile and Install a Contiki shell ? ==<br />
<br />
<p> ''' example-shell is a Comprehensive Shell and can be used for initial development. ''' </p><br />
<p>Pros: It'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's no stringent memory constraints on native targets, this project is useful for initial development phase.</p><br />
<p>Cons: Since this shell has comprehensive set of shell commands, it increases the memory footprint of the firmware and hence can't be compiled on Tmote Sky motes. </p><br />
<br />
<p>Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell </p><br />
<p>'''example-shell.c''' is the shell file in this project.</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***'''</p><br />
<p> 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's in it, to make our lives simpler. </p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(example_shell_process, "Contiki shell");<br />
AUTOSTART_PROCESSES(&example_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(example_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
serial_shell_init();<br />
<br />
shell_base64_init();<br />
shell_blink_init();<br />
/*shell_checkpoint_init();*/<br />
/*shell_coffee_init();*/<br />
shell_download_init();<br />
/*shell_exec_init();*/<br />
shell_file_init();<br />
shell_httpd_init();<br />
shell_irc_init();<br />
shell_netfile_init();<br />
/*shell_ping_init();*/ /* uIP ping */<br />
shell_power_init();<br />
/*shell_profile_init();*/<br />
shell_ps_init();<br />
/*shell_reboot_init();*/<br />
shell_rime_debug_init();<br />
shell_rime_netcmd_init();<br />
shell_rime_ping_init(); /* Rime ping */<br />
shell_rime_sendcmd_init();<br />
shell_rime_sniff_init();<br />
shell_rime_init();<br />
/*shell_rsh_init();*/<br />
shell_run_init();<br />
shell_sendtest_init();<br />
/*shell_sky_init();*/<br />
shell_tcpsend_init();<br />
shell_text_init();<br />
shell_time_init();<br />
shell_udpsend_init();<br />
shell_vars_init();<br />
shell_wget_init();<br />
<br />
PROCESS_END();<br />
}<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> ''' Compiling and installing the Contiki shell on native target ''' </p><br />
<pre>cd contiki-2.7/examples/example-shell <br />
make </pre><br />
<br />
''' Run the Contiki Shell on native target '''<br />
<pre>./example-shell.native </pre><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/example-shell$ ./example-shell.native <br />
Contiki 2.7 started<br />
Rime started with address 2.1<br />
MAC nullmac RDC nullrdc NETWORK Rime<br />
2.1: Contiki></pre><br />
<br />
Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell.<br />
<pre>help</pre><br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<pre>2.1: Contiki> <br />
echo hello<br />
hello<br />
2.1: Contiki></pre><br />
----------------------------------------------------------------------------------------------------------------------------------------<br />
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p><br />
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p><br />
<p>'''sky-shell.c''' is the shell file in this project</p><br />
<p>'''*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***'''</p><br />
<br />
<source lang="c"><br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
/* shell_file_init();<br />
shell_coffee_init();*/<br />
/* shell_download_init();<br />
shell_rime_sendcmd_init();*/<br />
/* shell_ps_init();*/<br />
shell_reboot_init();<br />
shell_rime_init();<br />
shell_rime_netcmd_init();<br />
/* shell_rime_ping_init();<br />
shell_rime_debug_init();<br />
shell_rime_debug_runicast_init();*/<br />
/* shell_rime_sniff_init();*/<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
/* shell_base64_init();*/<br />
shell_text_init();<br />
shell_time_init();<br />
/* shell_checkpoint_init();*/<br />
/* shell_sendtest_init();*/<br />
shell_rime_unicast_init();<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p> 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.</p><br />
<br />
<p> Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell </p><br />
<p>'''Note:''' 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't overflow. </p><br />
<br />
<p> ''' Compiling and uploading the Contiki Sky Shell on sky motes ''' </p><br />
<p>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.</p><br />
<pre>cd contiki-2.7/examples/sky-shell <br />
make TARGET=sky sky-shell.upload savetarget </pre><br />
<br />
<p>Wait for the compilation and uploading to finish.</p><br />
<p>To connect to the shell over the USB port, run: </p><br />
<br />
''' You can now login to the node with the command '''<br />
<pre>make login </pre> <p>Press the return key to get a shell prompt.</p><br />
<br />
''' After running the Contiki Shell, you will see the Contiki Sky Shell prompt '''<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
''' Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell. '''<br />
<pre>help</pre><br />
<br />
<p>You can now run any supported shell commands</p><br />
<p>For example, running '''echo hello''' will echo the <text> back on the shell prompt. </p><br />
<br />
<pre>5.0: Contiki> <br />
echo hello<br />
SEND 11 bytes<br />
hello<br />
5.0: Contiki></pre><br />
<br />
== Modify sky-shell project for this tutorial ==<br />
<br />
'''Replace the sky-shell.c file with the following version of sky-shell.c file'''<br />
<br />
<p> Please copy the below source code into the sky-shell.c file </p><br />
<source lang="c"><br />
/*<br />
* Copyright (c) 2008, Swedish Institute of Computer Science.<br />
* All rights reserved.<br />
*<br />
* Redistribution and use in source and binary forms, with or without<br />
* modification, are permitted provided that the following conditions<br />
* are met:<br />
* 1. Redistributions of source code must retain the above copyright<br />
* notice, this list of conditions and the following disclaimer.<br />
* 2. Redistributions in binary form must reproduce the above copyright<br />
* notice, this list of conditions and the following disclaimer in the<br />
* documentation and/or other materials provided with the distribution.<br />
* 3. Neither the name of the Institute nor the names of its contributors<br />
* may be used to endorse or promote products derived from this software<br />
* without specific prior written permission.<br />
*<br />
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND<br />
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE<br />
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br />
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br />
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br />
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br />
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br />
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br />
* SUCH DAMAGE.<br />
*<br />
* This file is part of the Contiki operating system.<br />
*<br />
*/<br />
<br />
/**<br />
* \file<br />
* Tmote Sky-specific Contiki shell<br />
* \author<br />
* Adam Dunkels <adam@sics.se><br />
*/<br />
<br />
#include "contiki.h"<br />
#include "shell.h"<br />
#include "serial-shell.h"<br />
#include "collect-view.h"<br />
<br />
#include "net/rime.h"<br />
<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS(sky_shell_process, "Sky Contiki shell");<br />
AUTOSTART_PROCESSES(&sky_shell_process);<br />
/*---------------------------------------------------------------------------*/<br />
#define WITH_PERIODIC_DEBUG 0<br />
#if WITH_PERIODIC_DEBUG<br />
static struct ctimer debug_timer;<br />
static void<br />
periodic_debug(void *ptr)<br />
{<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
collect_print_stats();<br />
}<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
/*---------------------------------------------------------------------------*/<br />
PROCESS_THREAD(sky_shell_process, ev, data)<br />
{<br />
PROCESS_BEGIN();<br />
<br />
#if WITH_PERIODIC_DEBUG<br />
ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);<br />
#endif /* WITH_PERIODIC_DEBUG */<br />
<br />
serial_shell_init();<br />
shell_blink_init();<br />
shell_file_init();<br />
<br />
shell_ps_init();<br />
shell_reboot_init();<br />
<br />
shell_sky_init();<br />
shell_power_init();<br />
shell_powertrace_init();<br />
<br />
shell_text_init();<br />
shell_time_init();<br />
<br />
shell_collect_view_init();<br />
<br />
#if DEBUG_SNIFFERS<br />
rime_sniffer_add(&s);<br />
#endif /* DEBUG_SNIFFERS */<br />
<br />
PROCESS_END();<br />
}<br />
/*---------------------------------------------------------------------------*/<br />
</source><br />
<br />
<p>This will create a sky shell with features or shell commands that we will go through in the next section</p><br />
<p>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</p><br />
<p>If successful you should be able to see the following and get a Contiki shell prompt</p><br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
AR contiki-sky.a<br />
CC sky-shell.c<br />
CC ../../platform/sky/./contiki-sky-main.c<br />
LD sky-shell.sky<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
../../tools/sky/msp430-bsl-linux --telosb -c /dev/ttyUSB0 -r<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
+++++ Erasing /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Mass Erase...<br />
Transmit default password ...<br />
+++++ Programming /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Invoking BSL...<br />
Transmit default password ...<br />
Current bootstrap loader version: 1.61 (Device ID: f16c)<br />
Changing baudrate to 38400 ...<br />
Program ...<br />
45722 bytes programmed.<br />
+++++ Resetting /dev/ttyUSB0<br />
MSP430 Bootstrap Loader Version: 1.39-telos-7<br />
Use -h for help<br />
Reset device ...<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.co obj_sky/contiki-sky-main.o sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login<br />
using saved target 'sky'<br />
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0<br />
connecting to /dev/ttyUSB0 (115200) [OK]<br />
+�{/#+�3++�&�<br />
SEND 1 bytes<br />
5.0: Contiki> </pre><br />
<br />
'''If you don'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'''<br />
<br />
<pre>user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make TARGET=sky sky-shell.upload savetarget<br />
msp430-objcopy sky-shell.sky -O ihex sky-shell.ihex<br />
make IHEXFILE=sky-shell.ihex sky-reset sky-upload<br />
make[1]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -k -j 20 sky-reset-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make -j 20 sky-upload-sequence<br />
make[2]: Entering directory `/home/user/contiki-2.7/examples/sky-shell'<br />
Done<br />
make[2]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
make[1]: Leaving directory `/home/user/contiki-2.7/examples/sky-shell'<br />
saving Makefile.target<br />
rm sky-shell.ihex<br />
user@instant-contiki:~/contiki-2.7/examples/sky-shell$</pre><br />
<br />
<p>This indicates that your Tmote Sky mote is disconnected!!!</p><br />
<p>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?</p><br />
<p>I did! When I figured out what was going wrong.</p><br />
<br />
'''Nevertheless, we are All Set and Good to Launch now :) :)'''<br />
<br />
== Contiki Shell Commands, their usage and Contiki shell programming ==<br />
Ready to dive in ?<br />
<br />
Everyone needs help at some point in time, don't we? So let'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 :) <br />
<br />
You should see a list of all available shell commands as shown below:<br />
<pre>5.0: Contiki> <br />
help<br />
SEND 5 bytes<br />
Available commands:<br />
?: shows this help<br />
append <filename>: append to file<br />
binprint: print binary data in decimal format<br />
blink [num]: blink LEDs ([num] times)<br />
collect-view-data: sensor data, power consumption, network stats<br />
echo <text>: print <text><br />
energy: print energy profile<br />
exit: exit shell<br />
hd: print binary data in hexadecimal format<br />
help: shows this help<br />
kill <command>: stop a specific command<br />
killall: stop all running commands<br />
ls: list files<br />
nodeid: set node ID<br />
null: discard input<br />
power: print power profile<br />
powerconv: convert power profile to human readable output<br />
powertrace [interval]: turn powertracing on or off, with reporting interval <interval><br />
ps: list all running processes<br />
quit: exit shell<br />
randwait <maxtime> <command>: wait for a random time before running a command<br />
read <filename> [offset] [block size]: read from a file, with the offset and the block size as options<br />
reboot: reboot the system<br />
repeat <num> <time> <command>: run a command every <time> seconds<br />
rfchannel <channel>: change CC2420 radio channel (11 - 26)<br />
rm <filename>: remove the file named filename<br />
sense: print out sensor data<br />
senseconv: convert 'sense' data to human readable format<br />
size: print the size of the input<br />
time [seconds]: output time in binary format, or set time in seconds since 1970<br />
timestamp: prepend a timestamp to data<br />
txpower <power>: change CC2420 transmission power (0 - 31)<br />
write <filename>: write to file<br />
5.0: Contiki> <br />
<br />
</pre><br />
<br />
Lets, go ahead and do the simplest first! echo :)<br />
<pre>5.0: Contiki> <br />
echo howdy contiki shell?<br />
SEND 20 bytes<br />
SEND 6 bytes<br />
howdy contiki shell?<br />
5.0: Contiki> <br />
</pre><br />
<br />
'''Contiki Shell Commands'''<br />
---------------------------<br />
<br />
'''1) Time related Shell commands'''<br />
'''time [seconds]''': output time in binary format, or set time in seconds since 1970. <br />
<p>'''repeat <num> <time> <command>''': run a command every time seconds. </p><br />
'''randwait <maxtime> <command>''': wait for a random time before running a command.<br />
'''timestamp''': prepend a timestamp to data.<br />
<br />
'''shell-time.c''' : This file holds all the time related shell commands. You can find the source file in this path ~/contiki-2.7/apps/shell<br />
'''shell_time_init()''': This function is used to register time related shell commands with the Contiki Shell.</div>Hegdea