Message Queuing Telemetry Transport (MQTT) in MPLAB® X IDE
Objective
This tutorial uses the AVR® Internet of Things (IoT) WG development board to set up the environment for Message Queuing Telemetry Transport (MQTT) in MPLAB® X IDE. The AVR IoT WG will be set up as the client and Eclipse Mosquitto™ MQTT as the broker, although any other broker may be used.
Once you have set up an AVR IoT WG as an MQTT client, you can use it for a variety of IoT applications that involve sending and receiving data over the internet.
Here are some example applications:
- Monitor and Control IoT Devices: You can use the AVR IoT WG to subscribe to MQTT topics that represent sensor data or control commands from other IoT devices. For example, you can subscribe to a temperature sensor topic and turn on a fan when the temperature exceeds a certain threshold.
- Send Data to Cloud Services: You can use the AVR IoT WG to publish data to cloud services such as AWS IoT, Google Cloud IoT, or Microsoft® Azure® IoT. This allows you to store and analyze the data in the cloud and trigger actions based on the data.
- Implement home automation: You can use the AVR IoT WG to control smart home devices such as lights, thermostats, and locks. For example, you can publish a message to turn on the lights when you enter a room.
- Build Industrial Automation Systems: You can use the AVR IoT WG to monitor and control industrial equipment such as motors, pumps, and valves. For example, you can subscribe to a topic that represents the status of a motor and turn it off if it overheats.
Overall, the AVR IoT WG as an MQTT client provides a flexible and scalable platform for building IoT applications that require real-time communication and data exchange.
The AVR IoT WG board has a code example that can be generated with the MCC library and uses the WINC1510 to establish an MQTT connection to any known broker, subscribe to topics, and publish.
Materials Required
Hardware
Reference
AVR IoT Development Board Introduction Video
MQTT MCC Library Release Notes v 2.0.1
Software
MPLAB® X Integrated Development Environment (IDE)
Eclipse Mosquitto™ MQQT broker
MyMQTT Play Store App
Wireshark
MQTT Explorer
Training Project Files
Training
- Installation
- Mosquitto.config
- pwfile.example
- Execute Mosquitto as broker
- Testing Mosquitto
- Know your host IP
- Configuring MyMQTT
- Subscribing
- MQTT Explorer
- Wireshark
Section 4: First Steps in MPLAB X IDE
- Add MQTT Library in MCC
- MQTT Window
- WINC1510 Window
- RTC Window and SPI0
- Pin Module (D0, D1, D2 and D3 Pins)
- Generate Code
- Write Code in main.c
- Run Basic Program
Section 5: MCC Generated Example Background
- app_mqttExampleInit()
- app_mqttSchedulre()
- Publish Always Same Message
- Publish Different Messages
- Publish to Different Topics
- Publishing Speed
- Declare New States
- Socket Handler
- Write New State
Section 8: Add Subscribe Function
- Create Subscribe Packet
- Send Subscribe Packet
- Subscribe Just Once
Section 9: Receiving, Processing, and Reading Packets
- Add line in socketHandler()
- Add line in MQTT_ReceptionHandler()
- Write code for processing received packets
- Read Received Message
- Declare Variables
- Declare Callback
- Define Callback
- Testing Result
- Nothing to Process