IoTFlows Open Source Python WebSocket SDK.
Project description
iotflows python module
IoTFlows Open Source Python WebSocket SDK.
With this tool you can:
- Publish secure real-time data streams.
- Subscribe to the data streams and access real-time data on your web/mobile/IoT apps.
- Publish alerts to the alert channels with a defined severity level. Subscribers will get notified in the form of SMS/Email/Push.
- Define cloud actions that can be called from other IoT devices/web applications.
Installation
Use pip3
to install the iotflows python module:
Prerequisite
sudo pip3 install pathlib2
IoTFlows Module
sudo pip3 install iotflows
Note: only Python3 is supported for this module.
Usage
Initialization
This function will create and initialize an IoTFlows instance.
import iotflows.realtime as iotflowsRT
IoTFlows = iotflowsRT.init('CLIENT_ID', 'CLIENT_SECRET')
Make sure to change CLIENT_ID
and CLIENT_SECRET
with the proper credentials obtained from IoTFlows console.
These credentials can be either one of these options:
- A Device Client that has permission to interact with the resources available in its project, or
- An Organization IoT API KEY that can have read-only or read/write permissions to the entire organization resources
- 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:
IoTFlows.publish(
data_stream_uuid='ds_xxxxxxxxxxxxxxxxxxxxxxx',
data='Hello World!')
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:
def handlerFunction(topic, payload):
print('received new payload!!!')
print(payload)
IoTFlows.subscribe(
data_stream_uuid = 'ds_xxxxxxxxxxxxxxxxxxxxxxx',
qos = 2,
callback = handlerFunction)
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:
IoTFlows.alert(
alert_channel_uuid = 'ac_xxxxxxxxxxxxxxxxxxxxxxxx',
severity_level = 'MINOR',
subject = 'Water Leak',
description = 'Water leackage detected in Site A.')
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:
def controlPump(topic, payload):
print('received new command!')
print(payload)
IoTFlows.defineAction(
action_uuid = 'da_xxxxxxxxxxxxxxxxxxxxxxxxx',
qos = 2,
callback = controlPump)
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:
IoTFlows.callAction(
action_uuid='da_xxxxxxxxxxxxxxxxxxxxxxxxx',
data='Turn on!')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file iotflows-1.1.12.tar.gz
.
File metadata
- Download URL: iotflows-1.1.12.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac85bdf09bd33480fb6997c522c0c959860cb441ca75cd4b057c64536c01705f |
|
MD5 | 0c3700ad3aced28e76c0e79086bfc721 |
|
BLAKE2b-256 | 19a00356e770f06d413d1c12b1e71b7dad90b277a835aa4aa94f9a2d8cbcc8e9 |