MQTT - Hall Effect Bricklet

This is the description of the MQTT API bindings for the Hall Effect Bricklet. General information and technical specifications for the Hall Effect Bricklet are summarized in its hardware description.

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

Examples

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

Simple

Download (example-simple.txt)

1
2
3
4
5
6
# Change XYZ to the UID of your Hall Effect Bricklet

setup:
    # Get current edge count without reset
    subscribe to tinkerforge/response/hall_effect_bricklet/XYZ/get_edge_count
    publish '{"reset_counter": false}' to tinkerforge/request/hall_effect_bricklet/XYZ/get_edge_count

Callback

Download (example-callback.txt)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Change XYZ to the UID of your Hall Effect Bricklet

setup:
    # Handle incoming edge count callbacks
    subscribe to tinkerforge/callback/hall_effect_bricklet/XYZ/edge_count
    publish '{"register": true}' to tinkerforge/register/hall_effect_bricklet/XYZ/edge_count # Register edge_count callback
    
    # Set period for edge count callback to 0.05s (50ms)
    # Note: The edge count callback is only called every 0.05 seconds
    #       if the edge count has changed since the last call!
    publish '{"period": 50}' to tinkerforge/request/hall_effect_bricklet/XYZ/set_edge_count_callback_period

API

All published payloads to and from the MQTT bindings are in JSON format.

If an error occures, the bindings publish a JSON object containing the error message as attribute "_ERROR". It is published on the corresponding response topic: .../response/... for .../request/... and .../callback/... for .../register/....

Basic Functions

request/hall_effect_bricklet/<UID>/get_value
Response payload:
 
  • value -- bool

Returns true if a magnetic field of 35 Gauss (3.5mT) or greater is detected.

request/hall_effect_bricklet/<UID>/get_edge_count
Request payload:
 
  • reset_counter -- bool
Response payload:
 
  • count -- int

Returns the current value of the edge counter. You can configure edge type (rising, falling, both) that is counted with request/hall_effect_bricklet/<UID>/set_edge_count_config.

If you set the reset counter to true, the count is set back to 0 directly after it is read.

Advanced Functions

request/hall_effect_bricklet/<UID>/set_edge_count_config
Request payload:
 
  • edge_type -- int (has symbols)
  • debounce -- int

The edge type parameter configures if rising edges, falling edges or both are counted. Possible edge types are:

  • 0 = rising (default)
  • 1 = falling
  • 2 = both

A magnetic field of 35 Gauss (3.5mT) or greater causes a falling edge and a magnetic field of 25 Gauss (2.5mT) or smaller causes a rising edge.

If a magnet comes near the Bricklet the signal goes low (falling edge), if a magnet is removed from the vicinity the signal goes high (rising edge).

The debounce time is given in ms.

Configuring an edge counter resets its value to 0.

If you don't know what any of this means, just leave it at default. The default configuration is very likely OK for you.

Default values: 0 (edge type) and 100ms (debounce time)

The following symbols are available for this function:

for edge_type:

  • "Rising" = 0
  • "Falling" = 1
  • "Both" = 2
request/hall_effect_bricklet/<UID>/get_edge_count_config
Response payload:
 
  • edge_type -- int (has symbols)
  • debounce -- int

Returns the edge type and debounce time as set by request/hall_effect_bricklet/<UID>/set_edge_count_config.

The following symbols are available for this function:

for edge_type:

  • "Rising" = 0
  • "Falling" = 1
  • "Both" = 2
request/hall_effect_bricklet/<UID>/get_identity
Response payload:
 
  • uid -- string
  • connected_uid -- string
  • position -- string
  • hardware_version -- [int,int,int]
  • firmware_version -- [int,int,int]
  • device_identifier -- int (has symbols)
  • _display_name -- string

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. If symbolic output is not disabled, the device identifier is mapped to the corresponding name in the format used in topics.

The display name contains the Hall Effect's name in a human readable form.

Callback Configuration Functions

request/hall_effect_bricklet/<UID>/set_edge_interrupt
Request payload:
 
  • edges -- int

Sets the number of edges until an interrupt is invoked.

If edges is set to n, an interrupt is invoked for every n-th detected edge.

If edges is set to 0, the interrupt is disabled.

Default value is 0.

request/hall_effect_bricklet/<UID>/get_edge_interrupt
Response payload:
 
  • edges -- int

Returns the edges as set by request/hall_effect_bricklet/<UID>/set_edge_interrupt.

request/hall_effect_bricklet/<UID>/set_edge_count_callback_period
Request payload:
 
  • period -- int

Sets the period in ms with which the register/hall_effect_bricklet/<UID>/edge_count callback is triggered periodically. A value of 0 turns the callback off.

The register/hall_effect_bricklet/<UID>/edge_count callback is only triggered if the edge count has changed since the last triggering.

The default value is 0.

request/hall_effect_bricklet/<UID>/get_edge_count_callback_period
Response payload:
 
  • period -- int

Returns the period as set by request/hall_effect_bricklet/<UID>/set_edge_count_callback_period.

Callbacks

Callbacks can be registered to receive time critical or recurring data from the device. The registration is done with the corresponding .../register/... topic and an optional suffix. This suffix can be used to deregister the callback later.

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.

register/hall_effect_bricklet/<UID>/edge_count
Request payload:
 
  • register -- bool
Response payload:
 
  • count -- int
  • value -- bool

A callback can be registered for this event by publishing to the .../register/hall_effect_bricklet/<UID>/edge_count[/<SUFFIX>] topic with the payload "true". An added callback can be removed by publishing to the same topic with the payload "false". To support multiple (de)registrations, e.g. for message filtering, an optional suffix can be used.

If the callback is triggered, a message with it's payload is published under the corresponding .../callback/hall_effect_bricklet/<UID>/edge_count[/<SUFFIX>] topic for each registered suffix.

This callback is triggered periodically with the period that is set by request/hall_effect_bricklet/<UID>/set_edge_count_callback_period. The callback payload members are the current count and the current value (see request/hall_effect_bricklet/<UID>/get_value and request/hall_effect_bricklet/<UID>/get_edge_count).

The register/hall_effect_bricklet/<UID>/edge_count callback is only triggered if the count or value changed since the last triggering.