The Zerynth Device Manager (ZDM) Library contains many different commands that allows you to connect your devices to the ZDM. You can use ZDM lib to send data from your devices and to let them receive your remote commands (jobs).
To learn how to be able to use it and call ZDM methods, see the ZDM getting started doc.
The Credentials class¶
Creates a Credentials instance that loads the provisioning information from the appropriate location. Provisioning information is saved in the :samp:
zdevice.json file contained in the Zerynth project folder. Based on its content, the Credentials class is capable of loading or creating all the necessary pieces of information:
device_idthe unique identifier of the device in the ZDM
credential_typethe type of credentials to use (i.e. cloud token, device token, certificates, etc...)
device_secret, secret key. If empty, the secure element is used as key storage
endpoint, the mqtt broker address
ca, the ZDM root certificate
The Config class¶
Creates a Config instance that set parameters for the connection to the MQTT broker. In particular, the following parameters are available:
keepalivethe MQTT keep alive timeout, in seconds
cycle_timeouthow long to block on the socket waiting for broker input, in milliseconds
command_timeout, how long to wait for a connect/disconnect command to finish, in milliseconds
clean_session, use MQTT clean session flag
qos_publish, the quality of service when publishing to the MQTT broker
qos_subscribe, the quality of service when subscribing to the MQTT broker
The Device class¶
class Device(cred=None, cfg=None, jobs_dict=None, condition_tags=, on_timestamp=None, on_open_conditions=None, fota_callback=None, time_function=default_time_func)
Creates a Device instance with uid
device_id. All other parameters are optional and have default values.
jobs_dictis the dictionary that defines the device's available jobs
condition_tagsis a list of strings defining the conditions tags used by the device (default ).
on_timestamp, is a callback function called when timestamp is received after requesting current time to the ZDM (default None).
on_open_conditions, is a callback function that is called when the list of open conditions is received (default None).
fota_callback, is a function accepting one ore more arguments that will be called at different steps of the FOTA process.
time_function, is a synchronous function that returns the time. Default is retrieving the time through a ntp server.
Connect to the ZDM with the parameters and credentials specified in the constructor.
Upon successful connection, subscribe to the required ZDM topics for jobs.
Upon successful subscription, request current device status from the ZDM.
Return the result code of MQTT connection (0 for ok).
True if the device is connected to the ZDM,
Create and return a new condition.
condition_tagthe tag of the new condition. For the condition to be created correctly, the condition tag must be presend in the
condition_tagsparameter of the class constructor.
Request the timestamp to the ZDM. When the timestamp is received, the callback
on_timestamp is called.
Request all the open conditions of the device not yet closed.
When the open conditions are received, the callback on_open_conditions is called.
class Condition(client, tag)
Creates a Condition on a tag.
clientis the object ZDMClient object used to open and close the condition.
tagis the tag associated with the condition.
Open a condition.
payloadis a dictionary containing custom data to associated with the open operation.
startis a time (RFC3339) used to set the opening time. If None is automatically set with the current time.
Close a condition.
payloadis a dictionary containing custom data to associated with the close operation.
finishis a time (RFC3339) used to set the closing time. If None is automatically set with the current time.
Reset the condition by generating a new id.
Return True if the condition is open. False otherwise.
Return the payload of the condition when it was opened.
Return the payload of the condition when it was closed.
Return the condition unique identifier.
Return the closing time.
Return the opening time.