aellwein / lwm2mclient

LWM2M client written in Python 3
MIT License
13 stars 12 forks source link

lwm2mclient

A customizable LWM2M client written in Python 3.

Installation

Prerequisite: Download and install Python 3.6+. Preferred way of installation is using virtualenv.

Usage

Running The Client

If you didn't previously, activate virtualenv for your shell. Use ./client.py command to connect LWM2M server listening on udp://localhost:5683 (for instance, a Leshan server).

Note for Windows/Mac users:

Because of the underlying transport implementation on Windows/Mac, see aiocoap FAQ for more details, the LwM2M client needs the --address argument to be set to some specific IP address on your system, the default IP address "::" would not work here.

See also

./client.py --help

for all options.

Client Data Model

The data for LWM2M objects hold by the client is represented in the file data.json. The data model for well-defined LWM2M objects (e.g. Device object) must match the object data definition specified in lwm2m-object-definitions.json. For custom objects, both files must be adjusted.

Execute Operations

Resources which provide an execute operation, are specified via string in data.json. The string name is evaluated to a method name, which should be contained in handlers.py. The signature for such a handler is

      def method_name(*args, **kwargs):
         ...

The positional args arguments are not used. Provided arguments such as model, path, payload and content_format are contained in the kwargs dictionary. See existing handlers for example.

Observe Operations

Resources which support Observe operations, must also be defined in handlers.py. The signature of a handler for observe on object/instance/resource follows a convention:

def observe_{object_id}_{instance_id}_{resource_id}(*args, **kwargs):
   ...

The positional args arguments are not used. Provided arguments such as notifier, cancel, model, path, payload and content_format are contained in the kwargs dictionary.
A notifier argument is a function, which triggers a client-initiated notification and may be, e.g. called periodically.
A cancel argument can be used in order to cancel an existing observation. See observe_3_0_13() example in handlers.py on how to trigger a periodic observation.

License

This project is licensed under the terms of MIT License.

ToDo