Difference between revisions of "Contiki Shell"

From Contiki
Jump to: navigation, search
(How to Install a Contiki shell ?)
(How to Install a Contiki shell ?)
Line 117: Line 117:
 
<pre>help</pre>
 
<pre>help</pre>
  
 +
----------------------------------------------------------------------------------------------------------------------------------------
 
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p>
 
<p> '''sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes. ''' </p>
 
+
<p>Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell </p>
 
<p>'''sky-shell.c''' is the shell file in this project</p>
 
<p>'''sky-shell.c''' is the shell file in this project</p>
 
<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>
 
<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>

Revision as of 18:52, 8 November 2014

Back to Contiki Tutorials


Introduction

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. In this tutorial, we will run the shell over a USB serial connection.

Below are the various instances of shells provided in Contiki:

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.

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.

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.

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.

In this tutorial we will focus on the Contiki Serial Shell.

Objective

At the end of this tutorial, goal is to make you at ease with the Contiki shell.

I fell in love with the Contiki Shell, I hope at the end you will too :)

You will learn

In this tutorial you will learn about the following topics:

1) How to get a Contiki Serial Shell up and running on Tmote sky nodes.

2) Various Contiki Shell Commands, their usage and Contiki shell programming.

3) How to create your own Shell Commands.

4) How to create your own Shell for Contiki through an example project.

5) You get to execute various fun examples and understand the Contiki shell along the way.

6) Last, but not least, where all the source code for Contiki is located and a code walkthrough.

Sounds exciting ? Game for it ? Let's begin then!

Source Code and Example Projects

Let's figure out where the source code for shell is in Contiki

This folder has all the source and headers for the Contiki Shell

~/contiki-2.7/apps/shell

This folder has the example-shell project

~/contiki-2.7/examples/example-shell

This folder has the sky-shell project

~/contiki-2.7/examples/sky-shell

How to Install a Contiki shell ?

example-shell is a Comprehensive Shell and can be used for initial development.

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.

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.

Navigate to this path to find the example-shell project : ~/contiki-2.7/examples/example-shell

example-shell.c is the shell file in this project

*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space while compiling try removing these. ***

/*---------------------------------------------------------------------------*/
PROCESS(example_shell_process, "Contiki shell");
AUTOSTART_PROCESSES(&example_shell_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_shell_process, ev, data)
{
  PROCESS_BEGIN();

  serial_shell_init();

  shell_base64_init();
  shell_blink_init();
  /*shell_checkpoint_init();*/
  /*shell_coffee_init();*/
  shell_download_init();
  /*shell_exec_init();*/
  shell_file_init();
  shell_httpd_init();
  shell_irc_init();
  shell_netfile_init();
  /*shell_ping_init();*/ /* uIP ping */
  shell_power_init();
  /*shell_profile_init();*/
  shell_ps_init();
  /*shell_reboot_init();*/
  shell_rime_debug_init();
  shell_rime_netcmd_init();
  shell_rime_ping_init(); /* Rime ping */
  shell_rime_sendcmd_init();
  shell_rime_sniff_init();
  shell_rime_init();
  /*shell_rsh_init();*/
  shell_run_init();
  shell_sendtest_init();
  /*shell_sky_init();*/
  shell_tcpsend_init();
  shell_text_init();
  shell_time_init();
  shell_udpsend_init();
  shell_vars_init();
  shell_wget_init();

  PROCESS_END();
}

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

Compiling and installing the Contiki shell on native target

cd contiki-2.7/examples/example-shell 
make  

Run the Contiki Shell on native target

./example-shell.native 

After running the Contiki Shell, you will see the Contiki Shell prompt

Contiki 2.7 started
Rime started with address 2.1
MAC nullmac RDC nullrdc NETWORK Rime
2.1: Contiki> 

Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell

help

sky-shell is a thinned out version of Contiki Shell for Tmote Sky motes.

Navigate to this path to find the sky-shell project : ~/contiki-2.7/examples/sky-shell

sky-shell.c is the shell file in this project

*** Each shell_xx_init() adds a set of features to shell, hence if you run out of space on the mote try removing these. ***

/*---------------------------------------------------------------------------*/
PROCESS(sky_shell_process, "Sky Contiki shell");
AUTOSTART_PROCESSES(&sky_shell_process);
/*---------------------------------------------------------------------------*/
#define WITH_PERIODIC_DEBUG 0
#if WITH_PERIODIC_DEBUG
static struct ctimer debug_timer;
static void
periodic_debug(void *ptr)
{
  ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);
  collect_print_stats();
}
#endif /* WITH_PERIODIC_DEBUG */
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sky_shell_process, ev, data)
{
  PROCESS_BEGIN();

#if WITH_PERIODIC_DEBUG
  ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);
#endif /* WITH_PERIODIC_DEBUG */

  serial_shell_init();
  shell_blink_init();
  /*  shell_file_init();
      shell_coffee_init();*/
  /*  shell_download_init();
      shell_rime_sendcmd_init();*/
  /*  shell_ps_init();*/
  shell_reboot_init();
  shell_rime_init();
  shell_rime_netcmd_init();
  /*  shell_rime_ping_init();
  shell_rime_debug_init();
  shell_rime_debug_runicast_init();*/
  /*  shell_rime_sniff_init();*/
  shell_sky_init();
  shell_power_init();
  shell_powertrace_init();
  /*  shell_base64_init();*/
  shell_text_init();
  shell_time_init();
  /*  shell_checkpoint_init();*/
  /*  shell_sendtest_init();*/
  shell_rime_unicast_init();
  shell_collect_view_init();

#if DEBUG_SNIFFERS
  rime_sniffer_add(&s);
#endif /* DEBUG_SNIFFERS */
  
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/

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.

Hence, commented out shell_xx_init() which corresponds to specific set of shell commands, will not be available in this shell

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.

Compiling and uploading the Contiki Sky Shell on sky motes

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.

cd contiki-2.7/examples/sky-shell 
make TARGET=sky sky-shell.upload savetarget 

Wait for the compilation and uploading to finish.

To connect to the shell over the USB port, run:

You can now login to the node with the command

make login 

Press the return key to get a shell prompt.

After running the Contiki Shell, you will see the Contiki Sky Shell prompt

user@instant-contiki:~/contiki-2.7/examples/sky-shell$ make login
using saved target 'sky'
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0
connecting to /dev/ttyUSB0 (115200) [OK]

SEND 1 bytes
5.0: Contiki> 

Punch in help on the Contiki Shell prompt to see all the available shell commands in Contiki shell

help