Package: iotflows
iotflows python modulehttps://iotflows.comIoTFlows 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.InstallationUsepip3to install the iotflows python module:Prerequisitesudo pip3 install pathlib2IoTFlows Modulesudo pip3 install iotflowsNote: only Python3 is supported for this module.UsageInitializationThis function will create and initialize an IoTFlows instance.importiotflows.realtimeasiotflowsRTIoTFlows=iotflowsRT.init('CLIENT_ID','CLIENT_SECRET')Make sure to changeCLIENT_IDandCLIENT_SECRETwith the proper credentials obtained from IoTFlows console.
These credentials can be either one of these options:ADevice Clientthat has permission to interact with the resources available in its project, orAnOrganization IoT API KEYthat can have read-only or read/write permissions to the entire organization resourcesAUser Clientthat 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 usingOAuth2. With the obtainedJWT, you can perform aBasic authenticationHTTP request to generate a User Client.Publish data streamTo publish a real-time data stream, you need to pass these parameters in a json object:data_stream_uuid: the uuid of the data streamdata: the data to be published to the data streamRead more:How to create a data streamExample:IoTFlows.publish(data_stream_uuid='ds_xxxxxxxxxxxxxxxxxxxxxxx',data='Hello World!')Subscribe to data streamTo 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 uuidqos (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 receivedExample:defhandlerFunction(topic,payload):print('received new payload!!!')print(payload)IoTFlows.subscribe(data_stream_uuid='ds_xxxxxxxxxxxxxxxxxxxxxxx',qos=2,callback=handlerFunction)Publish an alertTo publish an alert, you need to pass these parameters in a json object:alert_channel_uuid: the uuid of the alert channelseverity_level: the severity level of the alert. It can be MAJOR, MINOR or INFORMATIVEsubject: the subject of the alertdescription: the description/message of the alertRead more:How to create an alert channelExample:IoTFlows.alert(alert_channel_uuid='ac_xxxxxxxxxxxxxxxxxxxxxxxx',severity_level='MINOR',subject='Water Leak',description='Water leackage detected in Site A.')Define a cloud actionTo 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 uuidqos (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 executedRead more:How to create an actionExample:defcontrolPump(topic,payload):print('received new command!')print(payload)IoTFlows.defineAction(action_uuid='da_xxxxxxxxxxxxxxxxxxxxxxxxx',qos=2,callback=controlPump)Call/Execute a cloud actionTo publish an alert, you need to pass these parameters in a json object:action_uuid: the uuid of the actionpayload: the payload to be published to the actionExample:IoTFlows.callAction(action_uuid='da_xxxxxxxxxxxxxxxxxxxxxxxxx',data='Turn on!')