A customizable LWM2M client written in Python 3.
- Prerequisite: Download and install Python 3.5+.
- run
python3 setup.py install
(for system-wide installation) or python3 setup.py install --user
(for user-local installation).
Use python3 leshan_client.py
command to connect to Leshan public LWM2M server
(Make sure to create a secure client with PSK here first Leshan
also edit leshan_client.py to match your configured client. Remember PSK is in ASCII, but Leshan uses hex!).
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.
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.
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.
Please observe that Leshan uses Passive Observe Cancel, which is currently not supported by aiocoap/this client. See more information here: https://tools.ietf.org/html/rfc7641#section-3.6
This project is licensed under the terms of MIT License.
- implement TLV encoding
- implement Execute (via handlers)
- implement Observe (via handlers)
- implement Write
- implement Cancel Observation (when this issue is resolved)
- improve data definition validation
- extend with REST API (for instrumenting it using 3rd party software)
- provide Dockerfile
- add DTLS support
- tests, docs & stuff
- fulfill SCRs from OMA (s. Tech Spec)