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

Leshan: Add registration handler interface #34

Merged
merged 12 commits into from
Jul 4, 2024

Conversation

jonas-rem
Copy link
Member

@jonas-rem jonas-rem commented May 30, 2024

Status: WIP

Django has to be informed of the registration status of endpoints. In Leshan there are callbacks that contain all relevant information such as 'lastUpdated', 'registered'. This information will be send to the matching Django ReST API.

  • Clean up, make Log Level configurable
    - [ ] Define a better ReST API with Django-Rest-Framework (DRF)
  • Send registration information to new Django ReST API
  • Define Object/Resource Ids (not defined in standard) to store historical endpoint events, that is linked to an endpoint. That way no new tables are required.
  • Document the Django ReST APIs (automatically if possible)
  • Split singleResource, compositeResource to different ReST API Endpoints
  • Write tests for Django (de)serializer
  • Document: Change Log Level for Leshan, custom device registration resource

@jonas-rem jonas-rem self-assigned this May 30, 2024
@jonas-rem jonas-rem changed the title Leshan: Add registration handler interface to Django Leshan: Add registration handler interface May 30, 2024
@jonas-rem jonas-rem force-pushed the WIP/jonas-rem/leshan_registration_handler branch 2 times, most recently from 354d218 to 93ce8ee Compare June 5, 2024 13:25
@jonas-rem
Copy link
Member Author

This PR also adds an automatic ReST API documentation, based on redoc and OpenAPI v3 to the Sphinx documentation. The information is directly generated from the validation code in the Django Rest Framework Serializer. That way it makes sure that documentation and implementation are always in sync.

image

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Make logging for the leshan lwm2m server easier to configure in
file-level. Add the logback dependency and a logback.xml configuration
file.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Try to make the code more readable by renaming logger into log and make
the lines shorter. In addition some log levels send too much messages.
Those messages are now configured as debug or trace to switch them off
easier.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Endpoint events (registered, updated, unregistered) are send to django
via LwM2M user defined resources (10240/0/0|1|2). This is allows to use
the existing database model in Django.

Build json data with jackson json library instead of manually.

Migrate to new API (leshan_api/resource).

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Add new initial data that includes endpoint registration, update and
deregistration.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
- Adapt serializer to new format

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
The django extension drf_spectacular allows to generate OpenAPI schema.
Via redoc, this schema can be rendered into a detailed html api
documentation. This api documentation is referenced by Sphinx to be
available on the GitHub pages documentation.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Divide singleResource and compositeResource Serializers so that
individual ReST Endpoints are responsible. This makes the
deserialization as well as the documentation easier to read.

There are now two resources:

1. /leshan_api/resource/composite
1. /leshan_api/resource/single

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Switch to the new rest endpoints for single and composite resources.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
- rename device to endpoint consistently
- Add a status field, that allows to filter registered endpoints. Once
  Endpoints get registered, this bit is set to True on unregistration
  set to False.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
The data type is set from Leshan and converting Opaque types is rare and
never required for float and int values. The only conversion that is
happening is to convert from LwM2M Types to database types (str, int,
float).

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Single and composite tests.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
@Kappuccino111 Kappuccino111 force-pushed the WIP/jonas-rem/leshan_registration_handler branch from d1ff295 to eddf65f Compare July 4, 2024 13:07
Copy link
Collaborator

@Kappuccino111 Kappuccino111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonas-rem what exactly do we mean by Django has to be informed of the registration status of endpoints.? Like is this only when a new client is added ? Because once we have a new client registered , then there will be only certain endpoints that we would need to monitor.

@Kappuccino111
Copy link
Collaborator

@jonas-rem could you please explain the difference between simple and composite resources ?

@Kappuccino111
Copy link
Collaborator

I like the idea of automatically generating API Documentation. That seems to be a very good addition and would help us keep track of the APIs and the changes in them as well.

@jonas-rem
Copy link
Member Author

@jonas-rem what exactly do we mean by Django has to be informed of the registration status of endpoints.? Like is this only when a new client is added ? Because once we have a new client registered , then there will be only certain endpoints that we would need to monitor.

LwM2M maintains registrations of endpoints. As long as an endpoint updates its registration within the allowed time, the registration remains active. If the endpoint reports for an update too late, the endpoint will be deregistered from Leshan. It has to re-register as a consequence. The database should keep track of the past and current registration efforts and status. Therefore registrations, registration updates and deregistrations are send as a custom LwM2M Object.

@jonas-rem
Copy link
Member Author

I will merge this PR and update the documentation in a new PR.

@jonas-rem jonas-rem merged commit e1ba086 into main Jul 4, 2024
1 of 2 checks passed
@jonas-rem jonas-rem deleted the WIP/jonas-rem/leshan_registration_handler branch July 4, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants