Setting up a Low-Power IPv6/RPL Network
From ContikiWiki
One of the defining features of Contiki is that it natively supports the Internet Protocol. This tutorial shows how to set up a Contiki low-power IPv6 network. We will use the Cooja network simulator, but the principles are the same for a network with real hardware.
For simplicity, we use Instant Contiki as the development environment.
Contents |
[edit] The easy way: load a ready-made simulation
Before going through the entire process, we will show easy way: loading an already existing simulation in Cooja.
[edit] Start Cooja and open the simulation
Start Cooja by double-clicking on the “Run Cooja” icon. If there is no Run Cooja icon in your Instant Contiki, open a terminal and run
cd contiki/tools/cooja ant run
In Cooja, open the File menu, the Open simulation menu item, and click on Browse…
Go to the directory contiki-2.x/examples/ipv6/rpl-collect and open the file collect-tree-dense-noloss.csc
[edit] Start the simulation
After Contiki has been compiled and the simulation has loaded, the CollectView window will appear on top of the Cooja window. Click on the Cooja window to bring it to the front.
This simulation is a 25 node network, running IPv6 with RPL routing, where one node is the sink node to which the others periodically send sensor data.
Click the Start button to start the simulation.
[edit] View the data from the network
After the simulation time has reached some 70000 ms, data will begin to appear at the sink node. The sink node prints out the received data on its serial port. The CollectView program listens to this (emulated) serial port and displays the data, along with information about the network.
Bring up the CollectView window to see the data. Click the Network Graph tab to see the structure of the IPv6/RPL network. Right-click on the sink node (called 1.1) and click on the Fixed Node Position menu item to fix its position. It is helpful to first uncheck the Update Layout menu item – this will cause the nodes to stop moving around.
Click on the Network tab to explore the parameters in the network. Click the <All> item on the top left to select all nodes.
The Node Info tab has more information about the nodes.
The Power tab shows the power consumption of the nodes in the network.
[edit] Set up your own simulation
Now that we know how a running simulation looks like, we can set up our own. We will use the same example C code as in the previous simulation, but we will set up the simulation ourselves.
[edit] Create a new simulation
Close the Cooja window that we previously opened. Open a new Cooja.
When Cooja has started, select the New simulation menu item on the File menu.
Create a new simulation. Give it a nice name.
[edit] Create the sink node
We now create the sink node.
When the new simulation has opened, click on the Mote Types menu, select the Create mote type menu item, and the Sky Mote Type item.
Give the mote type a name, and click on the Browse button.
Go to the directory contiki-2.x/examples/ipv6/rpl-collect and select the udp-sink.c file. This file contains the code for the sink node.
Click the Compile button to compile the sink code.
When the Compilation is complete, the Compile button has changed into a Create button. Click this button.
Create one sink node.
[edit] Create sender nodes
Next, we create the sender nodes. We create a new mote type for this. We use the Sky Mote Type as before.
The sender node uses the udp-sender.c file from the same directory as the sink node. Click the Compile and Create buttons.
Create a few nodes – say, 8.
[edit] Show mote types in simulation visualizer
In the Simulation Visualizer window, open the visualizer skin menu. Select Mote IDs and Mote Type. This will show the node ID of the nodes in the window and will color the nodes differently depending on what mote type they are. In this example, we have two mote types, one sink mote type and one sender mote type.
[edit] Start the CollectView program
Right click on the sink node. The sink node has node ID 1 and is green. Click the Open mote plugin menu. Select the Collect View menu item.
This brings up the CollectView window.
[edit] Start the simulation
Click on the Cooja window in the background and start the simulation.
[edit] View the data
Let the simulation run for 100000 ms or so, then bring up the CollectView window again. The sensors should now have begun reporting data. The Node Info tab has information about the nodes. As before, explore the other tabs as well.