Tutorial: LWM2M and IPSO Objects
To make an application with LWM2M and IPSO Objects functionality you can start from the example:
Build this example for instance on the TI Sensortag, as follows:
$ make TARGET=srf06-cc26xx BOARD=sensortag/cc2650 example-ipso-objects
Then, program your device with the firmware (see documentation of the platform you are using).
After booting, your node will register with the default LWM2M server address:
To set a different address, define
LWM2M_SERVER_ADDRESS in the
#define LWM2M_SERVER_ADDRESS "coap://[fd00::1]"
In order to get anything registered you will need to setup a 6LoWPAN network with a border-router on an prefix and interface address such as
fd00::1/64 (see tutorial:rpl-br).
Then also make sure that your LWM2M server is started and is listening on this interface (the tun interface corresponding to the 6LoWPAN network).
Another option is to set up a globally routable IPv6 network so that you can register with any IPv6 enabled LWM2M server.
To setup a Leshan LWM2M server on the computer that runs the border router, try this:
$ wget https://hudson.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar $ java -jar ./leshan-server-demo.jar
To access the demo server go to http://localhost:8080 and you should see the registration page of the Leshan server. If everything is set up correctly, your device should show up on the Leshan server's device list.
Registering with global LWM2M server via NAT64
If you like to register with the demo server at Eclipse you can change the registration address in the code to the NAT64 format. Note: this requires your 6LoWPAN border router to have a NAT64 running on the same network (so that the IPv6 address is converted into an IPv4 address). You can use the Jool NAT64 for that (see doc:ip64).
#define LWM2M_SERVER_ADDRESS "coap://[64:ff9b::527:53ce]"
When you run a successful registration here you should see your device at the URL: http://leshan.eclipse.org
LWM2M with DTLS (pre-shared keys)
Contiki-NG's LWM2M implementation supports DTLS, to secure the communication with the registration server in LWM2M. First some small changes in the configuration are needed. Add the following to the project-conf.h:
#define LWM2M_SERVER_ADDRESS "coaps://[fd00::1]" #define COAP_DTLS_PSK_DEFAULT_IDENTITY "Client_identity" #define COAP_DTLS_PSK_DEFAULT_KEY "secretPSK"
This will change the registration to secure mode as it is CoAPs in the URI and identity and pre-shared key for DTLS is defined. The key needs to be entered in Leshan as hexadecimal - "secretPSK" is "73656372657450534b" in hex.
Then do a distclean:
$ make distclean
$ make TARGET=zoul BOARD=firefly-reva MAKE_WITH_DTLS=1 MAKE_COAP_DTLS_KEYSTORE=MAKE_COAP_DTLS_KEYSTORE_SIMPLE example-ipso-objects.upload
If you did not already setup a Leshan server and a 6LoWPAN border-router, do that (description above) and configure the same security Identity and keys in the Leshan server. Remember to take note of the registration endpoint so that you can get the correct name on that in the security configuration in Leshan. If you are using a Zolertia firefly it might look like the following:
Note: if you do not know the endpoint name you can run in non-secure mode first to see the name of the endpoint.
This tutorial describe how to setup a LWM2M client registering to a server with all security keys (or none) configured beforehand. LWM2M also offers a bootstrap option where the node first contacts a local server, and from there, obtain the server to actually register with. When bootstrapping the bootstrap server can also set the security keys that should be used for the other server connection. To enable bootstrapping in the Contiki-NG LWM2M client, set the following flag:
#define REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER 1
Here are some references to used standards and LWM2M servers.