Skip to content

Enhancing Axis Network Camera Capabilities with MQTT and HiveMQ

by Kamiel Straatman
20 min read

In the realm of smart technology, the convergence of edge computing and artificial intelligence has unlocked new possibilities for devices like network cameras. These cameras, equipped with onboard analysis capabilities, can analyze video data locally, reducing unwanted privacy intrusions and solving bandwidth requirements. 

When combined with the MQTT communication protocol, Axis network cameras become powerful tools for real-time data processing and efficient information exchange. Let's delve into how the marriage of Axis Camera with ‘Intelligence on the Edge’ and HiveMQ MQTT communication is revolutionizing the capabilities of network cameras.

Intelligence on the Edge Empowers Axis Network Cameras

Traditionally, network cameras relied on human evaluation (watching all these screens)  or centralized platforms for data processing and analysis. However, this approach often resulted in latency issues, privacy concerns, and increased bandwidth usage. Intelligence on the Edge addresses these challenges by enabling cameras to perform real-time analytics locally on camera; at the "edge" of the network.

With onboard real-time analytics capabilities, Axis network cameras can detect objects, analyze traffic behavior, measure environmental values, and perform other complex tasks without relying on external servers. Transmitting just this ‘analyzed’ data by means of MQTT not only reduces latency and allows for immediate ingestion or action but also enhances privacy by minimizing the need to transmit sensitive data over the network.

MQTT: Lightweight and Efficient IoT Communication

MQTT is a lightweight messaging protocol designed for constrained devices and low-bandwidth, high-latency, or unreliable networks. It follows a publish-subscribe model, where clients (publishers) send messages to a central broker, which then distributes them to interested clients (subscribers). This asynchronous communication pattern makes MQTT ideal for IoT (Internet of Things) applications, including smart cameras.

By leveraging MQTT, IP cameras equipped with edge AI can efficiently communicate with other devices, servers, or cloud platforms. They can publish data, such as detected events or analytics results, to MQTT topics, which can be subscribed to by other devices or applications for further processing or action. Also the cameras can ‘overlay’ received MQTT data in their video feeds. Immediate, on-screen reporting is facilitated in this way.

Advantages of MQTT for Network Cameras with Intelligence on the Edge

  • Low Latency: MQTT's lightweight protocol and asynchronous communication model minimize latency, enabling real-time data exchange between cameras and other devices.

  • Bandwidth Efficiency: MQTT's small message size and efficient queuing mechanism reduce bandwidth consumption, making it suitable for resource-constrained networks.

  • Scalability: MQTT's publish-subscribe architecture allows for seamless scalability, enabling cameras to communicate with multiple subscribers without increasing complexity.

  • Reliability: MQTT's built-in features, such as persistent sessions and Quality of Service (QoS) levels, ensure reliable message delivery even in unreliable network conditions.

  • Security: MQTT supports TLS (Transport Layer Security) encryption and authentication mechanisms, ensuring secure communication between cameras and other devices or servers.

Applications of IP Cameras with Intelligence on the Edge and MQTT

  • Smart Surveillance: IP cameras equipped with edge AI can detect and analyze events in real-time, such as intrusions, accidents, or anomalies, and publish relevant data to MQTT topics for immediate action by security personnel or automated systems.

  • Smart Cities: In smart city initiatives, IP cameras can monitor traffic flow, detect environmental hazards, do Automatic Numberplate recognition (ANPR), or analyze crowd behavior using edge AI algorithms. The collected data can be communicated via MQTT to city management systems for traffic optimization, emergency response, or urban planning.

  • Industrial IoT: In industrial settings, IP cameras with edge AI can monitor equipment health, detect defects, or track inventory in real-time. By publishing data to MQTT topics, they enable predictive maintenance, quality control, and inventory management systems to react promptly to detected events.

So, HiveMQ MQTT Loves Axis ‘Intelligence on the Edge’

The combination of real-time on-camera analytics and MQTT communication is transforming network cameras from passive observers to active participants in the IoT ecosystem. By processing data locally and communicating efficiently with other devices or systems, these cameras enable real-time decision-making, enhance security, and drive efficiency across various applications. As edge computing and IoT technologies continue to evolve, IP cameras will play an increasingly critical role in shaping the future of smart environments and connected ecosystems.

A Practical Approach to Using HiveMQ MQTT Broker

In the following sections, we will implement an Axis camera solution equipped with ‘Intelligence on the Edge’. The camera streams its video over IP to a remote viewing station. It also communicates data, making use of a HiveMQ MQTT Broker equipped with HiveMQ’s Data Hub payload processing. The then-processed data will be fed both in-stream to the network viewing station (with the help of the camera) as well as in a Grafana dashboard and its associated databases.

The setup is as depicted below:

A Practical Approach to Using HiveMQ MQTT Broker with Axis Network CamerasTo elaborate a bit more on the above image, in the upper left, we see the camera itself streaming video-data to a conventional, network-based viewing station. The camera is able to communicate via the same network to the MQTT broker in order to publish MQTT messages. It does that by sending detailed JSON-based MQTT messages to specific ‘Topics’ whenever specific, on-camera detected events occur.

These on-camera detected events can be very diverse — think line crossing, loitering, number plate recognition, traffic detection and many more. 

All these detections will generate detailed MQTT-based messages when occurring, ready for further processing. 

The scalable HiveMQ Broker system will process these camera MQTT messages and prepare them for further upstream processing by making use of the built-in Data Hub facility. Subsequently, the processed MQTT messages are republished on a different topic, can be stored in databases or trigger external alarms, and can be displayed as events (counters) on various real-time dashboards. 

As an extra the Axis camera is also able, by subscribing to the output MQTT topics, to blend in the processed MQTT data in its streams. This enables all event-driven data to be seen in the network viewing stations.

Quick Demo Setup of MQTT Broker on Axis Camera

To get started, we need to set up an MQTT broker on our network. The HiveMQ Broker is extremely scalable and reliable and in its full version. A trial license is restricted to 25 client connections and is freely downloadable for testing. As hardware requirements are pretty low for testing, please follow the instructions here to set it up.

To set up the Axis network camera, follow the instructions of your particular camera model. We assume for the rest of this demo that the camera and the broker are enabled and you can log into their respective web interfaces from a single IP network.

First, we start by connecting the Axis network camera MQTT client to the HiveMQ Broker. This can be done in the systems/MQTT section of the Axis main menu. For a default broker install, all that's needed is to fill in the correct broker IP address, MQTT over TCP all on port 1883.

Slide the Connect toggle to the right and make sure you’re connected.

Connecting the Axis network camera MQTT client to the HiveMQ Broker.Now we can select one of Axis’ many analytics applications to do the actual detection. In this case we use the ‘line cross counter’, a module within the standard object analytics package.

From the left main menu, select Analytics/Axis Object Analysis/Open. This will open a new browser window where you can add scenarios. Add a new ‘ Crossline counting’ scenario. Once added, open it. Give it a proper name (eg) and configure it more closely:

Connecting the Axis network camera MQTT client to the HiveMQ BrokerAs depicted, you can draw a line on which selectable objects (Humans, Vehicles) can be counted when they cross. Other options, such as ‘Reset at midnight’ can make sense for your case as well.

Once defined, head back to the systems/MQTT section in the previous window.

Now that the object analysis is defined, we need to add a response to this line crossing event. This response will be in the form of a published MQTT message that will contain all the data associated with the event.

In order to do so, scroll down to the lower part of the MQTT definition window and select ‘MQTT publications’. Check all the checkboxes and select ‘Add condition’. 

Connecting the Axis network camera MQTT client to the HiveMQ Broker.In this config, select as condition the ‘Object Analytics: Crossline’ as you have just defined and click ‘add’. Note down the actual topic name because you need it later.

Our first setup is OK now. Once you cross the line (or hit the ‘Test events’ button in the line crossing scenario window) an Axis standard formatted MQTT message is sent from the camera to the broker. You can check this by simply subscribing to the ‘Axis/#’ topic. 

Please check to make sure your camera and MQTT setup is working OK.

Process the Data and Visualize

Once the Axis network camera is publishing MQTT data, we can concentrate on the actual payload of the message sent. We need to transform that into a format we can work with. In this demo case we receive a pretty complex JSON data structure from the camera module, and we need as output only the ‘counted today’ value. So we make use of HiveMQ's unique Data Hub facility to process this incoming data and rework it to the much more simple format we need.

We receive the following JSON structure on topic "axis:Cam..enario1" :

{ "topic": "axis:CameraApplicationPlatform/ObjectAnalytics/Device1Scenario1",
  "timestamp": 1718193886191,
  "serial": "B8A44F284388",
  "message": {
      "source": {},
      "key": {},
      "data": {
        "reason": "human",
        "resetTime": "2024-06-12T11:59:14Z",
        "totalHuman": "12",
        "total": "12",
        "scenario": "Crossline cnt 1"
      }
}

We transform this to the following JSON structure on topic "axis-data" :

{
    "linecrossings": "13",
    "linecrossnumber": 13
}

HiveMQ Data Hub

In order to do this JSON simplification, we rely on HiveMQ’s Data Hub for which you can find all info in the Data Hub documentation.

For making this setup easy, we already defined all the user schemas, scripts, and policies needed to define Data Hub. Please refer to this GitHub link to install these on the broker.

Before uploading the data to Data Hub, make sure that you alter the CheckLineCrossSchema.json file in line 4 of the data policy file so the topic matches the one you wrote down when creating the MQTT event on the camera: 

It should look like this (but with your serial etc.):

"topicFilter": "axis/B8A44F284388/event/tns:axis/CameraApplicationPlatform/ObjectAnalytics/#"

Now execute the following MQTT commands (on your broker in tools/mqtt-cli directory) in order to create all the resources for Data Hub:

mqtt hivemq schema create --id linecrossing --type json --file linecrossing.json
mqtt hivemq schema create --id linecrosswithnumber --type json --file  linecrosswithnumber.json
mqtt hivemq script create --id=extract_count --file=extract_count.js --type=transformation
mqtt hivemq data-policy create --file=CheckLineCrossSchema.json

Now Data Hub is set up (check in the HiveMQ web interface). You can recheck the output of the broker by subscribing to the ‘axis-data/#’ topic. You will notice that the published data is far more simple and readable.

MQTT in the Video Stream

Now that we have a simplified data model being published we can let the camera subscribe to that and overlay it on the video stream.

Once again we need to go to the systems/MQTT section where at the bottom of the screen a MQTT overlay tab is present; select that. Add an overlay modifier by clicking the plus sign and use the axis-data as topic and linecrossings as data field.

Save it, and you will see the subscription and the overlay modifiers (XMP?, #XMD?). Note these down and then click the ‘Go to Overlays button. 

MQTT in the Video StreamOnce in the Overlays section, add an overlay by selecting the plus sign with ‘text’ in the selection box. Configure text box as needed and include the #XMD? tag where the MQTT transported ‘linecrossings’ value should be displayed.

Overlays in AxisPosition the overlay on the correct position on the video stream by dragging it. The MQTT value may not be visible immediately.

If you now revert back to the main menu and select Stream, you see the full network camera picture along with overlays displaying the latest received MQTT value for the linecross value.

Integrating Axis Network Camera with MQTT

Conclusion

In conclusion, network cameras represent more than just tools for surveillance; they are powerful sensors capable of collecting diverse types of data for various applications. 

Integrating Axis Network Camera with MQTT and HiveMQMQTT is the most efficient protocol to communicate events from Axis-based analysis modules to upstream systems for data retention, visualization, and analysis. The wide range of data processing capabilities in Data Hub and broad range of connectivity options available on the HiveMQ Broker only extend this range of possibilities. Give HiveMQ a try today.

Try HiveMQ for Free

Kamiel Straatman

Kamiel is part of Solutions Engineering team at HiveMQ. Based out of the Netherlands, Kamiel is an IoT enthusiast with many years of experience working in the data center domain and Azure & AWS cloud architectures. He specializes in ICT infrastructure consulting with a strong focus on cloud, cloud automation, datacenter transformation, security, storage and networking.

  • Contact Kamiel Straatman via e-mail
HiveMQ logo
Review HiveMQ on G2