OKdo IoT Library¶
The Zerynth OKdo IoT Library can be used to ease the connection to the OKdo IoT Cloud.
It makes your device act as an OKdo IoT Device which can be created and provisioned on the OKdo IoT Cloud dashboard.
The device always send and receive data in the JSON format.
Check out the examples for a jump start.
The Device class¶
-
class
Device
(device_id, device_token, client)¶ Create a Device instance representing an OKdo device.
The device is provisioned by the
device_id
anddevice_token
, obtained from the OKdo dashboard upon the creation of a new device. theclient
parameter is a class that provides the implementation of the low level details for the connection. It can be one ofMqttClient
in themqtt_client
module, orHttpClient
in thehttp_client
module.
-
connect
()¶ Setup a connection to the OKdo Cloud. It can raise an exception in case of error.
-
run
()¶ Starts the device by executing the underlying client. It can start a new thread depending on the type of client (Mqtt vs Http)
-
publish_asset
(asset_name, value)¶ Modify a device asset state. After a successful execution, the new state of the device asset
asset_name
will be set tovalue
.Return the message sent to the OKdo Cloud, or
None
if the message cannot be sent.
-
publish_state
(state)¶ Modify a device state. After a successful execution, the new state of the device will be set to the values contained in
state
.state
is a dict where each key is the name of an asset and each value the desired state.Return the message sent to the OKdo Cloud, or
None
if the message cannot be sent.
-
watch_command
(asset_name, callback)¶ Start listening for asset command on the device asset identified by
asset_name
. When a new asset command arrives, the functioncallback
is executed receiving as arguments the asset name, the new value and the previous value (or None if it is the first update). Incoming values are checked against the last received timestamp in order to avoid triggering the callback for Modify a device state. After a successful execution, the new state of the device will be set to the values contained instate
.state
is a dict where each key is the name of an asset and each value the desired state.Return the message sent to the OKdo Cloud, or
None
if the message cannot be sent.