Configuration: Using MQTT
About
MQTT, which stands for Message Queuing Telemetry Transport, is a lightweight and efficient messaging protocol widely used in the Internet of Things (IoT) for device-to-device communication. It's designed to work under limited network bandwidth and with low-power devices, making it ideal for connecting remote sensors, mobile devices, and various small-scale gadgets to the internet.
Connecting
Connect Agent DVR to your MQTT server using the Settings menu. Once connected, you can set alert actions to publish messages to your MQTT server. See MQTT Server Settings for details.
To configure this, edit your device, navigate to the General tab and select Actions. Add an action for an alert (or other event) and choose MQTT as the action type. Here, you can specify the topic and message to post.
Specify the topic to post to (e.g., Agent/alerts) and craft your message accordingly.
Sending Commands
Agent DVR can also receive and process MQTT messages on the channel SERVER/commands channel where SERVER is your server name (displayed in the server menu which you can edit in Settings). These commands are formatted similarly to the HTTP API. Just replace /command with cmd=:
To turn all devices on: cmd=allon.
To take a photo on a specific device: cmd=snapshot&ot=2&oid=1.
Using mosquitto, you can send a command like (replace SERVER with your server name): mosquitto_pub -t 'SERVER/commands' -m 'cmd=record&ot=2&oid=1'
.
Agent DVR will execute the command and send a JSON response to the SERVER/responses channel.
Auto MQTT
Agent DVR features an automatic MQTT configuration that sends default events, statuses, and usage statistics. To activate this feature, enable the "MQTT Events" option on the General tab while editing a device.
This configuration includes flags for topics such as motion, connected, alert, and recording.
Troubleshooting
If you encounter frequent disconnects and reconnects in MQTT, it typically indicates that the Client ID specified in Server Settings under MQTT is being used by multiple clients. It's important to ensure that each client connected to MQTT has a unique Client ID.