Post Page Advertisement [Top]

Basic Tutorial for programming in #Contiki Operating System for #IoT| PART 3

Part 1 in this series can be found here.
Part 2 can be found here.

The next question that arises is that can we include additional processes in a file. The answer is Yes! But these processes will be concurrent. This means that they can be executed in parallel.

/*We declare two processes*/
PROCESS(process_1, "The first process");
PROCESS(process_2, "The second process");

/*The next step is to use AUTOSTART_PROCESSES. Luckily we can 
specify both of our processes in a single function call. */
AUTOSTART_PROCESSES(&process_1, &process_2);

/*The process definition for the first one*/
PROCESS_THREAD(process_1, ev, data)
/* Some Code*/

/*The process definition for the second one*/
PROCESS_THREAD(process_2, ev, data)
/* Some Code*/

So far so good. But we still haven’t done anything useful. Let's start with a basic hello world being printed. Being printed where? On the serial port. Under Cooja, you can go to Tools> Mote Interface Viewer > (Select your mote) > (In the drop menu) Serial Port.

You can also see it in the 'Mote Output' dialog box.

#include "contiki.h"
#include < stdio .h >
/*Notice I have include the standard I/O file header. This
is for enabling printf functionality */

PROCESS(process2, "Our first Hello World"); //Declare

AUTOSTART_PROCESSES(&process2); //Start

PROCESS_THREAD(process2, ev, data) //Definition
PROCESS_BEGIN(); //Here we go

printf("Hello World \n"); //A simple printf 


After simulating this code, the output looks happy:

See you later in Part 4.

| Designed by Colorlib