Installing Conkit and verifying with Hello, World Program

Published on 2023-02-05

IoT

The is the first step to the journey of getting started with Internet of Things (IoT). We prepare the working environment (Conkit) to develop the programs to run on the devices and verify the systems with infamous "Hello, World" Program.

Introduction

Objective

At a very first start, we will prepare our working environment to be able to develop, debug and run software for wireless sensors. Then, we will run a simple ā€œHello World!ā€ program. The goals are 1. Prepare the environment for IoT development work 2. Understand Contiki C Programming 3. Compile the code into a program 4. Run the program

Prerequisites

What we are doing here is installing Contiki Operating System for IoT onto Ubuntu Operating System.

Preparing Contiki

Besides downloading the zip file, we also need to install the required packages for compiling and running ContikiOS.
Command is as follows:

sudo apt-get install build-essential binutils-msp430 gcc-msp430 msp430-libc msp430mcu mspdebug gcc-arm-none-eabi gdb-arm-none-eabi openjdk-8-jdk openjdk-8-jre ant libncurses5-dev

I would recommend installing them one by one in case there any issues. Explanation of the command: - sudo --> this is Ubuntu based command line. Sudo means giving admin rights - apt-get install --> command to fetch the application from network and install it - openjdk-8-jdk --> Java Development Kit from OpenJDK - openjdk-8-jre --> Java Runtime Environment from OpenJDK - ant --> Apache Ant, a Java library and command-line tool

System Verification

Open a terminal window, and go to the hello-world example directory (∼/contiki/examples/hello-world/). In the directory you will see - hello-world.c - Makefile - README.MD - hello-world-example.csc

Let's examine them.

hello-world.c

#include "contiki.h" // Import Contiki header to include Contiki OS into the compiled program
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process"); // Define the process. It takes in name and description.
AUTOSTART_PROCESSES(&hello_world_process); // Start this process upon launch of OS
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
  PROCESS_BEGIN();

  printf("Hello, world\n");

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/

Makefile

CONTIKI_PROJECT = hello-world
all: $(CONTIKI_PROJECT)

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

In order to run the code on the sensor node, we need to tell the compiler how to compile the programs and for which specific platform. This is where Makefile comes in. It is kind of like Dockerfile if you are familiar with Docker. In the example above, we tell the compiler the name of c file and where Contiki headers/libraries can be found.

Compiling 'Hello, world' Program

To compile the program, in the terminal, type:

make TARGET=native

It will search for Makefile in your current directory of terminal and compile the program. In the context of Contiki OS, TARGET=native is a makefile variable used to specify the target system for building and running the operating system. The native target is used to build and run the operating system natively on a host computer, without using any hardware or emulated hardware.

This target is typically used for development and testing purposes, as it allows developers to quickly test changes to the operating system and verify that they work correctly before deploying them to real hardware.

The native target is different from other targets, such as zoul or sky, which are used to build and run the operating system on specific types of hardware platforms. When building for the native target, the operating system uses the host computer's resources, such as its CPU and memory, instead of the resources of a specific hardware platform.

Running 'Hello, world' Program

Now that, we have our executable, we can run by typing below command line in terminal:

./hello-world.native
The program should print the words ā€œHello, world ā€ on the screen and then appear to hang. In reality, Contiki is still running correctly, but will not produce any output because the Hello World program has finished. Press Ctrl+C on the keyboard to quit.

Congratulation, you have just run your first Hello World program of Conkit!