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.
The example code below is Public Domain (CC0 1.0).
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
|
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
|
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 member _ERROR
.
It is published on the corresponding response topic: .../response/...
for .../request/...
and .../callback/...
for .../register/...
.
request/
hall_effect_bricklet/
<UID>/
get_value
¶Request: |
|
---|---|
Response: |
|
Returns true if a magnetic field of 3.5 millitesla or greater is detected.
request/
hall_effect_bricklet/
<UID>/
get_edge_count
¶Request: |
|
---|---|
Response: |
|
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.
request/
hall_effect_bricklet/
<UID>/
set_edge_count_config
¶Request: |
|
---|---|
Response: |
|
The edge type parameter configures if rising edges, falling edges or both are counted. Possible edge types are:
A magnetic field of 3.5 millitesla or greater causes a falling edge and a magnetic field of 2.5 millitesla 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).
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.
The following symbols are available for this function:
For edge_type:
request/
hall_effect_bricklet/
<UID>/
get_edge_count_config
¶Request: |
|
---|---|
Response: |
|
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:
request/
hall_effect_bricklet/
<UID>/
get_identity
¶Request: |
|
---|---|
Response: |
|
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', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.
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.
request/
hall_effect_bricklet/
<UID>/
set_edge_interrupt
¶Request: |
|
---|---|
Response: |
|
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.
request/
hall_effect_bricklet/
<UID>/
get_edge_interrupt
¶Request: |
|
---|---|
Response: |
|
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: |
|
---|---|
Response: |
|
Sets the period 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.
request/
hall_effect_bricklet/
<UID>/
get_edge_count_callback_period
¶Request: |
|
---|---|
Response: |
|
Returns the period as set by request/hall_effect_bricklet/<UID>/set_edge_count_callback_period
.
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
¶Register Request: |
|
---|---|
Callback Response: |
|
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.