Skip to main content

IoT Relay - Relay data between data sources and destinations.

Project description

Internet of Things Relay

IoT Relay is a framework for connecting many data sources with many destinations, or handlers. It is intended to be used with time-series, like those produced by IoT devices, but can probably also be used for non-time-series data. Handlers register themselves and provide callbacks, which are invoked when their registered reading type is received by a data source. A handler may simply relay readings as they come or it may inspect the readings and generate events based on those readings.

Creating a data source 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 an empty iterator.:

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 setup tools to find plugins registered in the iotrelay group. Datasources should use the entrypoint name source:

from setuptools import setup


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

Creating a data handler plugin

Sample Handler:

class Handler(object):
   batch_len = 10

    def __init__(self, config):
        self.readings = []
        self.config = config

    def set_reading(self, reading):
        print('set_reading({0!r})'.format(reading))
        self.readings.append(reading)
        if len(self.readings) == self.batch_len:
            for item in self.readings:
                print(item)
            self.readings = []

    def flush(self):
        print('flushing unsent readings')
        for reading in self.readings:
            print(reading)
        self.readings = []

Sample setup.py:

from setuptools import setup


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

License

Copyright (c) 2014, 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.0.0.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

iotrelay-1.0.0-py2.py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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