Tutorial: LWM2M and IPSO Objects - simonduq/contiki-ng GitHub Wiki

To make an application with LWM2M and IPSO Objects functionality you can start from the example: examples/lwm2m-ipso-objects/example-ipso-objects.c. Build this example and program your Firefly node:

$ make example-ipso-objects.upload MOTE=<your-port>

After booting, your node will register with the default LWM2M server address: fd00::1. To set a different address, define LWM2M_SERVER_ADDRESS in the project-conf.h file:

#define LWM2M_SERVER_ADDRESS "coap://[fd00::1]"

LWM2M offers a bootstrap option where the node first contacts a hardcoded server, and from there, obtain the server to actually register with. To enable bootstrapping, set the following flag:

#define REGISTER_WITH_LWM2M_BOOTSTRAP_SERVER 1

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.

Then do a distclean:

$ make distclean

Followed by:

$ 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:

Security configuration.

Note: if you do not know the endpoint name you can run in non-secure mode first to see the name of the endpoint. The security key in hex: 73656372657450534b.

References

Here are some references to used standards and LWM2M servers.

⚠️ **GitHub.com Fallback** ⚠️