Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle SEND messages from a device whose IP may change #1544

Closed
AntonioPerezBazuelo opened this issue Nov 24, 2023 · 7 comments
Closed
Labels
question Any question about leshan

Comments

@AntonioPerezBazuelo
Copy link

Question

Hello everyone,

We are using a leshan server demo connected to a redis store database, currently the M13 release. The devices we are supporting can change it's IP address and we are using as a workaround the already existing solution to update the registration on every observation so this issue is resolved.

However, the device doesn't send an UPDATE message periodically and performs the send according to the frequency time that we set, but as the IP of the device may change, when the device publishes the message we can't detect it because the SendHandler tries to verify the message from an incoming IP address and not from the REGID (as it is done inside the ObservationHandler). Is it possible to handle the incoming SEND messages using this field? I'm really sorry if the question sounds a bit newbie, but I'm kind of a beginner in this area and as far as my knowledge and the tests I've done, I can't see how I can change the code to support this (or even if it's possible).

Thank you very much.

@AntonioPerezBazuelo AntonioPerezBazuelo added the question Any question about leshan label Nov 24, 2023
@sbernard31
Copy link
Contributor

Firstly, if you device is an IP changing environment it should use Queue Mode. After its absent/sleeping period it should start the communication by an UPDATE. See for more details : https://github.com/eclipse-leshan/leshan/wiki/LWM2M-Devices-with-Dynamic-IP

If it does not behave like this. It doesn't respect the specification and so you will face some interoperability issue.

Now if you don't care about interoperability (which is generally not a good idea)
You can try :

  • LeshanServerBuilder.setUpdateRegistrationOnNotification(boolean) : you already used it, if I understand you.
  • LeshanServerBuilder.setUpdateRegistrationOnSend(boolean) : works like above ☝️ for send and so should solve your issue.

Let me know if this works for you.

About reusing demo :

@AntonioPerezBazuelo
Copy link
Author

Hi sbernard31, thanks for your reply.

I've tried the second approach and when I try to simulate it (using the leshan-client-demo but changing the update to every 2 hours) the server returns a 400 (no registration found).

The only changes I've made to the actual code is that inside the leshanServerDemo I've added both builder.setUpdateRegistrationOnSend(true) and builder.setUpdateRegistrationOnNotification(true).

To simulate a device changing its IP address, I've done the following

  • Run leshar server
  • Create a device with leshan client (I modified it to take a long time to do an UPDATE/REGISTRATION)
  • Simulate sending a message (send current value /3303/0/5700)
    -After receiving a message (all OK), I go into redis and modify the port field.
    -Simulate a send message again.

Also this behaviour happens with the real device, and the server returns the same (BAD_REQUEST(400)]: no registration found.

Thank you very much

@sbernard31
Copy link
Contributor

I'm not sure I get you.

But I understand that when you are using : setUpdateRegistrationOnSend(true), you get a : BAD_REQUEST(400): no registration found.

My guess you are not using CoAP over DTLS but just CoAP. In that case there is no way for the server to know from who came the Send Request.

In other words, this works only with protocol with authentication like coaps.
(I should update the javadoc 🤔)

@AntonioPerezBazuelo
Copy link
Author

Thank you very very much sbernard31, now I totally understand what is happening. We'll try to see if we can start using Coap over DTLS.

@sbernard31
Copy link
Contributor

You're welcome 😉.

I reopen this issue, just to remember to update javadoc and maybe wiki page.

@sbernard31
Copy link
Contributor

I adapt the wiki page about it : https://github.com/eclipse-leshan/leshan/wiki/LWM2M-Devices-with-Dynamic-IP

and also adapt javadoc in commit 4614ebb.

@sbernard31
Copy link
Contributor

We can close this issue now 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Any question about leshan
Projects
None yet
Development

No branches or pull requests

2 participants