MQTT brokers are becoming increasingly popular for various hardware suppliers and of course, the home automation market. In very simple terms, an MQTT broker is a message dispatcher. One or more Clients can Publish topics and values to the broker and additionally, One or more clients can Subscribe to be notified when someone writes values to these topics.
If you are searching for an MQTT driver, then I assume you know what this is. If not, mqtt.org can provide all of the additional information you could possibly need.
Firstly I have to give Kudos to Peter at daq.io. With constant reference to the MQTT specification, and referring to Peters implementation saved me a lot of time. Thus I had something working quite quickly.
So why did I (re)develop an MQTT Driver? Simply put, I had a few issues that I found easier to solve by reworking the implementation.
Several API calls exist for the various MQTT functions. All can be tested using the aptly named 'test.vi'.
An MQTT comms server VI must run in parallel to the event loop. The comms server VI sends and receives data to the broker and dispatches data to the relevant callers.
Published data from the Broker are received by the comms server VI and then distributed within my application via a User Event. Thus it is possible for multiple VI's to register to the user event and thus, be updated when data is received from the broker.
The broker configuration is via clusters in the 'test.vi' block diagram.
The driver has been tested with mosquitto MQTT broker and also io.adafruit.
What is missing?
Unsubscribe command not currently supported.
TCPIP auto reconnect (in the case of disconnection - auto recovery).
Disconnect on error. The MQTT-v3.1.1-os Specification defines many cases where a bad message should cause the client to close the connection. These have not yet been implemented.
The driver can be utilised in an application only once due to non-reentrancy, single queues/user events.
Hardware and Software Requirements
Steps to Implement or Execute Code
Get an MQTT broker server. During my testing, I used mosquitto. However, there are of course others. A list of available brokers can be found here.
Launch the project and open the VI 'test.vi'.
From the block diagram, open the INIT.vi and configure your broker settings.
Run 'test.vi' and click connect. If the connection is accepted, you are now free to subscribe from and publish to your broker.
Note that I also used an independent MQTT client to subscribe to the broker and verify my LabVIEW MQTT events were really working. In my case, I used mqttfx
Additional Information or References
Huge thanks to Peter at daq.io. Peters driver was referred to often during this implementation. Peter is aware of my development.