dbsqp / withings-influxdb2

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Got this working

jmaffie opened this issue · comments

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.