MQTT Object I/O Application
Overview
This application demonstrates bidirectional MQTT communication using hardware I/O pins on embedded platforms. It creates a bridge between physical hardware inputs/outputs and MQTT messaging, allowing remote monitoring and control of GPIO pins through MQTT topics.
Features
- Input Monitoring: Monitors a physical input pin and publishes state changes to an MQTT topic
- LED Control: Subscribes to an MQTT topic to control a physical LED
- Serial Console Interface: Provides local control and monitoring through serial console
- Multi-Platform Support: Compatible with multiple NetBurner development boards
Hardware Configuration
The application uses different GPIO pins depending on the target platform:
| Platform | Input Pin | LED Pin |
| SOMRT1061 | Pin 22 | LED1 |
| NANO54415 | Pin 50 | LED1 |
| MODM7AE70 | P2[8] | LED1 |
| MOD5441X | J2[45] | LED1 |
| SBE70LC | P1[5] | LED1 |
| SB800EX | No input pin | LED1 |
MQTT Topics
Published Topics
- Device/Input1: Publishes input pin state changes
- Values:
0 (low/GND) or 1 (high/3.3V)
- Published automatically when input pin state changes
Subscribed Topics
- Device/LED1: Controls LED state
- Accepted values:
true or any value > 0: Turns LED ON
false or 0: Turns LED OFF
Operation
Startup Behavior
- Initializes network stack and file system (if needed for certificates)
- Waits for active network connection (5 second timeout)
- Displays application name and NNDK revision
- Sets up MQTT I/O objects for input monitoring and LED control
- Outputs current input pin state (
0 or 1) to serial console
- Enters main loop for serial console interaction
Runtime Behavior
- Input Pin Monitoring: Automatically publishes to
Device/Input1 when the input pin state changes
- LED Control via MQTT: LED state changes when messages are received on
Device/LED1 topic
- Serial Console Control: Pressing any key on the serial console toggles the LED state
Testing
Input Pin Testing
- Connect the specified input pin to GND to read
0
- Connect the specified input pin to 3.3V to read
1
- Monitor the serial console or MQTT topic
Device/Input1 for state changes
LED Control Testing
- Via MQTT: Send messages to the
Device/LED1 topic:
- Send
1, true, or any positive number to turn LED on
- Send
0 or false to turn LED off
- Via Serial Console: Press any key to toggle the LED state
Configuration
The MQTT client configuration (broker URI, username, password, certificates, etc.) is handled through the NetBurner configuration system. Ensure your MQTT broker settings are properly configured before running the application.
Code Structure
Key Components
Optional Features
- Uncomment the
myLED.SetFlags(MQTT::eObj_Flag_PubOnWrite) line to publish LED state changes to the MQTT topic when the LED is controlled locally
Dependencies
- NetBurner NNDK (NetBurner Network Development Kit)
- MQTT library support
- Network connectivity
- File system support (for MQTT certificates/keys)
Build Requirements
- Compatible NetBurner development board
- Properly configured MQTT broker
- Network connection (Ethernet or WiFi depending on platform)
Notes
- The SB800EX platform does not support input pin monitoring due to hardware limitations
- System diagnostics are enabled by default (consider removing for production deployments)
- The application waits up to 5 seconds for network connectivity before proceeding
- Certificate and key storage requires file system support on platforms that don't have built-in file system capabilities