horihiro / node-fitbit-livedata

This project aims to getting `livedata` from Fitbit tracker, is unofficial and experimental.
MIT License
10 stars 3 forks source link

Hearth beat #1

Closed jonathanboulenaz closed 6 years ago

jonathanboulenaz commented 7 years ago

Is it possible to get live data from heart rate on Mac ?

horihiro commented 7 years ago

Yes, this module can get live data which includes followings from Fitbit tracker in case of Charge HR.

It depends on type of Fitbit tracker. What´s your tracker?

And there are some limitations.

  1. I haven't checked the Fitbit Tracker other than my own Charge HR.
  2. You need to connect your tracker to your mac by other ways(e.g. Official Fitbit Application) before using this module. This limitation is only for macOS.

Please try this module and report to me, if you can.

horihiro commented 6 years ago

Hi, @jonathanboulenaz Did you try this module? What is your Fitbit Tracker?

I got Fitbit Ionic yesterday and tried to get livedata with this module. But I couldn't get.

I'm investigating the cause.

horihiro commented 6 years ago

I tried to get livedata from Fitbit Ionic again, and succeeded it with this module and Raspberry Pi Zero W.

jonathanboulenaz commented 6 years ago

I receive my charge HR yesterday and I'm gonna try to get live heart rate data today but I don't really know how to do it, I'm a beginner. An advice ?

Thanks for your help by the way

jonathanboulenaz commented 6 years ago

I don't understand what I'm suppose to do with the code I get when I click on the link in the html page

horihiro commented 6 years ago

@jonathanboulenaz Thank you for your reply.

Can you execute following code with node.js after git clone this project?

const fitbit = require('fitbit-livedata');

const accounts = [
  {
    username: <YOUR_FITBIT_ACCOUNT_NAME>,
    password: <YOUR_FITBIT_ACCOUNT_PASSWORD>
  }
];

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) => {
    console.log(JSON.stringify(livedata, null, 2));
  });
  tracker.connect();
});
fitbit.on('error', (error) => {
  console.error(`${error}\n`);
  process.exit(1);
});

fitbit.getTrackers(accounts)
  .then((trackers) => {
    fitbit.scanTrackers(trackers);
  });

If you use macOS, please review the limitation in the comment.

jonathanboulenaz commented 6 years ago

I get the live data but it seems that the heart rate data isn't actualise as often as the others. Can you just tell me the line I have to modify to refresh it every minutes like the others and how I have to modify this line. Thanks

horihiro commented 6 years ago

Frequency of emitting of ´data´ event is uncontrollable by this module, it depends on the tracker.

Can you show me your environment and all of your code and the result?

Thanks.

jonathanboulenaz commented 6 years ago

So it's impossible to get heart rate data more often than once in 4 days with the charge HR ?

horihiro commented 6 years ago

Once in 4days!?

I think that Fitbit trackers emit live data when atleast one of data changes.

My change HR emits data event, including heart rate, in every half minute at least. When I exercise or I'm nervous, my trackers(Change HR/Ionic) emit heart rate data in every second.

jonathanboulenaz commented 6 years ago

@horihiro

And you can see the heart rate value change ? For me it stays at zero as you can see on the screenshot.

capture d ecran 2017-11-22 a 09 28 40
horihiro commented 6 years ago

@jonathanboulenaz Thanks.

Please show me your environment, e.g. version of macOS/node.js etc.

And can you execute the following command at node-fitbit-livedata directory?

$ DEBUG=noble,bleno,fitbit-livedata node ./dist/bin/cli.js -u <YOUR_FITBIT_ACCOUNT_NAME> -p <YOUR_FITBIT_ACCOUNT_PASSWORD> -t "Charge HR"

After that, you will get the following logs. Please show the logs you will get.

$ DEBUG=noble,bleno,fitbit-livedata node ./dist/bin/cli.js -u <YOUR_FITBIT_ACCOUNT_NAME> -p <YOUR_FITBIT_ACCOUNT_PASSWORD> -t "Charge HR"
  fitbit-livedata login succeeded +0ms
  bleno platform darwin +0ms
  bleno addressChange ab:cd:ef:01:23:45 +1ms
  noble addressChange ab:cd:ef:01:23:45 +0ms
  bleno stateChange poweredOn +1ms
  noble stateChange poweredOn +2ms
  bleno servicesSet +2ms
  fitbit-livedata already powered on. +0ms
  noble scanStart +2ms
  fitbit-livedata stop scanning. +0ms
  noble scanStop +3s
  bleno accept 01:23:45:67:89:ab +5s
  bleno mtu 23 +1ms
  fitbit-livedata 8 characteristics are found +0ms
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c00a0a00080010000000c80001' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0140c0a00008396acef54f71700' +0ms
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c0502e19e877ee600450' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0510e6120324aaf722763310000' +0ms
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c0523884581b8253526b' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c002' +0ms
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c001' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c001' +0ms
{"device":{"name":"Charge HR","address":"01:23:45:67:89:ab","serialNumber":"abcdef012345"},"livedata":{"time":"2017-11-22T09:03:15.000Z","steps":7682,"distance":5833646,"calories":1714,"elevation":31,"veryActive":48,"heartRate":73}}
jonathanboulenaz commented 6 years ago

https://we.tl/CE9oqcOA5G

capture d ecran 2017-11-22 a 10 41 38
horihiro commented 6 years ago

Is this all?The link broken.

I can't understand this situation. You didn't connect your tracker.

I use macos el capitan and node8. And you?

jonathanboulenaz commented 6 years ago

@horihiro If you copy and paste the link in your search box it doesn't work ? I use Sierra and node 8. The tracker seems to be connected. I can see the step data change in realtime.

For the 4 days thing I mean it seems to be a four-days average of heart rate.

horihiro commented 6 years ago

@jonathanboulenaz Thank. I can get your code and execute it.

The logs is following.

$ DEBUG=noble,bleno,fitbit-livedata node build/index.js
  fitbit-livedata login succeeded +0ms
login succeeded

  bleno platform darwin +0ms
  bleno addressChange ab:cd:ef:01:23:45 +0ms
  bleno stateChange poweredOn +2ms
  bleno servicesSet +2ms
  noble addressChange ab:cd:ef:01:23:45 +0ms
  noble stateChange poweredOn +2ms
  fitbit-livedata start scanning... +0ms
  noble scanStart +1ms
connecting to the tracker
  bleno accept f7:54:ef:ac:96:83 +29s
  bleno mtu 23 +0ms
  fitbit-livedata 8 characteristics are found +0ms
start tracker session
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c00a0a00080010000000c80001' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c0140c0a00008396acef54f71700' +0ms
start tracker authentication process.
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c050d300cd530d759d11' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c051785cc7254a5c6e406f310000' +0ms
send authention infomation.
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c052880c429d95b704e1' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c002' +0ms
finishing tracker authentication process...
  fitbit-livedata HOST --> adabfb026e7d4601bda2bffaa68956ba 'c001' +0ms
  fitbit-livedata HOST <-- adabfb016e7d4601bda2bffaa68956ba 'c001' +0ms
tracker is connected.
{"device":{"name":"Charge HR","address":"01:23:45:67:89:ab","serialNumber":"abcdef012345"},"livedata":{"time":"2017-11-22T22:12:30.000Z","steps":744,"distance":432140,"calories":557,"elevation":1,"veryActive":0,"heartRate":72}}
{"device":{"name":"Charge HR","address":"01:23:45:67:89:ab","serialNumber":"abcdef012345"},"livedata":{"time":"2017-11-22T22:12:40.000Z","steps":744,"distance":432140,"calories":557,"elevation":1,"veryActive":0,"heartRate":75}}
{"device":{"name":"Charge HR","address":"01:23:45:67:89:ab","serialNumber":"abcdef012345"},"livedata":{"time":"2017-11-22T22:12:41.000Z","steps":744,"distance":432140,"calories":557,"elevation":1,"veryActive":0,"heartRate":76}}
{"device":{"name":"Charge HR","address":"01:23:45:67:89:ab","serialNumber":"abcdef012345"},"livedata":{"time":"2017-11-22T22:12:42.000Z","steps":744,"distance":432140,"calories":557,"elevation":1,"veryActive":0,"heartRate":76}}

I got heart rate (and its change) from Charge HR. I think this module and your usage is no problem.

Please check again whether Heart Rate settings of Charge HR is On or Auto using FItbit app for a smartphone, and sync again.

If your smartphone is Android, you can see following setting screen.

horihiro commented 6 years ago

@jonathanboulenaz can you tell me about the current status? No progress?

jonathanboulenaz commented 6 years ago

I change the settings on my android and everything works fine. Thank you very much for your help.

horihiro commented 6 years ago

Really? I'm glad about your success!