Package: wolk-connect
██╗    ██╗ ██████╗ ██╗     ██╗  ██╗ ██████╗ ██████╗ ███╗   ██╗███╗   ██╗███████╗ ██████╗████████╗██║    ██║██╔═══██╗██║     ██║ ██╔╝██╔════╝██╔═══██╗████╗  ██║████╗  ██║██╔════╝██╔════╝╚══██╔══╝██║ █╗ ██║██║   ██║██║     █████╔╝ ██║     ██║   ██║██╔██╗ ██║██╔██╗ ██║█████╗  ██║        ██║██║███╗██║██║   ██║██║     ██╔═██╗ ██║     ██║   ██║██║╚██╗██║██║╚██╗██║██╔══╝  ██║        ██║╚███╔███╔╝╚██████╔╝███████╗██║  ██╗╚██████╗╚██████╔╝██║ ╚████║██║ ╚████║███████╗╚██████╗   ██║╚══╝╚══╝  ╚═════╝ ╚══════╝╚═╝  ╚═╝ ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝╚═╝  ╚═══╝╚══════╝ ╚═════╝   ╚═╝██████╗ ██╗   ██╗████████╗██╗  ██╗ ██████╗ ███╗   ██╗██╔══██╗╚██╗ ██╔╝╚══██╔══╝██║  ██║██╔═══██╗████╗  ██║█████╗██████╔╝ ╚████╔╝    ██║   ███████║██║   ██║██╔██╗ ██║╚════╝██╔═══╝   ╚██╔╝     ██║   ██╔══██║██║   ██║██║╚██╗██║██║        ██║      ██║   ██║  ██║╚██████╔╝██║ ╚████║╚═╝        ╚═╝      ╚═╝   ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝WolkAbout Python Connector library for connecting devices to WolkAbout IoT platform instance.PrerequisitePython 3.7+InstallationThere are two ways to install this packageInstalling with pippython3 -m pip install wolk-connectInstalling from sourceClone this repository from the command line using:git clone https://github.com/Wolkabout/WolkConnect-Python.gitInstall dependencies by invokingpython3 -m pip install -r requirements.txtInstall the package by running:python3 setup.py installExample UsageEstablishing connection with WolkAbout IoT platformCreate a device on WolkAbout IoT Platform by using theSimple exampledevice type that is available on the
platform.Note that device type can be created by importing `simple_example.json` file as new Device Type.This device type fitsmain.pyand
demonstrates the periodic sending of a temperature feed reading.importwolk# Setup the device credentials which you received# when the device was created on the platformdevice=wolk.Device(key="device_key",password="some_password")# Pass your device and server information# defaults to secure connection to Demo instance - comment out host, port and ca_certwolk_device=wolk.WolkConnect(device,host="insert_host",port=80,ca_cert="PATH/TO/YOUR/CA.CRT/FILE")wolk_device.connect()Adding feed valueswolk_device.add_feed_value(("T",26.93))# or multiple feed value readingswolk_device.add_feed_value([("T",27.11),("H",54.34),("P",1002.3)])Optionally pass atimestampasround(time.time()) * 1000.
This is useful for maintaining data history when readings are not published immediately after adding them to storage.
Iftimestampis not provided, the library will assign a timestamp before placing the reading into storage.Adding feed values with timestamp# Add a signel feed reading to the message queue with the timestampwolk_device.add_feed_value(("T",12.34),1658315834000)# Add a multi feed reading to the message queue with the timestampwolk_device.add_feed_value([("T",12.34),("H",56.78),("P",1022.00)],1658315834000)Readings persistence and limitReadings with methodadd_feed_valueare added into local persistence. When adding messages be mindful of the
message size that will be published. The default MQTT message size is 260MB, and since readings are of different sizes
(based on the users use-case), check that the limit of readings in persistence will be under the MQTT limit for your broker.
The default readings limit is set to 500000. You can change it withset_custom_readings_persistence_limit, if your readings
are bigger, you can decrease the size, or if you have smaller readings, you can increase the size.Data publish strategyStored feed values are pushed to WolkAbout IoT platform on demand by calling:wolk_device.publish()Adding feed values 'separated'When adding feed values, the values themselves are persisted, which means when publishing all values will be placed
in a single message and published as a single message.If you would like to ensure different behavior, where you can add feed values that will be sent as a separate message
from any other feed values, use the alternative method:# Method arguments are exactly the same as for the `add_feed_value`wolk_device.add_feed_value_separated([("T",12.34),("H",56.78),("P",1022.00)],1658315834000)Disconnecting from the platformwolk_device.disconnect()Additional functionalityWolkConnect-Python library has integrated additional features which can perform full WolkAbout IoT platform potential.
Explore theexamplesfor more information.