Giter Site home page Giter Site logo

dbsqp / withings-influxdb2 Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 154 KB

Docker image to fetch data from Withings API and push it to an InfluxDBv2 bucket.

License: MIT License

Dockerfile 4.17% Shell 2.07% Python 93.76%
docker influxdb withings

withings-influxdb2's Introduction

withings-influxdbv2

Docker container to fetch data from the Withings API and place it in your influxdb. Uses a modified version of https://github.com/vangorra/python_withings_api to allow access to further paramaters from withings API https://developer.withings.com/api-reference/.

Core script run hourly via cron but sleep stats only pulled once per day (hour = WITHINGS_SLEEP_AT) to allow synchronisation of data pulled by docker and sources.

Withings API Token

InfluxDBv2 Setup

Setup InfluxDBv2, create bucket and create a token with write permissions for said bucket.

Docker Setup

https://hub.docker.com/r/dbsqp/withings-influxdbv2

$ docker run -d \
 -e WITHINGS_CLIENT_ID="<WITHINGS CLIENT ID>" \
 -e WITHINGS_CLIENT_SECRET="<WITHINGS CLIENT SECRET>" \
 -e WITHINGS_AUTH_CODE="INIT/<WITHINGS_AUTH_CODE>/-" \
 -e WITHINGS_SLEEP_AT="<hour>" \
 -e INFLUXDB2_HOST="<INFLUXDBv2 SERVER>" \
 -e INFLUXDB2_PORT="8086" \
 -e INFLUXDB2_ORG="Home" \
 -e INFLUXDB2_TOKEN="" \
 -e INFLUXDB2_BUCKET="DEV" \
 --name "Withings-InfluxDBv2" \
dbsqp/withings-influxdbv2:latest

Start container WITHINGS_AUTH_CODE="INIT", this will generate URL in log. Goto URL, authenticate and copy authorisation code. Restart container with WITHINGS_AUTH_CODE="received authorisation code". Check log to ensure oauth authorisation worked and token created. This can take multiple trys (The authorization code is valid for 30 seconds). Once workng reset WITHINGS_AUTH_CODE="" and restart. Token is stored in directory for easy removal via docker volume.

Options

 -e INFLUXDB2_SSL="true"
 -e INFLUXDB2_SSL_VERIFY="False"

Debug

To report out further details in the log enable debug:

 -e DEBUG="true"

withings-influxdb2's People

Contributors

dbsqp avatar michiii1337 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

withings-influxdb2's Issues

Got this working

I had to add a few extra steps to get this working:

  1. I am not that familiar with what a call back URL is. I was not sure at first if this had to be my server IP or open port to the container etc. this is just the URL that is opened in the browser after authentication and can be anything.

I found that I had to specify an environmental variable WITHINGS_CALLBACK and give it the SAME address as was used when registering for the withings credentials. I used https://localhost knowing it would fail to load.

I booted into the container with WITHINGS_AUTH_CODE=INIT

instead of messing with the logs I bashed int the container and ran # python3 /withings2influxdb.py
went to the address provided and then logged in.

  1. The page then redirected to a page that failed to load as expected but in the URL field IN THE BROWSER was a code=XXXXXXXXX

I then set this in the terminal with # export WITHINGS_AUTH_CODE=XXXXX
and reran # python3 /withings2influxdb.py

  1. I ran into an issue that my apnea score is None and this breaks the code so I commented out the three lines of the code that reference the variable ahi in withings2influxdb.py

senddata["fields"]["ahi"]=round(float(ahi),2)

write_influxdb()

del senddata["fields"]["ahi"]

  1. I also ran into an error in the code using http to access the influxdb server.

influxdb2_ssl_verify_str=os.getenv('INFLUXDB2_SSL_VERIFY', "True")
if influxdb2_ssl_verify_str is not None:
influxdb2_ssl_verify = influxdb2_ssl_verify_str.lower() == "true"

The condition "is not none" breaks my brain a little and I think breaks the code as it replaces the input False with True.

to deal with it i replaced:

if influxdb2_ssl_str:
influxdb2_url="https://" + influxdb2_host + ":" + str(influxdb2_port)
else:
influxdb2_url="http://" + influxdb2_host + ":" + str(influxdb2_port)

with:

influxdb2_url="http://" + influxdb2_host + ":" + str(influxdb2_port)

This isn't a general solution but it worked for my case

Thank you for putting this together. The code was easy to read and I was able to get it up and running.
If anyone has code to pull night_events in the api I would be interested to get that. I may work on that next.

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.