GithubHelp home page GithubHelp logo

yasiral / thethings.io-python-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thethings/thethings.io-python-library

0.0 1.0 0.0 17 KB

Python API and examples to interface thethings.iO

Python 100.00%

thethings.io-python-library's Introduction

Python API for http://thethings.io

Installation

  1. Use git to download distribution

$ git clone https://github.com/theThings/thethings.iO-python-library.git ```

  1. Use setup.py to install API:

$ python setup.py install ```

API Documentation

Contents:

class class ThethingsAPI.TheThingsAPI(token=None)

activate(actCode)

  Activates a non activated thing.

  Args:
     actCode: activation code string.

  Returns:
     true on sucess, False on malformed URL error.  Any network
     problem raises an exception.

  Raises:
     URLError on errors (from urllib2.urlopen)

activateSync(resource, act, auxResource=None)

  Turn on or off sync mechanism for subscribe. If sync is on,
  every time the class realises that  the connection is lost, it
  will query thethings.io to recover lost data for a single
  specific resource.

  An auxiliary resource is needed to know which is the last
  processed data. i.e. Once internet connection is recovered, Sync
  will check the timestamp of the auxiliar  resource (by default
  resource + "_ack") and the timestamp  of the last value written
  for the specific resource  that we want to recover lost data
  ("resource" argument  of this function). If the timestamps
  differe, the  subscribe thread will recover all the data between
  this  two timestamps and will place it in the suscribe queue.
  Therefore, is the task of the user to: (a) Manually add a
  timestamp when writting the resource that we want to monitor
  (using third argument of addVar function). (b) Update the
  auxiliary resource with the timestamp  of the last processed
  data. Otherwise, Sync may  read an already processed value and
  put it again  in the subscribe queue (to stash multiple data
  from  once, it's enough to upddate the auxiliary resource  with
  the oldest data). The function stashData can be used for this
  purpose. In summary, if Sync is on, after processing a value
  read from the subscribe queue, the function "stashData" should
  be called with the value of the timestamp of the readed value.

  Args:
     resource: resource that we want to recover
        data if the connection is lost or the application is
        closed.

     auxResource: name of the auxiliary resource.

addVar(key, value, dt=None)

  Add the pair {key : value} to the list of pending  data to be
  written to thethings.io. This function can  be called any times
  to add more variables to be sent.  Call the "write" function to
  actually write the values.

  Args:
     key: string key to write. value: value dt: custom timestamp
     either string '2015-10-28T12:18:56.799Z' or python datetype.

clear()

  Clear internal data buffer to be written

static dt2str(dt)

  Converts datetime python object to formated string.

  Args:
     dt: python datetime

  Returns:
     string '2015-10-28T12:18:56.799Z'.

getToken()

  Get function for internal token.

  Returns:
     current token.

internalLogs(act)

  set on or off internal logs of this class that will provide
  information for developers. The logs will be written to
  thethings.io resources  "err" and "log" for errors and other
  logs  respectively.

  Args:
     act: true if on, false if off.

read(key, limit=1, startDate=None, endDate=None, to=10)

  Read a variable from the theThings.iO. If only the  argument
  "key" is specified, the last value will be  returned. This
  function will return "limit" number of  values of the variable
  inside an array. The elements are returned from newest to oldest

  Args:
     key: name of the variable limit: max number of values to
     return. startDate: '2015-10-28T12:18:56.799Z' or datetime
     endDate: '2015-10-28T12:18:56.799Z' or datetime to: timeout
     in seconds

  Returns:
     None on connection timeout, 0 if the resource  doesn't exist,
     otherwise a list with the readed  values.

stashData(dt)

  Stash data up to dt datetime as processed. This function is only
  useful for the Sync feature. It won't return until the data has
  been written.

  Args:
     dt: datetime python object.

static str2dt(strdate)

  Converts a formated string to python datetime.

  Args:
     strdate: string '2015-10-28T12:18:56.799Z'.

  Returns:
     datedime python object.

subscribe()

  Subscribe to thethings.iO. Calling this function will start a
  thread that will listen for incoming data from thethings.iO and
  will queue it as it is  retrieved.

  Returns:
     A python queue to read the data.

write()

  Actually write the values to theThings.iO. See  function
  "addVar". internal list of data to be sent is cleared.

  Returns:
     Http code status

  Raises:
     URLError on errors (from urllib2.urlopen)

Indices and tables


  • Index

  • Module Index

  • Search Page

thethings.io-python-library's People

Contributors

charlyo avatar jdgwartney avatar hextoryworld avatar aleixrocks avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.