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:

pip install consentiumthings

Getting Started

1. Import the ConsentiumThings Library

You’ll need to import the library before using it in your Python script:

from consentiumthings import consentiumthings

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.

ct = consentiumthings("your_board_key")

Sending Data

Steps to Send Data:

  1. Begin a Send Operation: Use your send key to initialize the sending process.

  2. Send Data: Pass the data and related information using the send_data() method.

# Initialize the send operation with your send key
ct.begin_send("your_send_key")

# Send data along with information about the data
data = [1, 2, 3, 4]  # Example: sensor readings
info = ['temp', 'humidity', 'pressure', 'light']  # Labels for the data
ct.send_data(data, info)

Receiving Data

Steps to Receive Data:

  1. Begin a Receive Operation: Initialize the receive operation with your receive key.

  2. Receive Data: Call receive_data() to retrieve the information sent to your board.

# Initialize the receive operation with your receive key
ct.begin_receive("your_receive_key")

# Retrieve the data from Consentium Cloud
received_data = ct.receive_data()
print(received_data)
  • To receive only the most recent data, add the recent=True flag:

ct.begin_receive("your_receive_key", recent=True)

API Methods

Here’s a quick breakdown of all available methods:

1. consentiumthings(board_key)

This initializes the ConsentiumThings instance.

  • Parameter:

    • board_key (str): The unique key that identifies your board.

2. 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)

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)

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): If True, fetches only the most recent data. Default is False.

5. 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:

from consentiumthings import consentiumthings

# Initialize the API with your board key
ct = consentiumthings("your_board_key")

# ---- Sending Data ----
ct.begin_send("your_send_key")

# Example: Sending sensor data
data = [25.5, 60, 1013, 300]  # Temp, Humidity, Pressure, Light Intensity
info = ['temperature', 'humidity', 'pressure', 'light']
ct.send_data(data, info)

# ---- Receiving Data ----
ct.begin_receive("your_receive_key")

# Get the data and print it
received_data = ct.receive_data()
print("Received Data:", received_data)