Python real-time SDK
iotflows python module https://pypi.org/project/iotflows/
IoTFlows Open Source Python WebSocket SDK.
IoTFlows python module https://pypi.org/project/iotflows/
With this tool you can:
  1. 1.
    Publish secure real-time data streams.
  2. 2.
    Subscribe to the data streams and access real-time data on your web/mobile/IoT apps.
  3. 3.
    Publish alerts to the alert channels with a defined severity level. Subscribers will get notified in the form of SMS/Email/Push.
  4. 4.
    Define cloud actions that can be called from other IoT devices/web applications.

Installation

Use pip3 to install the IotTFows python module:

Prerequisite

1
sudo pip3 install pathlib2
Copied!

IoTFlows Module

1
sudo pip3 install iotflows
Copied!
Note: only Python3 is supported for this module.

Usage

Initialization

This function will create and initialize an IoTFlows instance.
1
import iotflows.realtime as iotflowsRT
2
IoTFlows = iotflowsRT.init('API_KEY_USERNAME', 'API_KEY_PASSWORD')
Copied!
Make sure to change API_KEY_USERNAME and API_KEY_PASSWORD with the proper credentials obtained from IoTFlows console. These credentials can be either one of these options:
  1. 1.
    A Device API Key that has permission to interact with the resources available in its project, or
  2. 2.
    An Organization IoT API Key that can have read-only or read/write permissions to the entire organization resources
  3. 3.
    A User Client that is authorized to interact with the permitted resources of the user. This option is most useful when you need to build a web or mobile app. For this option, you need to register your Application in IoTFlows and authenticate users using OAuth2. With the obtained JWT, you can perform a Basic authentication HTTP request to generate a User Client.

Publish data stream

To publish a real-time data stream, you need to pass these parameters in a json object:
  • data_stream_uuid: the uuid of the data stream
  • data: the data to be published to the data stream
Read more:
Example:
1
IoTFlows.publish(
2
data_stream_uuid='ds_xxxxxxxxxxxxxxxxxxxxxxx',
3
data='Hello World!')
Copied!

Subscribe to data stream

To listen to real-time data streams that are published, you need to define the following parameters in a json object:
  • data_stream_uuid: data stream uuid
  • qos (optional): quality of service 0, 1, or 2 (0: At most once, 1: At least once, 2: Exactly once)
  • callback: handler function to be called when data received
Example:
1
def handlerFunction(topic, payload):
2
print('received new payload!!!')
3
print(payload)
4
5
IoTFlows.subscribe(
6
data_stream_uuid = 'ds_xxxxxxxxxxxxxxxxxxxxxxx',
7
qos = 2,
8
callback = handlerFunction)
Copied!

Publish an alert

To publish an alert, you need to pass these parameters in a json object:
  • alert_channel_uuid: the uuid of the alert channel
  • severity_level: the severity level of the alert. It can be MAJOR, MINOR or INFORMATIVE
  • subject: the subject of the alert
  • description: the description/message of the alert
Read more:
Example:
1
IoTFlows.alert(
2
alert_channel_uuid = 'ac_xxxxxxxxxxxxxxxxxxxxxxxx',
3
severity_level = 'MINOR',
4
subject = 'Water Leak',
5
description = 'Water leackage detected in Site A.')
Copied!

Define a cloud action

To define a cloud action that can be called from other IoT/web applications, you need to define the following parameters in a json object:
  • action_uuid action uuid
  • qos (optional): quality of service 0, 1, or 2 (0: At most once, 1: At least once, 2: Exactly once)
  • callback: handler function to be called when action gets executed
Read more:
Example:
1
def controlPump(topic, payload):
2
print('received new command!')
3
print(payload)
4
5
IoTFlows.defineAction(
6
action_uuid = 'da_xxxxxxxxxxxxxxxxxxxxxxxxx',
7
qos = 2,
8
callback = controlPump)
Copied!

Call/Execute a cloud action

To publish an alert, you need to pass these parameters in a json object:
  • action_uuid: the uuid of the action
  • payload: the payload to be published to the action
Example:
1
IoTFlows.callAction(
2
action_uuid='da_xxxxxxxxxxxxxxxxxxxxxxxxx',
3
data='Turn on!')
Copied!
Last modified 2mo ago