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 payload to an from the MQTT bindings is in the 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/motion_detector_bricklet/<UID>/get_motion_detected
Response payload:
 
  • motion -- int (has 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:

  • "NotDetected" = 0
  • "Detected" = 1

Advanced Functions

request/motion_detector_bricklet/<UID>/set_status_led_config
Request payload:
 
  • config -- int (has symbols)

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
  • "ShowStatus" = 2

New in version 2.0.1 (Plugin).

request/motion_detector_bricklet/<UID>/get_status_led_config
Response payload:
 
  • config -- int (has symbols)

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
  • "ShowStatus" = 2

New in version 2.0.1 (Plugin).

request/motion_detector_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 Motion Detector's name in a human readable form.

Callback Configuration Functions

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
Request payload:
 
  • register -- bool

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
Request payload:
 
  • register -- bool

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.