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
- Configure MQTT Connection: Use the NetBurner configuration system to set:
- MQTT broker URI
- Username/password (if required)
- SSL certificates (if using secure connection)
- Deploy Application: Flash the application to your NetBurner device
- Network Connection: Ensure the device has active network connectivity
Testing
Remote Configuration
- Connect to your MQTT broker using any MQTT client
- Send a JSON message to the device's config topic
- The device will apply the configuration changes immediately
Interactive Testing
- Connect to the device via serial console
- Press any key when prompted
- The application will send a test configuration message
- 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
- Initialize file system (if not available)
- Initialize network stack
- Enable system diagnostics
- Wait for active network connection
- Configure MQTT rate limiting
- Establish MQTT connection
- 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
- Connection Failures: Verify MQTT broker settings and network connectivity
- Topic Not Found: Check MAC address format in topic name
- Configuration Not Applied: Ensure JSON format matches NetBurner config structure
- 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:
- Remove or disable system diagnostics
- Configure appropriate SSL certificates
- Set production MQTT broker settings
- Implement proper error handling and logging
- Consider removing interactive testing code