Skip to content

LWM2M Devices with Dynamic IP

Simon edited this page Aug 5, 2024 · 4 revisions

LWM2M specification supports dynamic IP environment use cases like devices behind a NAT.

How to make it works ?

A specification compliant way to support a device which could change its IP address/port is :

  1. Devices should use Queue Mode (device initiated communication).
  2. When devices wake up/come back,
    1. At DTLS level, devices must do a new handshake (full or abbreviated) or use connection-Id.
    2. At LWM2M level, devices should start its communication with an Update request.
  3. When server receives the Update, it will update the registration using the new IP address/port, then it can send pending requests for this devices.

For more details, see LWM2M-v1.1.1@transport§6.5. Queue Mode Operation

What about observe notification ?

This should be OK with Leshan, you should look at LWM2M-Observe#requestnotifications-matching

Is the UPDATE request mandatory ?

Using Queue mode, this is mandatory and this Update request MUST be done before any other communications. If device doesn't do it, its registration will not be updated on Notification or Send requests which could lead to some behavior issue at Leshan side.

My device doesn't send Update on wake-up, what should I do ?

You SHOULD fix your device behavior because it doesn't fully comply the LWM2M specification and so could lead to interoperability issue.

If you think the specification should be modified, you could try to open an issue at : https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues but you should probably read this before : https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/555.

If you can not fix your device (this doesn't smell good), you can mitigate issue by configuring Leshan to update registration on Notification or Send Request. The drawback is that will increase write access to RegistrationStore as each Notification or Send request reception will lead to an extra write access.

For Notification:

Since Leshan v1.1, you can activate a Update Registration On Notification mode (Not recommended).
This mode can be activated via : leshanServerBuilder.setUpdateRegistrationOnNotification(true);

If you don't use DTLS and use Californium provider for CoAP (coap://), you probably need to use a the Relaxed response matching mode too. coapConfig.setString(NetworkConfig.Keys.RESPONSE_MATCHING, "RELAXED");
See LWM2M-Observe#for-udp-without-security

For Send request:

Since Leshan v2.0.0-M14, you can active Update Registration On Send Request mode (Not recommended).
This mode can be activated via : LeshanServerBuilder.setUpdateRegistrationOnSend(true);

Note Update Registration On Send Request only works when using protocol with authentication, e.g. this can not work with coap://.