Skip to main content

IoT Relay - Relay data between data sources and destinations.

Project description

IoT Relay: Giving Voice to Your Things

Release v1.2.3

In greater and greater numbers, “things” are capable of gathering data about their environment. These things have an interface to retrieve the measurements being taken but contain no way of pushing this data to the Internet. For example, home weather stations often contain only a USB interface and no network capability. Other devices may have network capability, such as ZigBee®, but still don’t have a direct way to send data to Internet connected hosts.

Internet of Things Relay is an application and framework for gathering data from sources and relaying it to destinations. It is somewhat like publish/subscribe except that it’s geared more toward devices that are unable to initiate a connection (they must be polled to get at their data).

IoT Relay provides basic setup and matches data sources with interested handlers. The rest of the work is left to plugins.

Installation

IoT Relay is available via PyPI.

$ pip install iotrelay

It is also necessary to create an (initially empty) ini-style file: ~/.iotrelay.cfg.

[itorelay]

Plugins

Before IoT Relay can do anything useful, it needs plugins. There are plugin types: source and handler. Source plugins generate data. Handler plugins handle or do something with data that source plugins produce. These definitions are intended to be open-ended. Although IoT Relay was developed with the intention of relaying time-series type data between remote sources and remote destinations, a handler could instead view each datum as an event and trigger some action. Likewise, data source plugins do not have to simply pass the data they are collecting. They may process the data in some way before making it available to interested handlers.

Data Source Sample Plugin

A data source definition is a class which provides a get_reading() method and a constructor which accepts a config parameter. The get_reading() method must return one or more instances of the Reading() class or None. In this example, create a file called iotrelay_sample_source.py and enter the following code.

# iotrelay_sample_source.py

import random
from iotrelay import Reading


class DataSource(object):
    def __init__(self, config):
        self.config = config

    def get_readings(self):
        return Reading('sample', random.randint(1, 100))

IoT Relay uses setuptools to find plugins registered in the iotrelay group. Datasources should use the entry-point name source. In the same directory as iotrelay_sample_source.py, the following code should be placed in setup.py.

# setup.py

from setuptools import setup


setup(name='iotrelay-sample-source',
      install_requires=['iotrelay'],
      py_modules=['iotrelay_sample_source'],
      entry_points={
          'iotrelay': ['source=iotrelay_sample_source:DataSource']
      }
)

Install the source plugin by typing:

$ python setup.py install

Data Handler Sample Plugin

Like the previous example, create a new directory with two files:

# iotrelay_sample_handler.py

class Handler(object):
    def __init__(self, config):
        self.config = config

    def set_reading(self, reading):
        print(reading)


# setup.py

from setuptools import setup


setup(name='iotrelay-sample-handler',
      install_requires=['iotrelay'],
      py_modules=['iotrelay_sample_handler'],
      entry_points={
          'iotrelay': ['handler=iotrelay_sample_handler:Handler']
      }
)

Install the handler plugin by typing:

$ python setup.py install

Plugin Configuration

The minimal source plugin used in this example does not require any configuration. The ‘reading types’ option in a handler’s configuration specifies which reading types a handler will receive. In order to receive readings from the ‘iotrelay-sample-source’ plugin, the ‘reading type’ option in the iotrelay-sample-handler would be ‘sample’. This corresponds to the reading_type attribute set by the Reading constructor when get_readings() was called.

The section names correspond directly to the plugin names, as defined in setup.py.

; ~/.iotrelay.cfg

[iotrelay]

[iotrelay-sample-source]
[iotrelay-sample-handler]
reading types = sample

Any options specified in each plugins section will be passed to that plugin’s constructor during initialization.

Running IoT Relay

Start IoT Relay with the following command:

$ iotrelay

License

IoT Relay is licensed under The BSD 2-Clause License.

License

Copyright © 2017, Emmanuel Levijarvi All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

iotrelay-1.2.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

iotrelay-1.2.3-py3.5.egg (10.0 kB view details)

Uploaded Egg

iotrelay-1.2.3-py2.py3-none-any.whl (9.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file iotrelay-1.2.3.tar.gz.

File metadata

  • Download URL: iotrelay-1.2.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for iotrelay-1.2.3.tar.gz
Algorithm Hash digest
SHA256 91050c87797497d337892f46b9af2005e90c892c0c59ac0d03d642d17a4915a0
MD5 059c0c2d5ff5e39a17dd739bf8cbd238
BLAKE2b-256 e136efe656921eb1b509c0549e209e15ecff81ab601bfa652fc69e3acb459450

See more details on using hashes here.

File details

Details for the file iotrelay-1.2.3-py3.5.egg.

File metadata

  • Download URL: iotrelay-1.2.3-py3.5.egg
  • Upload date:
  • Size: 10.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for iotrelay-1.2.3-py3.5.egg
Algorithm Hash digest
SHA256 873f0981cdaf3970a84b098d128b9e949c1e9e1894437971f006c42d1a0a1bce
MD5 10f7595d736095a89162ef1c86595ac0
BLAKE2b-256 f36e03cf137c5bebb73938b2c45d897c27e6781c2829dce1ee4644fbe1250429

See more details on using hashes here.

File details

Details for the file iotrelay-1.2.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for iotrelay-1.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6cb0a9dc45892afd8c4915021f606d4b4184e0cb39e399059650a69ac975ad41
MD5 f0fc6fcaa0f16fd7fb2fe30454be50c8
BLAKE2b-256 b7048f247099a354a047326e0145c724ab9d9ee3c9314fb74df01d6a7b1a41c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page