MQTT Echo Application
Overview
This NetBurner MQTT Echo application demonstrates advanced MQTT client functionality by subscribing to a specific topic and echoing received messages to the serial console. The application uses low-level MQTT protocol handling to provide detailed message processing capabilities.
Features
- MQTT Topic Subscription: Automatically subscribes to
testTopic/HelloWorld
- Message Echo: Outputs all received messages to the serial console
- Low-Level Protocol Handling: Uses file descriptors and
readall/writeall functions for direct message processing
- Connection Management: Handles MQTT connection establishment and monitoring
- Property Handling: Processes MQTT message properties (metadata) appropriately
- Error Handling: Manages subscription termination and connection failures
Architecture
Key Components
- ConfiguredClient: MQTT client configured through the NetBurner configuration system
- TopicHandler: Low-level message handler that processes incoming MQTT Publish messages
- EchoSubscriber: Callback function that handles message reception and console output
Message Processing Flow
- Application establishes connection to MQTT broker
- Subscribes to the configured topic (
testTopic/HelloWorld)
- Receives MQTT Publish messages through file descriptor interface
- Processes message properties (skips them in this implementation)
- Reads message payload and outputs to serial console
- Handles connection status changes and subscription termination
Configuration
The MQTT client configuration (broker URI, username, password, certificates) is managed through the NetBurner configuration system rather than hardcoded values.
Default Settings
#define MQTT_TOPIC_NAME "testTopic/HelloWorld"
#define MQTT_PUBLISH_MSG "Hello World"
Technical Details
File Descriptor Interface
This application demonstrates the low-level MQTT interface using:
readall() function for reading message data
writeall() function for console output
- Direct file descriptor manipulation for message processing
Message Structure Handling
The application properly handles MQTT Publish message structure:
- Properties Section: MQTT v5.0 properties for metadata (skipped in this example)
- Payload Section: Actual message content (echoed to console)
Connection Management
- Waits for active network connection (5-second timeout)
- Monitors MQTT connection status continuously
- Automatically attempts subscription when connection is established
- Handles connection failures gracefully
Usage
- Network Setup: Ensure the device is connected to a network
- MQTT Configuration: Configure MQTT broker settings through NetBurner config
- Deploy Application: Flash the application to the NetBurner device
- Monitor Output: Watch the serial console for received messages
- Test Messaging: Publish messages to
testTopic/HelloWorld from any MQTT client
Console Output
The application provides detailed console output including:
- Connection status updates
- Subscription confirmation with handler ID
- Received message topic information
- Message payload content
- Subscription termination notifications
Error Handling
- Subscription Termination: Detects when subscriptions end and reports reason codes
- Invalid Message Types: Filters out non-Publish messages
- Connection Failures: Continuously monitors and reports connection status
- File System Support: Conditionally initializes filesystem for certificate storage
Dependencies
- NetBurner NNDK (NetBurner Network Development Kit)
- MQTT library support
- Network stack initialization
- Optional: Filesystem support for certificates
Development Notes
- System diagnostics are enabled for development (should be disabled for production)
- Uses 10-second polling interval for connection monitoring
- 4-second timeout for subscription operations
- Supports both platforms with and without filesystem capabilities
Example Use Cases
- IoT device message monitoring
- MQTT broker testing and validation
- Network communication debugging
- Real-time message processing demonstrations
- Integration testing for MQTT-based systems