htLib.ubidots module

This module offers clients to send and receive data. This module consumes the Ubidots API, you can find more examples of the data that is sent or received in the following link https://docs.ubidots.com/v1.6/reference/welcome

This tool is still in development so you may encounter some errors or missing methods to perform certain actions. This will improve as needed based on the projects we carry out or based on the orders in the repository.

At this time you can create clients that use the http and tcp protocols.

class htLib.ubidots.HTTPClient(token)

Bases: object

This class offers connections to Ubidots platform using Http procotol.

__init__(token)
Parameters

token (str) – token of your ubidots account

get_from_device()
get_from_variable(device_label: str, variable_label: str)
get_from_variable_by_id(variable_id: str) Tuple[bool, Optional[dict]]

get data of variable based on id

Parameters

variable_id (str) – variable id . You can find it in your ubidots account

Returns

Tuple with 2 items, the first element indicates if there was an error the second element contains a dictionary if there was no error

Return type

tuple

send__to_device(device_label: str, data: dict, block=False)

Sends data to one or more variables on a Device

Parameters
  • device_label (str) – device label. You can find it in yoyur ubidots account

  • data (dict) – dictionary of data {“variable_label1”:1, “variable_label2”: 3}. See more examples in https://docs.ubidots.com/v1.6/reference/send-data-to-a-device

  • block (bool, optional) – If It’s False send data in a Thread, defaults to False

send_to_variable(device_label: str, variable_label: str, data: dict, block=False)

Sends data to a variable on a Device

Parameters
  • device_label (str) – device label. You can find it in your ubidots account

  • variable_label (str) – variable label. You can find it in your ubidots account

  • data (dict) – dictionary of values to variable {“value”:10}. See more examples in https://docs.ubidots.com/v1.6/reference/send-data-to-a-variable

  • block (bool, optional) – If It’s False send data in a Thread, defaults to False

send_to_variable_by_id(variable_id: str, data: dict, block=False)

send to specific variable based on id

Parameters
class htLib.ubidots.TCPClient(token: str)

Bases: object

This class offers connections to Ubidots platform using Http procotol.

__init__(token: str)
Parameters

token (str) – token of your ubidots account

connect()

start the connection

disconnect()

close the connection

rcv_data(variable_label: str) Tuple[bool, Optional[float]]

receive data

Parameters

variable_label (str) – variable label. Check it in your ubidots account

Returns

Tuple with 2 items, the first element indicates if there was an error the second element contains a float value if there was no error

Return type

tuple

send_data(data: dict, variable_label: str, block=False)
Parameters
  • data (dict) – data to will be sended {“variable_label”:value}. See more examples in https://docs.ubidots.com/v1.6/reference/sending-data-2

  • variable_label (str) – Check It in your ubidots account

  • block (bool) – If It’s True send data in Thread, defaults to False

htLib.ubidots.get_client(token: str, client: str) Optional[Union[htLib.ubidots.HTTPClient, htLib.ubidots.TCPClient]]

get a Client

Parameters
  • token (str) – token of your ubidots account

  • client (str) – type of client. Could be tcp, http

Returns

a Client to Ubidots API. If client doesn’t exist return None

Return type

HTTPClient, TCPClient, None