From 9c7bb44e4ba85939bd2f2c6ee8c21b453fc23834 Mon Sep 17 00:00:00 2001 From: Jonas Remmert Date: Tue, 14 May 2024 15:06:59 +0200 Subject: [PATCH] doc: add documentation for database model Explain the database model, how it is related to generic LwM2M resources. Furthermore, explain how an application can create custom aggregation events. Signed-off-by: Jonas Remmert --- doc/source/documentation.rst | 55 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/doc/source/documentation.rst b/doc/source/documentation.rst index b94e0ba4..876c73d2 100644 --- a/doc/source/documentation.rst +++ b/doc/source/documentation.rst @@ -84,20 +84,63 @@ following command: OK Destroying test database for alias 'default'... -Entity Relationship Diagram (ERD) -................................. +Database Model +~~~~~~~~~~~~~~ + +The database model is the core of the Django server. It aims to store +information according to the LwM2M resource model. The advantage is that data +can be stored in a generic way and the server can be extended with new +resources without changing the database schema. + +The server application logic only has to handle higher level events. Those +events are situations where multiple resources are associated (e.g. +Temperature, Pressure, Humidity, Acceleration). Those multiple resources are +linked in the event, together with a timestamp. The event itself is represented +by the database model in a generic way, several custom event types can be +created by the application logic. +>>>>>>> 3ccaacc (doc: add documentation for database model) An Entity Relationship Diagram (ERD) is a visual representation of the database -schema. It is be automatically generated from the Django models. - -``sensordata`` is the Django app that contains the application logic. +schema. It is automatically generated from the Django models. ``sensordata`` is +the Django app that contains the application logic. .. figure:: images/erd.svg Entity Relationship Diagram generated from Django models +**Device:** Represents IoT devices using the LwM2M protocol in the network, +identifiable by a universally unique ID alongside a human-readable name. + +**ResourceType:** Defines resource data points comprehensively, annotating each +with a unique object-resource ID combination, a descriptive name, and +specifying the expected data type. + +**Resource:** Captures individual data values from IoT devices, annotated with +timestamps, applicable data types, and linked to both the device and resource +type for which the data pertains. + +**Event:** Serves as a collection point for significant occurrences reported by +devices, including composite events defined by enclosing object IDs. The server +application logic has to generate events based on matching timestamps or +received composite notifications from devices. Although individual resources +within an event may have different timestamps, the event itself encapsulates a +single timestamp. + +**EventResource:** Acts as a junction table forming a many-to-many relationship +between events and their constituent resources, enabling flexible association +without direct modification to the core events or resources tables. + +**DeviceOperation:** Represents actionable commands or processes targeted at +devices, tracking the operation type, status, and scheduling through +timestamps, also detailing the transmission attempts and last action. + +**Firmware:** Stores metadata about firmware binaries that are available for +devices to download and install. Each record includes a version identifier, the +name of the file, a URL from where the device can retrieve the firmware, and +timestamps for tracking when each firmware record was created and last updated. + Leshan LwM2M ------------- +............ For testing the Lwm2m server can run locally, without the need of a docker container: