Tutorial: LWM2M - 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 device.
After that 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]"
Registering with global LWM2M server via NAT64
Let us register with the demo server at Eclipse.
Even through our nodes only run IPv6, our border router has a NAT64 translator, enabling IPv6 over IPv4 access points and to the IPv4 Internet.
The IPv4 address of the Eclipse demo server is 5.39.83.206
.
The NAT64-translated address is [64:ff9b::527:53ce]
.
Try pinging on your node to check NAT64 connectivity:
> ping 64:ff9b::527:53ce
Pinging 64:ff9b::527:53ce
Received ping reply from 64:ff9b::527:53ce, len 4, ttl 126, delay 78 ms
Now set the LWM2M registration address using the NAT64 format:
#define LWM2M_SERVER_ADDRESS "coap://[64:ff9b::527:53ce]"
Compile and flash your node. When you run a successful registration here you should see your device at the URL: http://leshan.eclipse.org
Take note of your Device endpoint, e.g., Contiki-NG-Zolertia4B0014B5EE9A
.
LWM2M with DTLS - Pre-shared keys
DTLS is used to secure the communication with the registration server in LWM2M. Contiki-NG's LWM2M implementation supports using DTLS.
First some small changes in the configuration is needed, add the following to the project-conf.h:
#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 MAKE_WITH_DTLS=1 MAKE_COAP_DTLS_KEYSTORE=MAKE_COAP_DTLS_KEYSTORE_SIMPLE example-ipso-objects.upload
You now need to 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 (default key in hexa is 73656372657450534b
):
Note: if you do not know the endpoint name you can run in non-secure mode first to see the name of the endpoint.
References
Here are some references to used standards and LWM2M servers.