NetBurner 3.5.6
PDF Version
MQTT Config Object Example

MQTT Config Object Application

Overview

This NetBurner application demonstrates how to expose the device's configuration system through MQTT messaging. It allows remote configuration of NetBurner devices by sending JSON configuration messages to specific MQTT topics, providing a convenient way to manage device settings without requiring direct HTTP access to the configuration system.

Application Features

  • Remote Configuration: Modify device configuration remotely via MQTT messages
  • Dynamic Topic Generation: Automatically creates device-specific topics based on MAC address
  • JSON Configuration Support: Accepts standard NetBurner configuration JSON format
  • Bidirectional Communication: Supports both reading and writing configuration values
  • Rate Limiting: Implements MQTT publish rate limiting for network stability
  • Interactive Testing: Provides console-based testing interface

How It Works

Topic Structure

The application creates a device-specific MQTT topic using the format:

device/nburn_<MAC_SUFFIX>/config

Where <MAC_SUFFIX> is the last 3 octets of the device's MAC address. For example:

  • If MAC address is 00:03:F4:1A:2B:3C, the topic becomes device/nburn_1A2B3C/config

Configuration Messages

Send JSON configuration messages to the device topic to modify settings. The JSON format follows the standard NetBurner configuration structure.

Example Configuration Message:**

{
"Sys": {
"Application": "My Custom App Name"
}
}

This is equivalent to sending the same configuration via the HTTP configuration interface.

Usage

Prerequisites

  • NetBurner device with MQTT support
  • MQTT broker (configure connection details via NetBurner config system)
  • Network connectivity

Setup

  1. Configure MQTT Connection: Use the NetBurner configuration system to set:
    • MQTT broker URI
    • Username/password (if required)
    • SSL certificates (if using secure connection)
  2. Deploy Application: Flash the application to your NetBurner device
  3. Network Connection: Ensure the device has active network connectivity

Testing

Remote Configuration

  1. Connect to your MQTT broker using any MQTT client
  2. Send a JSON message to the device's config topic
  3. The device will apply the configuration changes immediately

Interactive Testing

  1. Connect to the device via serial console
  2. Press any key when prompted
  3. The application will send a test configuration message
  4. Observe the response and applied changes

Example Configuration Messages

Change Application Name:**

{
"Sys": {
"Application": "Production Device v1.0"
}
}

Modify Network Settings:**

{
"Sys": {
"NetIf": {
"Ethernet0": {
"DHCP": false,
"IPAddr": "192.168.1.100"
}
}
}
}

Code Structure

Key Components

  • MqttClient: Configured MQTT client with connection management
  • mqttConfigTree: MQTT configuration exposer that handles topic subscription and message processing
  • Rate Limiting: Configured with 20 messages per 5-second window, burst of 4 messages
  • Connection Monitoring: Waits for established MQTT connection before proceeding

Main Application Flow

  1. Initialize file system (if not available)
  2. Initialize network stack
  3. Enable system diagnostics
  4. Wait for active network connection
  5. Configure MQTT rate limiting
  6. Establish MQTT connection
  7. Enter interactive testing loop

Configuration Options

The application uses the NetBurner configuration system for MQTT connection settings:

  • Broker Configuration: Set via MqttClient configuration object
  • SSL/TLS: Certificates stored in file system
  • Rate Limiting: 20 messages per 5 seconds, burst capacity of 4 messages

Error Handling

  • Connection Monitoring: Continuously monitors MQTT connection status
  • Network Dependency: Waits for active network before attempting MQTT connection
  • Rate Limiting: Prevents overwhelming the MQTT broker with messages

Security Considerations

  • Topic Naming: Uses MAC address suffix for device identification
  • SSL Support: Supports secure MQTT connections with certificates
  • Local Message Filtering: Configured to ignore messages from the same client

Dependencies

  • NetBurner NNDK
  • MQTT library support
  • File system support (for certificate storage)
  • Network stack

Troubleshooting

Common Issues

  1. Connection Failures: Verify MQTT broker settings and network connectivity
  2. Topic Not Found: Check MAC address format in topic name
  3. Configuration Not Applied: Ensure JSON format matches NetBurner config structure
  4. Rate Limiting: Reduce message frequency if experiencing delays

Debugging

  • Enable system diagnostics for detailed logging
  • Monitor serial console for connection status messages
  • Verify MQTT broker logs for message delivery

Production Deployment

For production use:

  1. Remove or disable system diagnostics
  2. Configure appropriate SSL certificates
  3. Set production MQTT broker settings
  4. Implement proper error handling and logging
  5. Consider removing interactive testing code