Skip to content

MQTT and GATT Integration Overview

MQTT

MQTT, which stands for Message Queuing Telemetry Transport, is a lightweight, open-source messaging protocol designed for low-bandwidth, high-latency, or unreliable networks. It was originally developed by IBM in the late 1990s and later became an open standard widely used in the Internet of Things (IoT) and other scenarios.

Key Features of MQTT:

  1. Publish/Subscribe Model:
    • MQTT follows a publish/subscribe messaging pattern. Devices (clients) communicate through a central broker.
    • Publishers (senders) publish messages to specific topics.
    • Subscribers (receivers) subscribe to topics of interest.
  2. Lightweight:
    • The protocol is designed to be lightweight and efficient, making it suitable for resource-constrained devices and networks.
  3. Quality of Service (QoS) Levels:
    • MQTT supports different levels of message delivery assurance:
      • QoS 0: At most once delivery (fire and forget).
      • QoS 1: At least once delivery (guaranteed delivery but may be duplicated).
      • QoS 2: Exactly once delivery (highest level of assurance).
  4. Retained Messages:
    • The broker can retain the last message sent on a particular topic. When a new subscriber joins, it immediately receives the last retained message for the topic.

Adoption as a Protocol Framework:

To adopt MQTT as the basic protocol framework for all devices in your company:

  1. Broker Setup:
    • Establish an MQTT broker, which acts as a central hub for all communication.
    • Several open-source and commercial MQTT brokers are available, such as Mosquitto, HiveMQ, and EMQX.
  2. Client Integration:
    • Integrate MQTT client libraries into your devices. There are libraries available for various programming languages.
  3. Topic Design:
    • Design a clear and hierarchical topic structure that reflects the different types of information your devices need to communicate.
  4. Security Measures:
    • Implement security measures, including authentication and encryption, to secure communication between devices and the broker.
  5. Scalability:
    • Ensure that the MQTT infrastructure is scalable to accommodate the growing number of devices in your company.

Applications:

  1. IoT Communication:
    • MQTT is widely used in IoT scenarios for efficient and scalable communication between devices.
  2. Home Automation:
    • MQTT is commonly used in smart home systems to enable communication between various devices, such as sensors, actuators, and controllers.
  3. Industrial Automation:
    • In industrial settings, MQTT facilitates communication between sensors, programmable logic controllers (PLCs), and other devices.
  4. Telemetry and Remote Monitoring:
    • MQTT is suitable for applications where telemetry data needs to be transmitted and monitored remotely.
  5. Mobile Applications:
    • MQTT is used in mobile applications for real-time data exchange, push notifications, and messaging.

BLE Overview:

  • BLE is a wireless communication standard: It operates in the 2.4 GHz ISM (Industrial, Scientific, and Medical) band, the same as classic Bluetooth, but with a focus on low power consumption.
  • Peripheral and Central Roles: BLE devices typically have one of two roles: peripheral or central. Peripherals provide data or services, while centrals initiate communication and interact with peripherals.
  • Low Power: BLE is designed for low energy consumption, allowing devices to operate for extended periods on small batteries.
  • Short Range: BLE has a relatively short range, typically up to 100 meters or less, making it suitable for personal area networks.

BLE Protocol Stack:

The BLE protocol stack is divided into layers, each with specific functions:

  1. Physical Layer (PHY): This layer handles the physical transmission and reception of data. It defines the radio frequencies, modulation, and transmission power levels.
  2. Link Layer: The Link Layer manages the establishment and maintenance of connections between devices. It handles advertising, connection initiation, and data packet transmission.
  3. Host Controller Interface (HCI): This layer provides a standardized interface between the Bluetooth hardware and the higher-level protocol stack. It allows for control and configuration of the Bluetooth radio.
  4. Logical Link Control and Adaptation Protocol (L2CAP): L2CAP provides a multiplexing and segmentation layer for data packets. It can handle multiple logical connections simultaneously.
  5. Attribute Protocol (ATT): ATT defines a simple protocol for reading and writing attributes, which represent data on the device. This is where GATT comes into play.
  6. Generic Attribute Profile (GATT): GATT builds on top of ATT and defines the structure and behavior of attributes, services, and characteristics. It provides a framework for organizing and accessing data on a BLE device. GATT allows devices to expose their capabilities and data in a standardized way.
  7. Security Manager (SM): SM handles authentication and encryption, ensuring secure communication between devices.

Borrowing GATT Concept for MQTT Broker's GATT:

To adapt the concept of GATT for an MQTT broker, you would need to create an abstraction layer that maps MQTT concepts to GATT concepts. Here's a simplified explanation:

  1. Services: In GATT, services represent functionalities or features of a peripheral device. In your MQTT broker's GATT, services could represent different aspects of the MQTT broker's functionality, such as message publishing, subscribing, authentication, and configuration.
  2. Characteristics: Characteristics in GATT represent individual data items within a service. In your MQTT broker's GATT, characteristics could correspond to specific actions or data points related to MQTT communication. For example, you might have characteristics for publishing messages, subscribing to topics, and managing client connections.
  3. Descriptors: Descriptors provide additional information about characteristics. In your MQTT broker's GATT, descriptors could provide metadata about MQTT clients, such as their client IDs, connection status, and subscriptions.
  4. Client-Server Interaction: Just as in GATT, your MQTT broker's GATT would involve client-server interactions. Clients (IOT) could connect to the MQTT broker's GATT, discover services and characteristics, and perform actions like publishing or subscribing to MQTT topics.
  5. Profiles: You could define profiles for different MQTT use cases or device types within your MQTT broker's GATT. These profiles would specify the services, characteristics, and descriptors required for those specific use cases.

MQTT and GATT borrowing concept

Untitled

MQTT/GATT Arch plantUml code (2)

Lets break down the diagram :

  1. !define: These lines are defining shortcuts for diagram elements. RECTANGLE, ELLIPSE, ACTOR, DATABASE, and FOLDER are aliases for different types of diagram elements that will be used later in the diagram.
  2. RECTANGLE Broker: This line creates a rectangle-shaped element labeled "Broker," which represents the MQTT broker in the diagram.
  3. ELLIPSE Topic: This line creates an ellipse-shaped element labeled "Topic," representing the MQTT topics.
  4. ACTOR Publisher: This creates an actor-shaped element labeled "Publisher," representing the MQTT publishers.
  5. ACTOR Subscriber: This creates another actor-shaped element labeled "Subscriber," representing the MQTT subscribers.
  6. FOLDER Service: This creates a folder-shaped element labeled "Service," representing the GATT services.
  7. DATABASE Characteristic: This creates a database-shaped element labeled "Characteristic," representing the GATT characteristics within the services.
  8. RECTANGLE Descriptor: This creates a rectangle-shaped element labeled "Descriptor," representing the GATT descriptors that further describe characteristics.
  9. Connections: The lines that follow (with arrows) represent the connections or relationships between these elements:
    • The Broker "manages" the Topic.
    • The Publisher "publishes to" the Topic.
    • The Subscriber "subscribes to" the Topic.
    • The Topic "maps to" the Service (illustrating the conceptual link between MQTT topics and GATT services).
    • The Service "includes" the Characteristic.
    • The Characteristic is "described by" the Descriptor.
  10. note: The note directives add descriptive text next to the relevant diagram elements. They provide additional information about each component's role within the system.

GATT

GATT stands for Generic Attribute Profile, and it is a protocol used in the Bluetooth Low Energy (BLE) technology stack. GATT defines a framework for how two BLE devices, typically a central device (like a smartphone or computer) and a peripheral device (like a sensor or wearable device), exchange data and communicate with each other.

Key features and concepts of GATT include:

  1. Attributes: GATT organizes data into attributes, which represent pieces of information that can be read or written. Attributes can include things like device information, sensor data, or control settings.
  2. Services: Services in GATT group related attributes together. Services define a collection of attributes that represent a specific functionality or feature of the peripheral device. For example, a heart rate monitor might have a "Heart Rate Service" that includes attributes for heart rate measurement.
  3. Characteristics: Characteristics are individual data items within a service. Each characteristic has properties that define how it can be accessed, such as read, write, or notify. For example, a temperature sensor service might have a characteristic for "Temperature Measurement" that can be read to retrieve the current temperature.
  4. Descriptors: Descriptors provide additional information about a characteristic's value or behavior. They can include things like human-readable descriptions, units of measurement, or client configuration settings. For example, a descriptor might specify how often a temperature measurement characteristic should send notifications.
  5. Client-Server Interaction: GATT interactions typically involve a client (central device) and a server (peripheral device). The client can discover services and characteristics on the server, read or write characteristic values, and subscribe to notifications when characteristics change.
  6. Profiles: GATT profiles are predefined sets of services, characteristics, and descriptors that define specific use cases or device types. For example, the Bluetooth Heart Rate Profile defines the services and characteristics needed for heart rate monitoring devices.

Summary

MQTT

  • Introduction: An overview of MQTT, its history, and its importance in IoT and other applications.
  • Key Features: Key attributes like the publish/subscribe model, lightweight design, QoS levels, and retained messages.
  • Adoption as a Protocol Framework: Steps to adopt MQTT within an organization, including broker setup, client integration, and scalability.
  • Applications: Various industries and use cases, such as IoT, home automation, and telemetry.

GATT

  • Introduction: An overview of GATT and its role in Bluetooth Low Energy (BLE) communication.
  • Key Features: Discussion on attributes, services, characteristics, descriptors, and the client-server interaction model in GATT.
  • Application in BLE: Overview of the role of GATT in facilitating data exchange between BLE devices.

MQTT and GATT Integration:

  • Borrowing GATT Concepts for MQTT Broker: Explanation of how concepts from GATT, such as services, characteristics, and descriptors, can be adapted to MQTT brokers for enhanced functionality.
  • Diagram Breakdown: A detailed explanation of the architecture of MQTT and GATT integration, emphasizing the relationship between MQTT topics, services, and the various elements like publisher, subscriber, and broker.