Warning: Parameter 1 to Language::getMagic() expected to be a reference, value given in /home/project-web/zolertia/htdocs/wiki/includes/StubObject.php on line 58
Mainpage:Contiki apps - Zolertia

Mainpage:Contiki apps

From Zolertia

Jump to: navigation, search

Contents


Contiki applications

The following examples can also be found in the "/examples/z1 directory" of your Contiki files as they are integrated as part of Contiki release.

To visualize the test results you can use the terminal windows by just typing:

make z1-reset && make login

Or use a serial client like putty and configure it with a 115200 baudrate, 8/1/N.

Test sensors

There's a specific section dedicated to the sensors currently supported by the Z1 mote:


Change the default MAC address and Node ID, and burn it to flash

To spare you the pain to manually modify the Node ID and the MAC address (and thus the IPv6 address as it is formed out of the MAC address), we have prepared a single program that allows you to burn the MAC address and Node ID to the flash memory, so it can be used each time at mote initialization.

As you can see in /platform/z1/contiki-z1-main.c (snippet below) the first bytes of the MAC address are hardcoded, which means that the program will only allow you to change the last 2 bytes, if you wish to change the upper bytes then you will have to modify node_mac[0-5].

#ifdef MACID 
  #warning "***** CHANGING DEFAULT MAC *****"
  node_mac[0] = 0xC1;  // Hardcoded for Z1
  node_mac[1] = 0x0C;  // Hardcoded for Revision C
  node_mac[2] = 0x00;  // Hardcoded to arbitrary even number so that the 802.15.4 MAC address 
                       // is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
  node_mac[3] = 0x00;  // Hardcoded 
  node_mac[4] = 0x00;  // Hardcoded 
  node_mac[5] = 0x00;  // Hardcoded
  node_mac[6] = MACID >> 8;
  node_mac[7] = MACID & 0xff;
#endif

To burn the MAC address and the node ID we take as a reference the serial number of the mote, you can of course take any numbering you want:

In /examples/z1 run:

make clean && make burn-nodeid.upload nodeid=158 nodemac=158 && make z1-reset && make login

Note: DO NOT use 0 at the beginning of the address, as this is actually a compiler flag will give you an error, for example instead of 0158 just type 158.

You will see an output like this:

Starting 'Burn node id'
Burning node id 158
Restored node id 158

Now lets try the new MAC/IPv6 address, go to /examples/z1/ipv6/z1-websense

make z1-websense.upload && make z1-reset && make login
 
Rime started with address 193.12.0.0.0.0.0.158
MAC c1:0c:00:00:00:00:00:9e Contiki-2.5-1362-gd2aece8 started. Node id is set to 158.
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26
Tentative link-local IPv6 address fe80:0000:0000:0000:c30c:0000:0000:009e
Starting 'Sense Web Demo'

And that's all!


Create a quick IPv6 network using Contiki and the Z1 motes

Tested with rev. 0fc5ec8 and msp430-gcc-4.4.5

This small example will allow to create a simple RPL-based IPv6 network to start working with Contiki and learn about how IPv6 its implemented. For this practice is required at least 2 Zolertia Z1 nodes.

Important: for this test to work (well, to be more accurate) it is necessary to flash each of your nodes with a known mac or number id (see section above). This guide also assumes that the reader is using the latest Contiki version available, if not please check the installation instructions.

First lets compile the border router:

examples/ipv6/rpl-border-router$make TARGET=z1 savetarget
examples/ipv6/rpl-border-router$make border-router.upload

Then when it finishes:

examples/ipv6/rpl-border-router$ make z1-reset && make connect-router
using saved target 'z1'
make -k -j 20 z1-reset-sequence
using saved target 'z1'
make[1]: Entering directory `/home/a-linan/Desktop/Contiki/contiki-2.x/contiki-mirror/examples/ipv6/rpl-border-router'
../../../tools/z1/z1-bsl-nopic --z1 -c /dev/ttyUSB0 -r
MSP430 Bootstrap Loader Version: 1.39-goodfet-8
Use -h for help
Use --fromweb to upgrade a GoodFET.
Reset device ...
Done
make[1]: Leaving directory `/home/a-linan/Desktop/Contiki/contiki-2.x/contiki-mirror/examples/ipv6/rpl-border-router'
using saved target 'z1'
sudo ../../../tools/tunslip6 aaaa::1/64
********SLIP started on ``/dev/ttyUSB0''
opened tun device ``/dev/tun0''
ifconfig tun0 inet `hostname` up
ifconfig tun0 add aaaa::1/64
ifconfig tun0
 
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:127.0.1.1  P-t-P:127.0.1.1  Mask:255.255.255.255
          inet6 addr: aaaa::1/64 Scope:Global
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
 
Rime started with address 193.12.0.0.0.0.4.7
MAC c1:0c:00:00:00:00:04:07 Contiki-2.5-1644-g7ca141b started. Node id is set to 1031.
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26
Tentative link-local IPv6 address fe80:0000:0000:0000:c30c:0000:0000:0407
Starting 'Border router process' 'Web server'
*** Address:aaaa::1 => aaaa:0000:0000:0000
SIN: 10
Got configuration message of type P
Setting prefix aaaa::
Server IPv6 addresses:
 aaaa::c30c:0:0:407
 fe80::c30c:0:0:407

The border router is all set, for this particular case the address of the mote is aaaa::c30c:0:0:407 as this was the ID flashed to the mote. After the tun0 interface has been created and configured, we need more motes to populate the network, attach another mote and in a different window (do not close the window with the running script!), to differentiate which mote to program use the "MOTES" argument as shown below (assuming the new connected mote is in /dev/ttyUSB1):

 /examples/ipv6/rpl-udp$ make TARGET=z1 savetarget
/examples/ipv6/rpl-udp$ make udp-client.upload MOTES=/dev/ttyUSB1

When this finishes compiling/uploading, reboot the mote and log into it to see what is happening:

/examples/ipv6/rpl-udp$ make z1-reset MOTES=/dev/ttyUSB1 && make login MOTES=/dev/ttyUSB1
using saved target 'z1'
make -k -j 20 z1-reset-sequence
using saved target 'z1'
make[1]: Entering directory `/home/a-linan/Desktop/Contiki/contiki-2.x/contiki-mirror/examples/ipv6/rpl-udp'
../../../tools/z1/z1-bsl-nopic --z1 -c /dev/ttyUSB1 -r
MSP430 Bootstrap Loader Version: 1.39-goodfet-8
Use -h for help
Use --fromweb to upgrade a GoodFET.
Reset device ...
Done
make[1]: Leaving directory `/home/a-linan/Desktop/Contiki/contiki-2.x/contiki-mirror/examples/ipv6/rpl-udp'
using saved target 'z1'
../../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB1
connecting to /dev/ttyUSB1 (115200) [OK]
Rime started with address 193.12.0.0.0.0.0.158
MAC c1:0c:00:00:00:00:00:9e Contiki-2.5-1645-g6f4ff36 started. Node id is set to 158.
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26
Tentative link-local IPv6 address fe80:0000:0000:0000:c30c:0000:0000:009e
Starting 'UDP client process'
UDP client process started
Client IPv6 addresses: aaaa::c30c:0:0:9e
fe80::c30c:0:0:9e
Created a connection with the server :: local/remote port 8765/5678

After this you should be able to view in your web browser the following IP:

http://[aaaa::c30c:0:0:407]/

And see the following:

Neighbors
fe80::c30c:0:0:9e
 
Routes
aaaa::c30c:0:0:9e/128 (via fe80::c30c:0:0:9e)

Keep adding motes and watch your network grow!

You can also ping the motes in your network:

examples/ipv6/rpl-udp$ ping6 aaaa::c30c:0:0:9e
PING aaaa::c30c:0:0:9e(aaaa::c30c:0:0:9e) 56 data bytes
64 bytes from aaaa::c30c:0:0:9e: icmp_seq=34 ttl=63 time=734 ms
64 bytes from aaaa::c30c:0:0:9e: icmp_seq=35 ttl=63 time=3262 ms
64 bytes from aaaa::c30c:0:0:9e: icmp_seq=36 ttl=63 time=2534 ms
64 bytes from aaaa::c30c:0:0:9e: icmp_seq=37 ttl=63 time=3121 ms

Create an ipv6-based webserver with battery and temperature data

Tested with rev. 0fc5ec8 and msp430-gcc-4.4.5

This small example will allow to add a working webserver to your IPv6 network in Contiki, this serves as a starting point to implement more complete applications based on the webserver functionalities.

Important: for this test to work (well, to be more accurate) it is necessary to flash each of your nodes with a known mac or number id (see section above). This guide also assumes that the reader is using the latest Contiki version available, if not please check the installation instructions.

The modified webserver for the Z1 mote is located at /examples/z1/ipv6/z1-websense, the sensors enabled for this test are temperature and battery. Due to the growth of the stack it was necessary to add the "SMALL" flag in the Makefile to shrink the code and minimize ram usage, this enables the following options in /cpu/msp430/Makefile.msp430:

### These flags can reduce the code size and RAM usage with up to 10%
ifdef SMALL
CFLAGS += -ffunction-sections
# CFLAGS += -fdata-sections
LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__
endif # SMALL

To compile and program a mote just execute:

make z1-websense.upload

When the script finish uploading the image to the mote, verify the application is running properly and check the IPv6 address:

/examples/z1/ipv6/z1-websense$ make z1-reset && make login
using saved target 'z1'
make -k -j 20 z1-reset-sequence
using saved target 'z1'
connecting to /dev/ttyUSB0 (115200) [OK]
Rime started with address 193.12.0.0.0.0.0.123
MAC c1:0c:00:00:00:00:00:7b Contiki-2.5-1646-g5c5678e started. Node id is set to 123.
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26
Tentative link-local IPv6 address fe80:0000:0000:0000:c30c:0000:0000:007b
Starting 'Sense Web Demo'

Then go to the border-router (see in section above how to access the border router via web browser) and verify the webserver is in the network:

Neighbors
fe80::c30c:0:0:7b
 
Routes
aaaa::c30c:0:0:7b/128 (via fe80::c30c:0:0:7b)

Consult the webserver by searching for http://[aaaa::c30c:0:0:7b] and see the available readings.

Use collect view to gather data from your network

Work in progress

Tested with rev. 0fc5ec8 and msp430-gcc-4.4.5

Follow the next steps:

  • 1. Go to /examples/ipv6/rpl-collect/
  • 2. Program one mote as sink, the other as sender (assuming the motes are connected in the ttyUSBX ports):
   $ make TARGET=z1 MOTES=/dev/ttyUSB0 udp-sink.upload
   $ make TARGET=z1 MOTES=/dev/ttyUSB1 udp-sender.upload
  • 3. Go to /tools/collect-view and run "ant" to build the collect viewer, you can edit the java files in the /src directory
  • 4. Go to the generated /tools/collect-view/dist and run:
   $ java -jar collect-view-jar /dev/ttyUSB0 (this is the port where the sink should be)
  • 5. In the collect window in Tools menu, select "Run Init script" and in the "Node Control" tab and click on "Start Collect"


Note that the temperature sensor is fully functional, the battery sensor is not linked and always output 0. I have to work on this.

Don't try to reprogram the mote through the collect view window (with the stored collect ihex file).

If you don't find any mote connected (for example when you used the collect-sky example) is because the scripts at /dist/tools are fitted to the sky mote, you can replace those by the corresponding ones in /tools/z1 (motelist-z1 and z1-bsl-nopic), copy these to /dist/tools/ and rename it accordingly.

In the near future I will build a collect-z1 example as the one for sky.

An available tarball with precompiled images of rpl-collect examples and proper scripts for the Z1 mote is available Here



Simulate with Cooja

The Z1 mote is now officially included and supported in Cooja in commit 9251692eed16c5ae041fa9cff68292c0d2edb0a7 (May 31 2012), thanks to Niclas Finne and the amazing SICS developing team, we will start trying this out and contributing with this handy simulation tool.

To start, go to /tools/cooja and run:

$ ant run

It will start compiling and after a few seconds the program window will load.

Before beggining there's a pre-test for cooja motes type in Settings/cooja mote configuration wizard, is not indispensable to work with Z1 motes but handy to test your setup.

If you get an error related to not being able to find "jni.h" check if the $JAVA_HOME path exists, in my case the jni.h file resides in:

/usr/lib/jvm/java-7-openjdk-i386/include

In the Settings/external tool path/COMPILER_ARGS option I had to modify the path as it was pointing the jni.h file location to be in $JAVA_HOME/include/linux.


To try a precompiled example for the Z1 mote do:

File -> Open Simulation -> Browse -> contiki_tests -> z1_helloworld.csc

Then in the simulation control window "Start" the simulation.



You can see the simulated expected output of the serial port in the mote output window:

Rime started with address 1.0
MAC 01:00:00:00:00:00:00:00 Contiki-2.5-release-645-g26d7a8b started. Node id is set to 1.
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26
Starting 'Hello world process'
Hello, world


To create your own simulation scenario go to File -> New Simulation, configure the simulation settings and then add some Z1 motes, in Motes -> Add motes -> Create new mote type -> Z1 mote. In browse window select the source file of any of the available Z1 mote examples, for example:

/opt/contiki/contiki/examples/z1/test-adxl345.c

You will see in the compile commands the proper compilation command to build this app:

make test-adxl345.z1 TARGET=z1

In the Mote interfaces select the desired interfaces to be shown, and click on "Compile", after the compilation process is over click on "Create" and place as many of Z1 motes as you like, then click "Add motes", you should see the motes placed on the simulation grid, and start Simulation... add as many watchers and interfaces as you like!



To learn more about Cooja refer to the following links:


You can also compile and simulate your applications directly with MSPSIM, A Java simulator for the TI msp430 processors developed by SICS, to start testing go to /examples/z1 and compile/run any of the available test programs like the following:

$ make TARGET=z1 test-battery.mspsim

The MSPSIM window will pop-up and the simulation will start:

Testfeed (Contiki OS + 6LoWPAN + RPL + HTTP + JSON)

Once again the SICS developing team have surprised Us with a Cosm (previously known as pachube) feed featuring 3 Z1 mote sending its temperature readings through HTTP and JSON using 6LoWPAN and RPL, the code is now available in Contiki's trunk.



Test REST example

I put together a brief walk-through of how to test REST/CoAP example in Contiki, please follow this step by step.

I tested this with the following setup:

  • Ubuntu 10.04 LTS
  • Contiki v.2.6 (from trunk), rev: c5e9d68
  • MSP430-4.7.x toolchain (get it from TinyProd or Here see:
a-linan@zolertia:~$ msp430-gcc --version
msp430-gcc (GCC) 4.7.0 20120322 (mspgcc dev 20120716)


I just followed the steps from the application's README: "A RESTful server example showing how to use the REST layer to develop server-side applications (at the moment only CoAP is implemented for the REST Engine)."


PRELIMINARIES

  • Make sure rpl-border-router has the same stack and fits into mote memory (use the msp430-47, has better code compression).
  • Disable RDC in border-router project-conf.h (see step above), add the following:
  #undef NETSTACK_CONF_RDC
  #define NETSTACK_CONF_RDC     nullrdc_driver
 $ make TARGET=z1 savetarget
  • Ensure the 3 motes you will be using to test this (border router, client, server) have flashed a MAC/IPv6 address (see HERE), be sure to write down the addresses!
  • Another thing, if you get an error like the following, Go to platform/z1/contiki-conf.h and change UIP_CONF_BUFFER_SIZE to 240:
#error "UIP_CONF_BUFFER_SIZE too small for REST_MAX_CHUNK_SIZE"
make: *** [obj_z1/er-coap-07-engine.o] Error 1


Z1 HOW-TO:

Server:

  1. Go to /examples/er-rest-example/
  2. Save the target (for convenience): make TARGET=z1 savetarget
  3. Connect a mote (check with $ make z1-motelist)
  4. $ make er-example-server.upload && make z1-reset && make login
  5. Annotate the address in the following line: "Tentative link-local IPv6 address fe80:0000:0000:0000:____:____:____:____"
  6. Press Ctrl + C to stop the serialdump, Disconnect the mote and connect another one to be used as client...


Client:

Remember you annotate the server address in step 5? edit er-example-client.c and replace yours in this line:

SERVER_NODE(ipaddr)   uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0xc30c, 0x0000, 0x0000, 0x039c)
  1. $ make er-example-client.upload
  2. Disconnect the mote, connect another one to be used as border-router...


Border-Router:

$ cd ../ipv6/rpl-border-router/
$ make TARGET=z1 savetarget 
$ make border-router.upload && make connect-router

Don't close this window! leave the mote connected, now you will be watching something like this:

SLIP started on ``/dev/ttyUSB0''
opened tun device ``/dev/tun0''
ifconfig tun0 inet `hostname` up
ifconfig tun0 add aaaa::1/64
ifconfig tun0 add fe80::0:0:0:1/64
ifconfig tun0
 
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:127.0.1.1  P-t-P:127.0.1.1  Mask:255.255.255.255
          inet6 addr: fe80::1/64 Scope:Link
          inet6 addr: aaaa::1/64 Scope:Global
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
 
Rime started with address 193.12.0.0.0.0.3.229
MAC c1:0c:00:00:00:00:03:e5 Contiki-2.5-release-681-gc5e9d68 started. Node id is set to 997.
CSMA nullrdc, channel check rate 128 Hz, radio channel 26
Tentative link-local IPv6 address fe80:0000:0000:0000:c30c:0000:0000:03e5
Starting 'Border router process' 'Web server'
Address:aaaa::1 => aaaa:0000:0000:0000
Got configuration message of type P
Setting prefix aaaa::
Server IPv6 addresses:
 aaaa::c30c:0:0:3e5
 fe80::c30c:0:0:3e5


Let's ping the border-router:

a-linan@zolertia:~$ ping6 aaaa:0000:0000:0000:c30c:0000:0000:03e5
PING aaaa:0000:0000:0000:c30c:0000:0000:03e5(aaaa::c30c:0:0:3e5) 56 data bytes
64 bytes from aaaa::c30c:0:0:3e5: icmp_seq=1 ttl=64 time=21.0 ms
64 bytes from aaaa::c30c:0:0:3e5: icmp_seq=2 ttl=64 time=19.8 ms
64 bytes from aaaa::c30c:0:0:3e5: icmp_seq=3 ttl=64 time=22.2 ms
64 bytes from aaaa::c30c:0:0:3e5: icmp_seq=4 ttl=64 time=20.7 ms

Now connect the server mote, ping it too:

a-linan@zolertia:~$ ping6 aaaa:0000:0000:0000:c30c:0000:0000:039c
PING aaaa:0000:0000:0000:c30c:0000:0000:039c(aaaa::c30c:0:0:39c) 56 data bytes
64 bytes from aaaa::c30c:0:0:39c: icmp_seq=1 ttl=63 time=40.3 ms
64 bytes from aaaa::c30c:0:0:39c: icmp_seq=2 ttl=63 time=34.2 ms
64 bytes from aaaa::c30c:0:0:39c: icmp_seq=3 ttl=63 time=35.7 ms
64 bytes from aaaa::c30c:0:0:39c: icmp_seq=4 ttl=63 time=36.9 ms
64 bytes from aaaa::c30c:0:0:39c: icmp_seq=5 ttl=63 time=36.1 ms
64 bytes from aaaa::c30c:0:0:39c: icmp_seq=6 ttl=63 time=35.5 ms

And connect the client mote, assuming it is connected in /dev/ttyUSB2 port:

a-linan@zolertia:~/Desktop/Contiki/contiki/examples/z1$ make login MOTES=/dev/ttyUSB2
../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB2
connecting to /dev/ttyUSB2 (115200) [OK]
Rime started with address 193.12.0.0.0.0.0.158
MAC c1:0c:00:00:00:00:00:9e Contiki-2.5-release-681-gc5e9d68 started. Node id is set to 158.
CSMA nullrdc, channel check rate 128 Hz, radio channel 26
Tentative link-local IPv6 address fe80:0000:0000:0000:c30c:0000:0000:009e
Starting 'COAP Client Example'
Press a button to request .well-known/core
--Requesting .well-known/core--
|</.well-known/core>;ct=40,</hello>;title="Hello world: ?len=0.."|;rt="Text",</tes|t/push>;title="P| demo";obs,</tes|itle="Sub-resour||g|b, POST/PUT m|le="Red LED";rt=|BlockOutOfScope
--Done--

Bro Hint: I just pressed the user button as requested by the test.


Now we can start discovering the resources, Open Firefox and type the server address:

coap://[aaaa::c30c:0000:0000:039c]:5683/

And began by discovering the available resources, Press "DISCOVER" and the page will be populated in the left side:


If you select the "toggle" resource and use POST you can see how the RED led of the server mote will toggle:


If you do the same with the "Hello" resource, the server will answer you back with a neighbourly well-known message:


And finally if you observe the "Sensors -> Button" events by selecting it and clicking "OBSERVE", each time you press the user button an event will be triggered and reported back:


More features

Finally if you go to the er-example-server.c file and enable the following:

#define REST_RES_HELLO 1
#define REST_RES_SEPARATE 1
#define REST_RES_PUSHING 1
#define REST_RES_EVENT 1
#define REST_RES_SUB 1
#define REST_RES_LEDS 1
#define REST_RES_TOGGLE 1
#define REST_RES_BATTERY 1
#define REST_RES_RADIO 1

You can play with more available features.


As commit d5d8de7 the following definitions are missing in z1/platform-conf.h, if not present by the time you try this test please add it yourself:

#define PLATFORM_HAS_BATTERY 1
#define PLATFORM_HAS_RADIO 1


Radio resource

And now to get the current RSSI level on the CC2420 transceiver:

coap://[aaaa::c30c:0000:0000:0098]:5683/sensor/radio?p=rssi


Battery sensor

Same to get the battery readings:

coap://[aaaa::c30c:0000:0000:0098]:5683/sensors/battery

This last case returns the ADC units when the mote is connected to the USB, the actual mv value would be:

V [mV] = (units * 5000)/4096


Leds resource

Let's say you want to turn the green LED ON, in the URL type:

coap://[aaaa::c30c:0000:0000:0098]:5683/actuators/leds?color=g

And then in the payload (the ongoing tab) write:

mode="on"

And press POST or PUT (hover with the mouse over the actuators/leds to see the description and allowed methods).


Test REST (HTTP) example

I put together a brief walk-through of how to test REST/HTTP example in Contiki, please follow this step by step.

I tested this with the following setup:

  • Ubuntu 10.04 LTS
  • Contiki v.2.6 (from trunk), rev: d5d8de7
  • MSP430-4.7.x toolchain (get it from TinyProd or Here see:
a-linan@zolertia:~$ msp430-gcc --version
msp430-gcc (GCC) 4.7.0 20120322 (mspgcc dev 20120716)


I just followed the steps from the application's README.


PRELIMINARIES

  • Make sure rpl-border-router has the same stack and fits into mote memory (use the msp430-47, has better code compression).
  • Disable RDC in border-router project-conf.h (see step above), add the following:
  #undef NETSTACK_CONF_RDC
  #define NETSTACK_CONF_RDC     nullrdc_driver
  • Install curl (apt-get install curl)
  • In /examples/rest-example/Makefile switch to a HTTP build by changing to "WITH_COAP = 0"
  • Optional: Save your target as default target
 $ make TARGET=z1 savetarget
  • Ensure the 2 motes you will be using to test this (border router, http server) have flashed a MAC/IPv6 address (see HERE), be sure to write down the addresses!
  • Another thing, if you get an error like the following, Go to platform/z1/contiki-conf.h and change UIP_CONF_BUFFER_SIZE to 240:
#error "UIP_CONF_BUFFER_SIZE too small for REST_MAX_CHUNK_SIZE"
make: *** [obj_z1/er-coap-07-engine.o] Error 1


Z1 HOW-TO:

Server:

  1. Go to /examples/rest-example/
  2. Save the target (for convenience): make TARGET=z1 savetarget
  3. Connect a mote (check with $ make z1-motelist)
  4. $ make rest-server-example.upload && make z1-reset && make login
  5. Annotate the address in the following line: "Tentative link-local IPv6 address fe80:0000:0000:0000:____:____:____:____"
  6. Press Ctrl + C to stop the serialdump

Border-Router:

$ cd ../ipv6/rpl-border-router/
$ make TARGET=z1 savetarget 
$ make border-router.upload && make connect-router

Don't close this window! leave the mote connected, now you will be watching something like this:

$ make connect-router
using saved target 'z1'
sudo ../../../tools/tunslip6 aaaa::1/64
SLIP started on ``/dev/ttyUSB0''
opened tun device ``/dev/tun0''
ifconfig tun0 inet `hostname` up
ifconfig tun0 add aaaa::1/64
ifconfig tun0 add fe80::0:0:0:1/64
ifconfig tun0
 
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:127.0.1.1  P-t-P:127.0.1.1  Mask:255.255.255.255
          inet6 addr: fe80::1/64 Scope:Link
          inet6 addr: aaaa::1/64 Scope:Global
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
 
*** Address:aaaa::1 => aaaa:0000:0000:0000
Got configuration message of type P
Setting prefix aaaa::
Server IPv6 addresses:
 aaaa::c30c:0:0:0
 fe80::c30c:0:0:0

Ping both motes (the http-server in this example has aaaa::c30c:0:0:97):

$ ping6 aaaa::c30c:0:0:97
PING aaaa::c30c:0:0:97(aaaa::c30c:0:0:97) 56 data bytes
64 bytes from aaaa::c30c:0:0:97: icmp_seq=1 ttl=63 time=41.6 ms
64 bytes from aaaa::c30c:0:0:97: icmp_seq=2 ttl=63 time=44.0 ms
64 bytes from aaaa::c30c:0:0:97: icmp_seq=3 ttl=63 time=42.4 ms
^C
--- aaaa::c30c:0:0:97 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 41.641/42.706/44.023/1.016 ms
$ ping6 aaaa::c30c:0:0:0
PING aaaa::c30c:0:0:0(aaaa::c30c:0:0:0) 56 data bytes
64 bytes from aaaa::c30c:0:0:0: icmp_seq=1 ttl=64 time=21.7 ms
64 bytes from aaaa::c30c:0:0:0: icmp_seq=2 ttl=64 time=23.7 ms
64 bytes from aaaa::c30c:0:0:0: icmp_seq=3 ttl=64 time=22.0 ms
^C
--- aaaa::c30c:0:0:0 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 21.767/22.524/23.709/0.848 ms

Discover the available resources:

$ curl -H "User-Agent: curl" aaaa::c30c:0:0:0097:8080/.well-known/core
</helloworld>;n="HelloWorld",</led>;n="LedControl"

Now let's use curl (http client) to get information from the mote and send commands:

$ curl -H "User-Agent: curl" aaaa::c30c:0:0:0097:8080/helloworld
Hello World!
 
$ curl -H "User-Agent: curl" aaaa::c30c:0:0:0097:8080/led?color=green -d mode=on -i -v
* About to connect() to aaaa::c30c:0:0:0097 port 8080 (#0)
*   Trying aaaa::c30c:0:0:97... connected
* Connected to aaaa::c30c:0:0:0097 (aaaa::c30c:0:0:97) port 8080 (#0)
> POST /led?color=green HTTP/1.1
> Host: aaaa::c30c:0:0:0097:8080
> Accept: */*
> User-Agent: curl
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: Contiki
Server: Contiki
< Connection: close
Connection: close
 
< 
* Closing connection #0
 
 
$ curl -H "User-Agent: curl" aaaa::c30c:0:0:0097:8080/led?color=green -d mode=off -i
HTTP/1.1 200 OK
Server: Contiki
Connection: close


Forward IPv4 to IPv6 with socat

There are many ways to do this, but let's use a simpler option: socat

Consider the following scenario:

file:IPv4v6_socat_example.jpg

For a simple demo it would be enough to listen incoming IPv4 requests and forward it to out IPv6 HTTP server, notice that this is a very constrained scenario and solution (basically 1 to 1 mapping), but for the test is enough. Execute (don't close):

socat TCP4-LISTEN:8080,reuseaddr,fork TCP6:[aaaa::c30c:0:0:0097]:8080

Where:

  • TCP-Listen: Select the port the listener will be stood up on.
  • reuseaddr: Allows other sockets to bind to an address even if parts of it (e.g. the local port) are already in use by socat.
  • fork: After establishing a connection, handles its channel in a child process and keeps the parent process attempting to produce more connections, either by listening or by connecting in a loop

Now from a remote PC (192.168.1.221) I can:

$ curl -H "User-Agent: curl" 192.168.70.220:8080/helloworld
Hello World!
Personal tools
Navigation
MansOS Support
General guides and apps
Assistance