项目作者: johndoe31415

项目描述 :
Bluetooth Low Energy heart rate monitoring service provides heart rate data via UNIX server socket
高级语言: C
项目地址: git://github.com/johndoe31415/btlehrservice.git
创建时间: 2019-09-28T22:06:57Z
项目社区:https://github.com/johndoe31415/btlehrservice

开源协议:GNU General Public License v3.0

下载


btlehrservice

This is a small application that opens up a listening UNIX socket and
continuously in the background tries to connect to a Bluetooth Low-Energy
(BTLE) Heart Rate monitor. If a connection is successfully established, it
reports the data periodically.

The underlying BTLE stack is huge and comparatively unreliable. It depends
highly on the connection quality and there’s a lot of things that can go wrong.
Furthermore, the stack doesn’t really seem written to allow to properly handle
reconnections (e.g., I had this issue).
Therefore, btlehrservice is written in a way that encapsulates the actual
fragile BTLE communication in a child process (i.e., contain it in its own
address space) and — as soon as any timeout occurs — just kills the whole
thing off entirely and retries.

Usage

It’s quite simple, there’s not many arguments right now:

  1. usage: btlehrservice [-r] [-u username] [-c oct_permissions]
  2. dest_mac_address socket
  3. Bluetooth Low Energy Heart Rate service.
  4. positional arguments:
  5. dest_mac_address BTLE MAC address of the device that the btlehrservice
  6. should try to connect to.
  7. socket UNIX socket that the btlehrservice listens on.
  8. optional arguments:
  9. -r, --random-btle-address
  10. Use a random BTLE address. Some heartrate monitors
  11. (e.g., Polar H9) seem to require this.
  12. -u username, --user username
  13. Change the username of the unix_socket to this user
  14. after it has been bound.
  15. -c oct_permissions, --chown oct_permissions
  16. Change permissions of the unix_socket to this octal
  17. permission value after it has been bound.

For example:

  1. $ ./btlehrservice -r 20:C3:8F:FF:0A:7E heartrate_socket

This opens a “heartrate_socket” UNIX socket that gives linewise JSON data when
connected to it. For example:

  1. { "connected": false }
  2. { "connected": false }
  3. { "connected": false }
  4. { "connected": true, "have_value": false, "ts": 0.000000, "last_value": 0 }
  5. { "connected": true, "have_value": false, "ts": 0.000000, "last_value": 0 }
  6. { "connected": true, "have_value": false, "ts": 0.000000, "last_value": 0 }
  7. { "connected": true, "have_value": false, "ts": 0.000000, "last_value": 0 }
  8. { "connected": true, "have_value": true, "ts": 1569758841.500977, "last_value": 78 }
  9. { "connected": true, "have_value": true, "ts": 1569758842.498586, "last_value": 78 }
  10. { "connected": true, "have_value": true, "ts": 1569758843.496032, "last_value": 78 }
  11. { "connected": true, "have_value": true, "ts": 1569758844.493620, "last_value": 78 }
  12. { "connected": true, "have_value": true, "ts": 1569758845.491243, "last_value": 77 }
  13. { "connected": true, "have_value": true, "ts": 1569758846.488755, "last_value": 77 }
  14. { "connected": true, "have_value": true, "ts": 1569758847.486287, "last_value": 77 }

The “connected” item indicates if a BTLE connection was successfully
established. The “have_value” item indicates if the heart rate monitor returned
a value (and therefore the “last_value” heart rate in BPM is current).

License

GNU GPL-3.