Desarrollo Parte 2
Desarrollo Parte 2
School 2013 -
University of Parma
1 Introduction
Welcome to this Contiki programming course! Contiki is a state-of-the-art, open
source operating system for sensor networks and other networked embedded
devices [1].
You will look at various cool Contiki features such as the uIP stack (IPv6, RPL,
6LoWPAN), HTTP/CoAP, power profiling and others. We will use Tmote Sky
boards as our hardware target. We will also use the Cooja network simulator
which emulates Tmote Sky nodes and connects them.
You can use the Instant Contiki development environment in the exercises. In-
stant Contiki is a single-file download that contains the Contiki source code
and all necessary compilers and tools required for developing software for Con-
tiki. The Instant Contiki environment is a Ubuntu Linux installation that runs
within the VMware Player virtual machine execution environment. VMware
Player is available for free at the VMware website. If you have Contiki working
on your native machine without Instant Contiki that is of course also fine.
2 Getting Started
Before starting with the actual exercises, make sure that your development setup
works by conducting the steps below.
1
2.1 Start Instant Contiki
Open the file
instant-contiki.vmx
2.2 Log In
When the login screen appears, log in to Instant Contiki:
Username: user
Password: user
$ cd contiki
$ cd examples/hello-world
$ make TARGET=native
Wait for the compilation to finish. Run the Hello World program in Contiki:
$ ./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 more output because the Hello World program has finished. Press Ctrl+C
on the keyboard to quit.
Note that Contiki uses printf to issue logs and messages. This can also be
used when you have a sensor node that is connected via a serial line, e.g. USB,
to a laptop.
2
2.5.1 Compile Contiki for the Tmote Sky
Compile Contiki for the sky platform:
Put a Tmote Sky in a computer’s USB port. The Tmote Sky will appear in
the top of the Instant Contiki (VMware Player) window with the name “Future
Device” in the menu “Player/Removable Devices”. Click on the name to connect
the Tmote Sky to Instant Contiki (note this will disconnect the device from the
host OS). Run the following to find all connected sky nodes and their associated
tty file:
$ make sky-motelist
During the uploading the Tmote Sky should quickly flash the red LEDs next to
the USB connector.
Once the upload is terminated, connect to the USB port to view the program
output:
Press the reset button on the Tmote Sky (the one further away from the USB
connector) and you should get some Contiki startup log messages followed by
Hello, world.
3
Exercise 2.Install the test-button program from the examples/sky directory.
Connect to the USB port (make login) and press the non-reset button (the one
closest to the USB connector).
4
Figure 2.1: The Cooja simulator
state of a current simulation is however not saved; all nodes are reset when the
simulation is loaded again. To save your current simulation:
Simulations are stored with the file extensions “.csc”. To later load a simulation:
5
and tick Radio Environment (UDGM) in the text window that pops up. If
you now left-click on one of the nodes, you will see a green circle around the
selected node. The green circle presents the transmission range of the node,
i.e. the selected node can communicate with all other nodes within that circle.
You may also see a grey circle around the green circle. This circle represents
the interference range. That is when the selected nodes transmits packets,
a node in the grey area cannot receive packets correctly but it is interferred
which means that it is not able to receive packets from other nodes when the
selected node communicates simultaneously. The areas that are not covered by
the green or grey circle are white; communication in that areas is not affected
at all by transmission from the selected nodes.
3 Single-Node Exercises
You will now extend the hello-world example to add more complex stuff. Create
a folder in an easy-to-access location. This folder will contain all the projects of
this course. Copy+paste the contiki/examples/hello-world folder in your
new folder. Use an editor that works for you (Eclipse is pre-installed).
#include "dev/button-sensor.h"
#include "dev/light-sensor.h"
#include "dev/leds.h"
#include <stdio.h> /* For printf() */
SENSORS_ACTIVATE(button_sensor);
SENSORS_ACTIVATE(light_sensor);
6
To wait for an event and check if this event is a button press:
PROCESS_WAIT_EVENT();
if(ev == sensors_event && data == &button_sensor) {
..
}
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_even
&& data == &button_sensor);
To toggle LEDs:
leds_toggle(LEDS_ALL);
Exercise 3.Write a program that loops indefinitely, checks if a button has been
pressed, and if so, toggles LEDs and prints out (printf) a message. Test it on
your mote.
Do you get the expected result? If not, then you have experienced one pecu-
liarity of protothreads: local variables are not stored across a blocking wait. A
workaround consists in declaring your variable as static. Doing so, the variable
is stored in the data segment rather than the runtime stack.
Exercise 5.Fix your counter program accordingly, and test it on your mote.