IoTFlows
  • Welcome to IoTFlows Docs
  • IoTFlows
  • Console
  • REST API
  • Device Management & Secure Remote Access
    • 1. Connect a device to the cloud or create a virtual device
    • 2. SSH to your device over the internet
    • 3. Transfer files to your device over the internet
    • 4. Remotely access Node-RED on your device
    • 5. Create public links for local web-apps
  • Real-Time Data Streams, Alerts, and Actions
    • Create a Device API Key
    • Publish and subscribe to real-time messages with Node-RED
    • Creating an Alert Channel
    • Publish an Alert with Node-RED
    • Define and execute an Action in Node-RED
    • Python real-time SDK
    • Javascript real-time SDK
  • Cloud Node-RED Servers
    • Create a secure Cloud Node-RED Server in five minutes
    • Subscribe to data streams with a Cloud Node-RED Server
    • Integrate data streams to Node-RED dashboard
    • Integrate data streams to Slack
  • IOTFLOWS OVERVIEW
    • IoTFlows Roles and Permissions
    • Adding Team Members
  • Example Projects
    • Raspberry Pi as Gateway
      • Arduino to Raspberry Pi Serial Communication for Ultrasonic Sensor
    • Getting Started with Node-Red Dashboard
      • Installing Node-Red Dashboard
      • Accessing Node-Red Dashboard
      • 1. Creating a Page
      • 2. Adding Gauge Nodes
      • 3. Changing Dashboard Themes
      • 4. Adding Data to Gauge Nodes
      • 5. Adding a Chart Node
      • 6. Adding Data to Chart Node
      • 7. Adding a Template Node
      • 8. Adding Data to Template Node
      • 9. Adding Switch Node
      • 10. Adding Logic to Switch Node
      • 11. Adding a Slider Node
      • 12. Adding a Color Picker Node
      • 13. Adding a Numeric Node
      • 14. Adding a Button Node
      • 15. Adding Logic to a Button Node
      • Node-Red Dashboard Code
    • Publishing Data Streams from Python
    • Ultrasonic Sensor on Raspberry Pi Node-Red
  • General
    • Downloading IoTFlows Node-Red Nodes
    • Publishing Alert from Node-Red Manual
    • Publishing Data Stream from Node-Red Manual
Powered by GitBook
On this page
  • Installation
  • Usage
  • Initialization
  • Publish data stream
  • Subscribe to data stream
  • Publish an alert
  • Define a cloud action
  • Call/Execute a cloud action

Was this helpful?

  1. Real-Time Data Streams, Alerts, and Actions

Python real-time SDK

iotflows python module https://pypi.org/project/iotflows/

PreviousDefine and execute an Action in Node-REDNextJavascript real-time SDK

Last updated 3 years ago

Was this helpful?

IoTFlows Open Source Python WebSocket SDK.

IoTFlows python module

With this tool you can:

  1. Publish secure real-time data streams.

  2. Subscribe to the data streams and access real-time data on your web/mobile/IoT apps.

  3. Publish alerts to the alert channels with a defined severity level. Subscribers will get notified in the form of SMS/Email/Push.

  4. Define cloud actions that can be called from other IoT devices/web applications.

Installation

Use pip3 to install the IotTFows 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('API_KEY_USERNAME', 'API_KEY_PASSWORD')

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:

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!')

A that has permission to interact with the resources available in its project, or

An Organization that can have read-only or read/write permissions to the entire organization resources

A 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 . With the obtained , you can perform a HTTP request to generate a User Client.

https://pypi.org/project/iotflows/
Device API Key
User Client
OAuth2
JWT
Basic authentication
How to create a data stream
How to create an alert channel
How to create an action
IoT API Key