Giter Club home page Giter Club logo

home_portal's Introduction

Quick little CLI for the flume API.

This script is currently written to explictly log data for just the last 1 minute assuming that your cron/scheduler is the throttle for data fidelity. There's lots of options available from flume. Feel free to make this code more robust/configurable

Dependencies

  • python3
  • pyjwt library
  • requests library

What you will need

  • Your API client ID and secret. You have to get this through the flumetech portal: https://portal.flumetech.com/#dashboard
  • Your username and password for the portal.
  • Only 1 flume device. I wrote this code to work with a single flume sensor. I have no idea what will happen if you have more than one.

How does it work

  1. First you need to establish a JWT/Token. This requires client ID & secret as well as username and password. You need to specify a tokenfile to write the resulting token to.
    • flumecli.py --auth --clientid <clientid> --clientsecret <clientsecret> --username <flumetech username> --password <flumetech password> --tokenfile <pathtofile>
  2. You may want to have a look at the details of your environment. These can be used to interface with the API directly or using other systems.
    • flumecli.py --details --tokenfile <pathtofile>
    • Your User ID and Device ID are generated by the flume system. These are often required when interacting with other API calls
  3. Query the flume API. There's a query language from flume but for the purposes of this script I'm just looking at the last 1 minute of water flow, assuming that you just schedule this script to run every minute. There's a number of different ways to output this data.
    1. flumecli.py --query --tokenfile <pathtofile> Simple query with output to stdout showing timestamp and water flow from last minute
    2. flumecli.py --query --tokenfile <pathtofile> --logfile <pathtologfile> Same output as above, except the output gets appended to the specified file
  4. Query the flume API for several days (YYYY-MM-DD format). This will retrieve all data, per minute, from 00:00:00 to 23:59:00 each day listed. Each day is two queries split into 12 hour segments.
    1. flumecli.py --getBulkData --startDate 2020-07-01 --endDate 2020-07-01 --tokenfile <pathtofile> Simple query with output to stdout showing timestamp and water flow for the day
    2. flumecli.py --getBulkData --startDate 2020-07-01 --endDate 2020-07-02 --tokenfile <pathtofile> --logfile <pathtologfile> Same output as above, except the output gets appended to the specified file
    3. flumecli.py --getBulkData --startDate 2020-07-01 --endDate 2020-07-02 --tokenfile <pathtofile> --logfile <pathtologfile> --DBfile <DB name> --DBtable <DB table> Same output as above, except the output gets appended to the specified tinyDB and table.

Read the --help on the command line. There are some other options available.

TL;DR

  1. Update credentials in the local_credentials.py file
  2. python3 flumecli.py --auth
  3. python3 flumecli.py --getBulkData --startDate 2021-01-15
  4. python3 flumecli.py --getBulkData --startDate 2021-01-15 --endDate 2021-02-01

home_portal's People

Contributors

jamesobenson avatar scriptblock avatar

Stargazers

Robert French 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.