ConsentiumThings Python API
Overview
ConsentiumThings is a user-friendly Python API that simplifies sending and receiving data between your devices and Consentium Cloud. It provides an intuitive interface, making it easy for developers to connect their IoT devices to Consentium Cloud for seamless data communication.
Installation
First, install the ConsentiumThings API using pip
:
Getting Started
1. Import the ConsentiumThings Library
You’ll need to import the library before using it in your Python script:
2. Initialize ConsentiumThings
To get started, initialize the API with your board key. This key is provided by Consentium Cloud to identify your specific IoT device.
Sending Data
Steps to Send Data:
Begin a Send Operation: Use your send key to initialize the sending process.
Send Data: Pass the data and related information using the
send_data()
method.
Receiving Data
Steps to Receive Data:
Begin a Receive Operation: Initialize the receive operation with your receive key.
Receive Data: Call
receive_data()
to retrieve the information sent to your board.
To receive only the most recent data, add the
recent=True
flag:
API Methods
Here’s a quick breakdown of all available methods:
1. consentiumthings(board_key)
consentiumthings(board_key)
This initializes the ConsentiumThings instance.
Parameter:
board_key
(str): The unique key that identifies your board.
2. begin_send(send_key)
begin_send(send_key)
This sets up the send operation.
Parameter:
send_key
(str): The unique key that allows your board to send data to Consentium Cloud.
3. send_data(data, info_list)
send_data(data, info_list)
This sends data and its corresponding labels to Consentium Cloud.
Parameters:
data
(list): A list of data values (e.g., sensor readings).info_list
(list): A list of labels or information for the data (e.g., type of sensor).
4. begin_receive(receive_key, recent=False)
begin_receive(receive_key, recent=False)
This sets up the receive operation.
Parameters:
receive_key
(str): The unique key that allows your board to receive data from Consentium Cloud.recent
(bool, optional): IfTrue
, fetches only the most recent data. Default isFalse
.
5. receive_data()
receive_data()
This retrieves the data from Consentium Cloud after calling begin_receive()
.
Returns:
A list of data values received from the cloud.
Complete Example
Here’s a full example to showcase how easy it is to send and receive data using ConsentiumThings: