MQTT - Motion Detector Bricklet

This is the description of the MQTT API bindings for the Motion Detector Bricklet. General information and technical specifications for the Motion Detector 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).

Callback

Download (example-callback.txt)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Change XYZ to the UID of your Motion Detector Bricklet

setup:
    # Handle incoming motion detected callbacks
    subscribe to tinkerforge/callback/motion_detector_bricklet/XYZ/motion_detected
    publish '{"register": true}' to tinkerforge/register/motion_detector_bricklet/XYZ/motion_detected # Register motion_detected callback

    # Handle incoming detection cycle ended callbacks
    subscribe to tinkerforge/callback/motion_detector_bricklet/XYZ/detection_cycle_ended
    publish '{"register": true}' to tinkerforge/register/motion_detector_bricklet/XYZ/detection_cycle_ended # Register detection_cycle_ended callback

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 member _ERROR. It is published on the corresponding response topic: .../response/... for .../request/... and .../callback/... for .../register/....

Basic Functions

request/motion_detector_bricklet/<UID>/get_motion_detected
Request:
  • empty payload
Response:
  • motion – Type: int, Range: See symbols

Returns 1 if a motion was detected. How long this returns 1 after a motion was detected can be adjusted with one of the small potentiometers on the Motion Detector Bricklet, see here.

There is also a blue LED on the Bricklet that is on as long as the Bricklet is in the "motion detected" state.

The following symbols are available for this function:

For motion:

  • "not_detected" = 0
  • "detected" = 1

Advanced Functions

request/motion_detector_bricklet/<UID>/set_status_led_config
Request:
  • config – Type: int, Range: See symbols, Default: 2
Response:
  • no response

Sets the status led configuration.

By default the status LED turns on if a motion is detected and off is no motion is detected.

You can also turn the LED permanently on/off.

The following symbols are available for this function:

For config:

  • "off" = 0
  • "on" = 1
  • "show_status" = 2

New in version 2.0.1 (Plugin).

request/motion_detector_bricklet/<UID>/get_status_led_config
Request:
  • empty payload
Response:
  • config – Type: int, Range: See symbols, Default: 2

Returns the configuration as set by request/motion_detector_bricklet/<UID>/set_status_led_config.

The following symbols are available for this function:

For config:

  • "off" = 0
  • "on" = 1
  • "show_status" = 2

New in version 2.0.1 (Plugin).

request/motion_detector_bricklet/<UID>/get_identity
Request:
  • empty payload
Response:
  • uid – Type: string, Length: up to 8
  • connected_uid – Type: string, Length: up to 8
  • position – Type: char, Range: ["a" to "h", "z"]
  • hardware_version – Type: [int, ...], Length: 3
    • 0: major – Type: int, Range: [0 to 255]
    • 1: minor – Type: int, Range: [0 to 255]
    • 2: revision – Type: int, Range: [0 to 255]
  • firmware_version – Type: [int, ...], Length: 3
    • 0: major – Type: int, Range: [0 to 255]
    • 1: minor – Type: int, Range: [0 to 255]
    • 2: revision – Type: int, Range: [0 to 255]
  • device_identifier – Type: int, Range: [0 to 216 - 1]
  • _display_name – Type: 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', '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 Motion Detector's name in a human readable form.

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/motion_detector_bricklet/<UID>/motion_detected
Register Request:
  • register – Type: bool
Callback Response:
  • empty payload

A callback can be registered for this event by publishing to the .../register/motion_detector_bricklet/<UID>/motion_detected[/<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/motion_detector_bricklet/<UID>/motion_detected[/<SUFFIX>] topic for each registered suffix.

This callback is called after a motion was detected.

register/motion_detector_bricklet/<UID>/detection_cycle_ended
Register Request:
  • register – Type: bool
Callback Response:
  • empty payload

A callback can be registered for this event by publishing to the .../register/motion_detector_bricklet/<UID>/detection_cycle_ended[/<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/motion_detector_bricklet/<UID>/detection_cycle_ended[/<SUFFIX>] topic for each registered suffix.

This callback is called when the detection cycle ended. When this callback is called, a new motion can be detected again after approximately 2 seconds.