Build your own application in Contiki

From Contiki
Revision as of 21:43, 22 November 2014 by Nitin (Talk | contribs) (Step 4)

Jump to: navigation, search

Back to Contiki Tutorials


This tutorial help you understand how to build you own application in Contiki. Section#2 How to start an application in Contiki walk you through the complete process of writing you own application in Contiki. Section#3 Generic structure of Application in Contiki gives a generic skeleton of any application in contiki.

How to start an application in Contiki

Step 1

Go to the directory contiki/examples and make new sub directory named my_first_app

Byaic 1.png

Step 2

Now create a new C file named my_first_app.c

Byaic 2.png

Step 3

Write my_first_app.c

 <Header Files>


      /* Declare variables required */
      static int i=652;         

      /* Begin Process */

      /* Set of C statement(s) */
      printf("EE-%d is an awesome course at USC\n");             
      /* Process End */

Every process in Contiki should start with the PROCESS macro. It takes two arguments

  • name: The variable name of the process structure.
  • strname: The string representation of the process name.

Then comes another macro AUTOSTART_PROCESS(struct process &). AUTOSTART_PROCESSES automatically starts the process(es) given in the argument(s) when the module boots.

  • &name: Reference to the process name.
                     AUTOSTART_PROCESS(struct process &) 

Then we call the PROCESS_THREAD function. This function is used to define the protothread of a process. The process is called whenever an event occurs in the system.Each process in the module requires an event handler under the PROCESS_THREAD macro.

  • name: The variable name of the process structure.
  • process_event_t: The variable of type character.If this variable is same as PROCESS_EVENT_EXIT then PROCESS_EXITHANDLER is invoked.
               PROCESS_THREAD(name, process_event_t, process_data_t) 

Then comes the PROCESS_BEGIN macro. This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition.


Then we write the set of C statements as per the requirement of the application.

At the end we use another macro called PROCESS_END. This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.


Step 4

Makefile - Create makefile in the same folder (contiki/exmples/my_first_app)

 CONTIKI_PROJECT = my_first_app


 CONTIKI = ../..
 include $(CONTIKI)/Makefile.include


Step 5

Compilation - Use terminal to go to "contiki/examples/my_first_app" directory. Once you are in this directory type "make". This will compile your code and generates all the supporting files like .csc file, symbols.c, symbols.h etc.

Step 6

Upload the firmware on Tmote Sky - Plug the Tmote Sky in your computer. Then use the terminal window to go to contiki/examples/my_first_app and then write the following commands to upload your program on the Tmote Sky.

make TARGET=sky savetarget (This save the target for any future compilations)
make my_first_app.upload (This will upload the code on the Tmote Sky)
make login (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)

See the following link for troubleshooting -

Press the reset button on the Tmote Sky. The following message will appear on the terminal window

EE-652 is an awesome course at USC

Then Press CTRL-C to quit.

Generic structure of Application in Contiki

<Header Files>

AUTOSTART_PROCESSES(struct process &);

PROCESS_THREAD(name, process_event_t, process_data_t)

----Initialization of required variables----


---Set of C statements---




Back to Contiki Tutorials

Edited by : Nitin