Shell - Heart Rate Bricklet

Note

This Bricklet is currently in the prototype stage and the software/hardware as well as the documentation is in an incomplete state.

This is the description of the Shell API bindings for the Heart Rate Bricklet. General information and technical specifications for the Heart Rate Bricklet are summarized in its hardware description.

An installation guide for the Shell API bindings is part of their general description.

Examples

The example code below is Public Domain (CC0 1.0).

Simple

Download (example-simple.sh)

1
2
3
4
5
6
7
8
#!/bin/sh
# connects to localhost:4223 by default, use --host and --port to change it

# change to your UID
uid=abc

# get current heart rate (in beats per minute)
tinkerforge call heart-rate-bricklet $uid get-heart-rate

Callback

Download (example-callback.sh)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/sh
# connects to localhost:4223 by default, use --host and --port to change it

# change to your UID
uid=abc

# set period for heart rate callback to 1s (1000ms)
# note: the heart rate callback is only called every second if the
#       heart rate has changed since the last call!
tinkerforge call heart-rate-bricklet $uid set-heart-rate-callback-period 1000

# handle incoming color callbacks
tinkerforge dispatch heart-rate-bricklet $uid heart-rate

Threshold

Download (example-threshold.sh)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/sh
# connects to localhost:4223 by default, use --host and --port to change it

# change to your UID
uid=abc

# get threshold callbacks with a debounce time of 10 seconds (10000ms)
tinkerforge call heart-rate-bricklet $uid set-debounce-period 10000

# Configure threshold for heart rate values,
# Heart Rate  : greater than 70 beats per minute
tinkerforge call heart-rate-bricklet $uid set-heart-rate-callback-threshold greater 50 70

# handle incoming heart-rate-reached callbacks
tinkerforge dispatch heart-rate-bricklet $uid heart-rate-reached\
 --execute "echo 'Heart Rate(bpm): {heart-rate}';
            echo '';"

API

Possible exit codes for all tinkerforge commands are:

  • 1: interrupted (ctrl+c)
  • 2: syntax error
  • 21: Python 2.5 or newer is required
  • 22: Python argparse module is missing
  • 23: socket error
  • 24: other exception
  • 25: invalid placeholder in format string
  • 26: authentication error
  • 201: timeout occurred
  • 209: invalid argument value
  • 210: function is not supported
  • 211: unknown error

Command Structure

The common options of the call and dispatch commands are documented here. The specific command structure is shown below.

tinkerforge call heart-rate-bricklet [<option>..] <uid> <function> [<argument>..]
Parameters:
  • <uid> -- string
  • <function> -- string

The call command is used to call a function of the Heart Rate Bricklet. It can take several options:

  • --help shows help for the specific call command and exits
  • --list-functions shows a list of known functions of the Heart Rate Bricklet and exits
tinkerforge dispatch heart-rate-bricklet [<option>..] <uid> <callback>
Parameters:
  • <uid> -- string
  • <callback> -- string

The dispatch command is used to dispatch a callback of the Heart Rate Bricklet. It can take several options:

  • --help shows help for the specific dispatch command and exits
  • --list-callbacks shows a list of known callbacks of the Heart Rate Bricklet and exits
tinkerforge call heart-rate-bricklet <uid> <function> [<option>..] [<argument>..]
Parameters:
  • <uid> -- string
  • <function> -- string

The <function> to be called can take different options depending of its kind. All functions can take the following options:

  • --help shows help for the specific function and exits

Getter functions can take the following options:

  • --execute <command> shell command line to execute for each incoming response (see section about output formatting for details)

Setter functions can take the following options:

  • --expect-response requests response and waits for it

The --expect-response option for setter functions allows to detect timeouts and other error conditions calls of setters as well. The device will then send a response for this purpose. If this option is not given for a setter function then no response is send and errors are silently ignored, because they cannot be detected.

tinkerforge dispatch heart-rate-bricklet <uid> <callback> [<option>..]
Parameters:
  • <uid> -- string
  • <callback> -- string

The <callback> to be dispatched can take several options:

  • --help shows help for the specific callback and exits
  • --execute <command> shell command line to execute for each incoming response (see section about output formatting for details)

Basic Functions

tinkerforge call heart-rate-bricklet <uid> get-heart-rate
Output:
  • heart-rate -- int

Returns the current heart rate measured.

If you want to get the heart rate periodically, it is recommended to use the callback heart-rate and set the period with set-heart-rate-callback-period.

Advanced Functions

tinkerforge call heart-rate-bricklet <uid> get-identity
Output:
  • uid -- string
  • connected-uid -- string
  • position -- char
  • hardware-version -- int,int,int
  • firmware-version -- int,int,int
  • device-identifier -- int (has symbols)

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c' or 'd'.

The device identifier numbers can be found here

Callback Configuration Functions

tinkerforge call heart-rate-bricklet <uid> set-heart-rate-callback-period <period>
Parameters:
  • <period> -- int
Output:

no output

Sets the period in ms with which the heart-rate callback is triggered periodically. A value of 0 turns the callback off.

heart-rate is only triggered if the heart rate has changed since the last triggering.

The default value is 0.

tinkerforge call heart-rate-bricklet <uid> get-heart-rate-callback-period
Output:
  • period -- int

Returns the period as set by set-heart-rate-callback-period.

tinkerforge call heart-rate-bricklet <uid> set-heart-rate-callback-threshold <option> <min> <max>
Parameters:
  • <option> -- char (has symbols)
  • <min> -- int
  • <max> -- int
Output:

no output

Sets the thresholds for the heart-rate-reached callback.

The following options are possible:

Option Description
'x' Callback is turned off
'o' Callback is triggered when the heart rate is outside the min and max values
'i' Callback is triggered when the heart rate is inside the min and max values
'<' Callback is triggered when the heart rate is smaller than the min value (max is ignored)
'>' Callback is triggered when the heart rate is greater than the min value (max is ignored)

The default value is ('x', 0, 0).

The following symbols are available for this function:

  • off = x, for <option>
  • outside = o, for <option>
  • inside = i, for <option>
  • smaller = <, for <option>
  • greater = >, for <option>
tinkerforge call heart-rate-bricklet <uid> get-heart-rate-callback-threshold
Output:
  • option -- char (has symbols)
  • min -- int
  • max -- int

Returns the threshold as set by set-heart-rate-callback-threshold.

The following symbols are available for this function:

  • off = x, for option
  • outside = o, for option
  • inside = i, for option
  • smaller = <, for option
  • greater = >, for option
tinkerforge call heart-rate-bricklet <uid> set-debounce-period <debounce>
Parameters:
  • <debounce> -- int
Output:

no output

Sets the period in ms with which the threshold callback

is triggered, if the threshold

keeps being reached.

The default value is 100.

tinkerforge call heart-rate-bricklet <uid> get-debounce-period
Output:
  • debounce -- int

Returns the debounce period as set by set-debounce-period.

tinkerforge call heart-rate-bricklet <uid> enable-beat-state-changed-callback
Output:no output

Enables the beat-state-changed callback.

tinkerforge call heart-rate-bricklet <uid> disable-beat-state-changed-callback
Output:no output

Disables the beat-state-changed callback.

tinkerforge call heart-rate-bricklet <uid> is-beat-state-changed-callback-enabled
Output:
  • enabled -- bool

Returns true if the beat-state-changed callback is enabled.

Callbacks

Callbacks can be used to receive time critical or recurring data from the device:

tinkerforge dispatch heart-rate-bricklet <uid> example

The available callbacks are described below.

Note

Using callbacks for recurring events is always preferred compared to using getters. It will use less USB bandwidth and the latency will be a lot better, since there is no round trip time.

tinkerforge dispatch heart-rate-bricklet <uid> heart-rate
Output:
  • heart-rate -- int

This callback is triggered periodically with the period that is set by set-heart-rate-callback-period. The parameter is the heart rate of the sensor.

heart-rate is only triggered if the heart rate has changed since the last triggering.

tinkerforge dispatch heart-rate-bricklet <uid> heart-rate-reached
Output:
  • heart-rate -- int

This callback is triggered when the threshold as set by set-heart-rate-callback-threshold is reached. The parameter is the heart rate of the sensor.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by set-debounce-period.

tinkerforge dispatch heart-rate-bricklet <uid> beat-state-changed
Output:
  • state -- int (has symbols)

This callback provides the current heart beat state.It is called every time a heart beat is detected. The state can either be

  • 0 = Falling: The falling edge of a detected heart beat.
  • 1 = Rising: The rising edge of a detected heart beat.

The following symbols are available for this function:

  • falling = 0, for state
  • rising = 1, for state
Creative Commons Licence The content of this page is licensed under Creative Commons Attribution 3.0 Unported License.