npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fitbit-livedata

v0.0.4

Published

This project aims to getting `livedata` from Fitbit tracker

Downloads

11

Readme

node-fitbit-livedata

This project aims to getting livedata from Fitbit tracker

!!! CAUTION !!!

This is an UNOFFICIAL and EXPERIMENTAL module.

Using this module sometimes forcibly logs out from fitbit application on your mobile device.

Requirement

  • Host Machine
    • macOS El Capitan
    • Windows10 Creators Update or later
    • Raspbian 4.9
  • Runtime
    • node.js (v6 or later)
    • Java (v1.8.0 or later)
  • Fitbit Account
  • Fitbit Tracker(Device) registered in the above account
    • Supported Trackers are

      • Charge HR

      The following trackers are not supported yet.

      • Ionic

      The following trackers are not verified yet. # I don't have them

      • Charge 2
      • Alta HR
      • Blaze
      • Flyer
      • Flex 2
      • Surge
      • Charge
      • Flex
      • One
      • Zip
      • Ultra
      • Force
      • Aria 2

Remarks

for Mac

Using this module on macOS, you need to connect or sync the macOS and your tracker with the official application only once before using this module.

for Windows

Because of using noble-uwp (it's very useful !), the version of your windows has to be Creators Update or later. And this module on Windows can't get heart rate from your trackers.

for Raspbian

If you want to get heart rate from your trackers, you need to comment out the line in node_modules/bleno/lib/hci-socket/bindings.js (bleno's issue)

for Trackers

Some trackers need to be set On or Auto about heart rate using FItbit app for a smartphone, and sync after that.

Install

Install as library

Do npm install(or npm i) in your project directory.

$ cd /path/to/your/project/
$ npm i fitbit-livedata

After npm install, you can see this module in dependencies of your package.json, the key is fitbit-livedata and the value is the path to node-fitbit-livedata.

$ cat /path/to/your/project/package.json
{
  "name": "<YOUR_`PROJECT_NAME>",
    :
  "dependencies": {
    "fitbit-livedata": "file:/path/to/node-fitbit-livedata"
  }
}

Install as CLI tool

$ npm i -g fitbit-livedata

Usage

Usage as library

import fitbit from 'fitbit-livedata';

fitbit.on('discover', (tracker) => {
  tracker.on('connecting', () => {
    console.log('connecting to the tracker');
  });
  tracker.on('openingSession', () => {
    console.log('start tracker session');
  });
  tracker.on('authenticating', () => {
    console.log('start tracker authentication process.');
  });
  tracker.on('sendAuth', () => {
    console.log('send authention infomation.');
  });
  tracker.on('authenticated', () => {
    console.log('finishing tracker authentication process...');
  });
  tracker.on('connected', () => {
    console.log('tracker is connected.');

    tracker.on('disconnected', () => {
      console.log('tracker is disconnected.');
      // if you want to re-connect automatically.
      tracker.connect();    
    });
  });
  tracker.on('data', (livedata) => {
    process.stdout.write(`${JSON.stringify(livedata)}\n`);
  });
  tracker.connect();
});
fitbit.on('error', (error) => {
  console.error(`${error}\n`);
  process.exit(1);
});

const accounts = [
  {
    username: fitbitUser1_Username,
    password: fitbitUser1_Password
  },
  {
    username: fitbitUser2_Username,
    password: fitbitUser2_Password
  },
//  :
];
const trackers = [];

accounts.reduce((prev, curr) => {
  return prev.then(() => {
    return new Promise((resolve) => {
      fitbit.getTrackers(curr)
        .then((trackerInfos) => {
          // login succeeded
          trackerInfos.forEach((trackerInfo) => {
            trackers.push(trackerInfo);
          });
          console.log(`${trackersInfos}\n`);
          resolve();
        })
        .catch((err) => {
          // login failed
          console.error(`login failed\n`);
          console.error(`${err}\n`);
          resolve();
        });
    });
  });
}, Promise.resolve()).then(() => {
  fitbit.scanTrackers(trackers);
});

Usage as CLI tool

$ fitbit-livedata -u <USERNAME> -p <PASSWORD>
{"device":{"name":"Charge HR","address":"XX:XX:XX:XX:XX:XX","serialNumber":"0123456789ab"},"livedata":{"time":"YYYY-MM-DDThh:mm:dd.sssZ","steps":5700,"distance":4024236,"calories":1220,"elevation":13,"veryActive":2,"heartRate":80}}
{"device":{"name":"Charge HR","address":"XX:XX:XX:XX:XX:XX","serialNumber":"0123456789ab"},"livedata":{"time":"YYYY-MM-DDThh:mm:dd.sssZ","steps":5700,"distance":4024236,"calories":1220,"elevation":13,"veryActive":2,"heartRate":82}}
 :

If you want to connect to only one tracker, add the tracker name( e.g. "Charge HR") with --trackername/-t option.

$ fitbit-livedata -u <USERNAME> -p <PASSWORD> -t "Charge HR"

Memo

Sequence Diagram between host, tracker and fitbit.com

sequence.png

Japanese memo on Qiita