Skip to content

Coreflux MQTT Broker

Introduction

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol ideal for IoT applications due to its low bandwidth usage and efficient data transmission. Coreflux MQTT Broker serves as a pivotal component in IoT ecosystems, enabling seamless device-to-device and device-to-server communication.

Key Features of Coreflux MQTT Broker

  • Lightweight Protocol: Ideal for constrained environments like IoT devices.
  • Efficient Data Transmission: Minimizes network bandwidth usage.
  • Reliable Message Delivery: Offers various levels of Quality of Service (QoS).
  • Secure Communication: Supports TLS/SSL for encrypted data transfer.
  • Access Control: Fine-grained permissions using the LOT (Language of Things) rules system.
  • Extensible: Supports assets, models, actions, and routes for complex IoT solutions.
  • Interoperable: Works with standard MQTT clients and tools.

The Publish-Subscribe Model

Unlike traditional client-server models, where a client communicates directly with an endpoint, MQTT uses a publish-subscribe model to decouple the producer of a message (publisher) from the consumer of a message (subscriber). This model is inherently scalable and allows for efficient information distribution.

graph LR
    broker[MQTT Broker]

    client1[Client 1 - Publisher] -->|Publishes to 'topic/a'| broker
    client2[Client 2 - Subscriber] -->|Subscribes to 'topic/a'| broker
    client3[Client 3 - Sub/Pub] -->|Publishes to 'topic/b'| broker
    client3 -->|Subscribes to 'topic/a & b'| broker
    client4[Client 4 - Publisher] -->|Publishes to 'topic/a'| broker

    broker -->|Sends 'topic/a' messages| client2
    broker -->|Sends 'topic/a' messages| client3
    broker -->|Sends 'topic/b' messages| client3

The diagram illustrates the interactions between an MQTT broker and four clients in a typical MQTT publish/subscribe scenario. Here's an explanation of what happens in this setup:

  • The MQTT Broker

    Is the central node in this communication model. It is responsible for managing the transmission of messages between the clients. The broker receives all messages from the publishers and then routes these messages to the appropriate subscribers based on the topic of the message.

  • Client 1 - Publisher

    Client 1 is configured as a publisher. It sends messages to the MQTT Broker on 'topic/a'. This means that any data or information Client 1 publishes will be under this topic.

  • Client 2 - Subscriber

    Client 2 is a subscriber to 'topic/a'. It is interested in receiving messages that are published on this topic. When Client 1 publishes a message on 'topic/a', the MQTT Broker forwards this message to Client 2.

  • Client 3 - Subscriber/Publisher

    Client 3 has a dual role; it acts both as a subscriber and a publisher. As a publisher, it sends messages to the MQTT Broker on 'topic/b'. As a subscriber, it is interested in messages from both 'topic/a' and 'topic/b'. Therefore, it receives messages from both these topics, sent by the broker. This includes messages from Client 1 and its own messages on 'topic/a', as well as its messages on 'topic/b'.

  • Client 4 - Publisher

    Similar to Client 1, Client 4 is also a publisher to 'topic/a'. It sends its messages to the MQTT Broker, which then forwards these messages to all subscribers of 'topic/a', which in this case includes Client 2 and Client 3.

  • Message Routing

    The MQTT Broker plays a crucial role in routing messages. It does not send messages to clients that have not subscribed to the relevant topic. In this scenario, messages published on 'topic/a' by Client 1 and Client 4 are received by both Client 2 and Client 3. Messages published on 'topic/b' by Client 3 are only received by Client 3 itself, as it's the only subscriber to 'topic/b'.

Topics and Brokers

  • Topics: In MQTT, messages are published on topics. A topic is a simple string that the broker uses to filter messages for each connected client.
  • Broker: The broker is the heart of the MQTT protocol. It is responsible for dispatching all messages between the sender and the appropriate receiver. Each client that publishes a message sends it to the broker, which then forwards the message to all clients subscribed to that topic.
  • Client: Any device that sends (publishes) or receives (subscribes) messages.

Quality of Service (QoS)

MQTT offers three levels of Quality of Service (QoS) for message delivery: - QoS 0 (At most once): The message is delivered at most once, or it may not be delivered at all. It's the fastest and least reliable mode. - QoS 1 (At least once): This ensures that a message is delivered at least once to the receiver. However, the message may be delivered more than once. - QoS 2 (Exactly once): This is the safest and slowest service level, where the message is guaranteed to be delivered exactly once.

Coreflux MQTT Broker Architecture

The Coreflux MQTT Broker is built on a robust architecture designed to handle IoT device communication efficiently and securely. It consists of several key components:

Core Components

  1. Message Broker Engine

    • Handles all MQTT protocol operations (Connect, Subscribe, Publish, etc.)
    • Manages topic subscriptions and message routing
    • Implements QoS mechanisms for reliable message delivery
  2. Authentication & Authorization System

    • User management with username/password authentication
    • Certificate-based authentication (TLS/mTLS)
    • Rule-based access control using LOT (Language of Things)
  3. Connectors/Routes Management System

    • Manages installable components (connectors and routes)
    • Handles connectors lifecycles (install, uninstall, start, stop)
    • Configures and monitors connectors performance
  4. LOT (Language of Things) Runtime

    • Executes models for data transformation
    • Processes actions triggered by events or schedules
    • Manages routes for inter-broker communication
  5. System Administration

    • Configuration management
    • Logging and diagnostics
    • Backup and restore capabilities

System Topics

The Coreflux broker uses special system topics (prefixed with $SYS/) for administration and monitoring:

System Topic Description
$SYS/Coreflux/Config Contains the broker configuration settings
$SYS/Coreflux/Config/users Contains the list of user accounts (accessible if the user has permission)
$SYS/Coreflux/Rules Provides the list of all defined rules in the broker
$SYS/Coreflux/Actions Contains the list of all defined actions
$SYS/Coreflux/Routes Provides the list of all defined routes
$SYS/Coreflux/Models Contains the list of all defined models
$SYS/Coreflux/Assets/# Provides status and information about installed connectors
$SYS/Coreflux/Logs/# Contains system logs and diagnostics
$SYS/Coreflux/Status/# Provides broker status information

By subscribing to these topics, you can monitor the current state of the broker, track changes to configurations, and maintain awareness of your IoT environment's components.

Broker Commands

Coreflux MQTT broker provides a comprehensive command interface that allows you to manage all aspects of the broker through MQTT messages. Commands are published to the $SYS/Coreflux/Command topic with a specific format.

For a complete reference of all available commands, please see the MQTT Broker Commands documentation.

Command Categories

The broker commands are organized into several categories:

  1. Asset Management
  2. Install, uninstall, start, and stop assets
  3. Configure asset parameters
  4. Set policies and names for assets

  5. User Management

  6. Add and remove users
  7. Change passwords and permissions
  8. Configure user settings

  9. LOT Management

  10. Add/remove rules for access control
  11. Add/remove models for data transformation
  12. Add/remove actions for event handling
  13. Add/remove routes for broker connectivity

  14. System Management

  15. Logging and diagnostics
  16. System backup and restore
  17. Status updates and monitoring

Example Commands

Here are a few example commands:

# Add a new user
-addUser operator password123

# Install an asset
-install assetName

# Add a rule
-addRule DEFINE RULE AllowPublish WITH PRIORITY 1 FOR Publish
    IF USER IS "sensor" THEN
        ALLOW
    ELSE
        DENY

MQTT in IoT Applications

MQTT has become a cornerstone in the Internet of Things (IoT) due to its simplicity, efficiency, and reliability. This lightweight messaging protocol is designed to facilitate communication in environments where resources are limited and network reliability can be inconsistent. Here are some key areas where MQTT is particularly effective in IoT:

  1. Home Automation: In smart homes, MQTT is used to control and monitor devices like lighting, heating, and security systems. Its low bandwidth requirements and real-time capabilities allow for immediate responses to user commands or sensor inputs, enhancing the user experience in home automation systems.

  2. Industrial IoT (IIoT): MQTT is widely used in industrial settings for machine-to-machine communication. It enables real-time monitoring of industrial equipment, facilitating predictive maintenance and efficient operations. MQTT's reliability is crucial in these environments, where data must be accurately and promptly communicated to prevent downtime or accidents.

  3. Agriculture: In precision agriculture, MQTT is used to connect various sensors deployed across farms to monitor conditions like soil moisture, temperature, and crop health. This data is vital for making informed decisions about irrigation, harvesting, and resource allocation.

  4. Healthcare: MQTT is employed in remote patient monitoring systems, where it transmits vital health data from wearable devices to healthcare providers. Its efficient use of bandwidth and ability to operate over unstable networks ensures continuous monitoring, which is critical for patient care.

  5. Transportation and Logistics: MQTT facilitates real-time tracking of vehicles and shipments. It helps in optimizing routes, monitoring vehicle health, and ensuring timely delivery of goods, which is essential in logistics and supply chain management.

Efficiency in IoT

  1. Low Bandwidth Usage: MQTT messages are small and lightweight, making the protocol ideal for environments where network bandwidth is limited. This is particularly important in IoT applications where devices often rely on cellular or other low-bandwidth networks.

  2. Optimized for Unreliable Networks: MQTT can maintain stable communication even over unreliable networks. This is crucial for IoT devices deployed in remote or challenging environments, where network connectivity may be intermittent.

  3. Minimal Power Consumption: The protocol's efficiency translates into lower power consumption, which is vital for battery-operated IoT devices. MQTT's ability to send concise messages without requiring constant connection helps in prolonging battery life.

  4. Flexible Quality of Service Levels: MQTT offers different levels of Quality of Service (QoS) to balance between message delivery assurance and network resource usage. This flexibility allows IoT applications to choose the appropriate QoS level based on their specific requirements.

  5. Retained Messages and Last Will: MQTT's features like retained messages and last will ensure that important information is not lost, even if the connection is temporarily disrupted. This is particularly useful in monitoring applications where data continuity is essential.

Security in Coreflux MQTT

Coreflux MQTT Broker includes several security features to protect your IoT communications:

  1. Authentication
  2. Username/password authentication
  3. X.509 certificate authentication
  4. Custom authentication plugins

  5. Transport Security

  6. TLS encryption for all communications
  7. Support for TLS 1.2 and 1.3
  8. Certificate validation and management

  9. Authorization

  10. Fine-grained access control with LOT rules
  11. Topic-level permissions
  12. User property-based authorization

  13. Network Security

  14. IP-based access restrictions
  15. Rate limiting to prevent DoS attacks
  16. Connection throttling