56°F

Aaron Parecki

  • Articles
  • Notes
  • Photos
  • Day 42: New Sleep Posts from FitBit #100DaysOfIndieWeb

    January 31, 2017

    I should have known this one would take longer than I expected.

    My Jawbone UP finally died, so I replaced it with a FitBit. I've really enjoyed the Jawbones, but I'm not confident in the future of the company's wearables department. I decided to take the plunge and dive in to the FitBit ecosystem instead. I got a new FitBit Charge 2, which among other things includes a heart rate monitor which I'm excited about. But step one was rewriting my sleep import script to pull sleep data from FitBit instead of Jawbone.

    Registering for the FitBit API was pretty straightforward. I was also impressed that the FitBit API provides additional capabilities for your own account when you tell it you're creating a "Personal" application. You get a lot more data out of the API compared to applications accessing other peoples' accounts. For example, you get the minute-by-minute sleep data needed to build the image that I show for sleep posts.

    One thing I was surprised about was that the API doesn't have any concept of absolute timestamps. All the times provided from the API lack a timezone and are local time. This means there are pieces of information such as "startTime": "2017-01-29T21:50:00.000" which doesn't actually correspond to an absolute point in time. This is a challenge when importing this to my website, since I want to pin that to an actual timestamp with a proper timezone offset. I realized this is the same problem I encountered with timestamps in Exif data in my photos. I even wrote a whole description of the problem and my solution. I had forgotten that at the end of that I turned the whole thing into an API so that I could reuse it later, so thanks past me!

    Now that I'm able to take a sleep record that starts at "2017-01-29T21:50:00" and turn that into an absolute point in time, the next step was generating the sleep image from the raw data they provide. FitBit provides minute-by-minute data, so I just draw a bunch of skinny rectangles in the SVG and let the browser sort it out. This looks fine at 100% zoom, for example:

    However, the number of vertical lines in the image is dependent on how long I was asleep for, so my images are all different widths. When I render this on my website, I just set the width to 100% and let the browser scale it. This unfortunately results in some interesting scaling artifacts that I'm not happy with:

    I don't really know how to solve this, so I'm going to leave it alone for now. I always have the raw data in the post so I can go back and regenerate the images again later.

    Portland, Oregon
    #100daysofindieweb #sleep #jawbone #fitbit
    Tue, Jan 31, 2017 12:44pm -08:00
    2 mentions

    Other Mentions

    • Aaron Parecki aaronparecki.com
      My 2017 Year in Review
      Thu, Jan 4, 2018 2:40pm -08:00
    • 100 Days of IndieWeb aaronparecki.com/tag/100daysofindieweb
      Day 42: New Sleep Posts from FitBit #100DaysOfIndieWeb: aaronparecki.com/2017/01/31/8/d…

      Tue, Jan 31, 2017 8:44pm +00:00 (via brid-gy.appspot.com)
Posted in /articles using quill.p3k.io

Hi, I'm Aaron Parecki, Senior Security Architect at Okta, and co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and participate in the OAuth Working Group at the IETF. I also help people learn about video production and livestreaming and dabble in product design.

I've been tracking my location since 2008 and I wrote 100 songs in 100 days. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. Read more.

  • Security Architect at Okta
  • IndieWebCamp Founder
  • OAuth WG Member

  • 🎥 YouTube Tutorials and Reviews
  • 🏠 We're building a triplex!
  • ⭐️ Life Stack
  • ⚙️ Home Automation
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Trips
  • Videos
  • Contact
© 1999-2023 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention Not by AI W3C HTML5 Creative Commons
WeChat ID
aaronpk_tv