In a previous article I wrote about writing a simple application for RIOT OS and and running it on native platform. It's time to go beyond that point and explore what's more we can do inside RIOT applications. In this article, I would like to show the things I have explored with shell module in RIOT. When we enable the shell module for a user application, we get a nice shell interface using which we can interact with the application.
Let's go ahead and modify our application program to have a shell interface. It can be done by adding few lines to the existing program. Below code shows the updated main.c program which invokes the shell module.
Then we can compile and run this program as usual.
Now we get the shell prompt of our program. We can type help on the prompt to see the available commands for us in this shell program. However in this shell we don't have any command. We can exit from the running RIOT instance by issuing a Ctrl+C on the prompt.
In order to make different RIOT commands available for the shell, we have to enable different modules at the compile time. We do that by updating the Makefile of our program. Update the right place to enable the two modules shell_commands and ps in our user program. Following excerpt is from the updated region of my Makefile.
This time when you compile and run the application, you will see that two new commands are available to you. In my shell I got reboot and ps commands. Now we know how we get them by enabling different modules in the Makefile. What if I wanted some new commands in my program with the shell. Is there any way to add my own commands that do different things on the shell? Yes, there is a way to define new commands and make them available to your programs. Let's try that. Following code shows an updated version of our main.c program which has a new command called echo defined by ourself.
When you compile and run this program you should see that a new command called echo is available to you. I hope this blog post helps to understand how we utilize the shell module in our programs.