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.
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.
Agent DVR can also receive and process MQTT messages on the channel Agent/commands. These commands are formatted similarly to the HTTP API.
For example, to turn all devices on: cmd=allon.
Using mosquitto, you can send a command like:
mosquitto_pub -t 'Agent/commands' -m 'cmd=record&ot=2&oid=1'.
Agent DVR will execute the command and send a JSON response to the Agent/responses channel.
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.
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.