Community Documents

Showing results for 
Search instead for 
Did you mean: 

MQTT Driver for LabVIEW


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, can provide all of the additional information you could possibly need.


Additionally, the MQTT specification can be found here: MQTT-v3.1.1-os Specification




Firstly I have to give Kudos to Peter at 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.

MQTT-Client-API-in-native (Peter -


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 ''.

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 '' block diagram.

The driver has been tested with mosquitto MQTT broker and also io.adafruit.



What is missing?

  1. Unsubscribe command not currently supported.
  2. TCPIP auto reconnect (in the case of disconnection - auto recovery).
  3. 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.
  4. The driver can be utilised in an application only once due to non-reentrancy, single queues/user events.



Hardware and Software Requirements

LabVIEW 2013+



Steps to Implement or Execute Code

  1. 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.
  2. Launch the project and open the VI ''.
  3. From the block diagram, open the and configure your broker settings.
  4. Run '' 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 Peters driver was referred to often during this implementation. Peter is aware of my development.


Source code is now available in GitHub:

Active Participant JensG69
Active Participant

Very nice API indeed. Smiley Happy


There's an error in VI "\class\mqtt\mqttCmd\mqttCmdPublish\": The payload for a publish command can be anything, so changing the data string to UTF-8 is incorrect. I noticed that when publishing a JSON-String (that already had been converted to UTF-8). That did not work to well. Smiley Wink


Wishful improvements (IMHO):

  • connector settings to MQTT-brooker not part of source-code. Just add controls to
  • Add an conditional disable structure to the VI "". Thus the API can run on RT-targets without any adjustments
  • change connector panes to widely accepted 4x2x2x4 pattern.
  • the "" will tell "connection accepted" when there's no answer from the broker. "Timed-Out" of the Wait für Notification should be handled.
  • It would be nice, if TCP-Open and TCP-Close could be started by the programm and not automatically inside the TCP-server.


Kudos are welcome...
Member cowen71
Hi Jens, Thank you for the feedback. I am sorry I am responding so late. I agree with most of your recommendations and when I have the time I will come back to this and update it further. The only small disagreement is regarding the conector pane. This was developed in my own time for a work application. The work application standardises on the patern 5x3x3x5 pattern. In this case, changing the pattern to match the online standard breaks standardisation in our own project. However, I do understand your point of view here. If you have already made modifications, please send them to me and I will republish with them (with redits to you of course ;-)).
Member 袁航

 Thanks a lot for your sharement, 

However, in "INIT. VI", I couldn't configure my USERNAME and PASSWORD, so, the result is "Connection refused: bad username or password"

Could you please tell me how to configure username and password?

Thanks a lot

Member cowen71



The MQTT object includes the fields for the username and password and so the following actions are needed:

  • Enable the username and password checkboxes in the connflags cluster (in the
  • Write the username and password to the user info cluster in the object (the accessor needs adding to the but...
    • The accessor to write this data should be located here: "....\mqtt_lv2013\src\class\mqtt\". But it is not there, I can only assume I forgot to create it!
      I will try and find a few moments to add this this week. However, it is very easy if you want to do this yourself.


Member cowen71

OK, time seems to be my biggest problem currently.


I have uploaded a newer version of the driver but with only very minor modification unfortunately.

  1. The call to the  "" can now be skipped by the use of an conditional disable structure.
  2. The username and password can now be provided from the main
  3. All configurations can now be entered from the test VI due to control inputs to the init vi.
  4. I believe the 'connection accepted' message when we have a connection timeout will not appear.

I really do welcome input from other developers to improve the driver further. There are several comments/requests above that make good sense to mebut I do not have the opportunity to implement them.

Member mRadziwon

Thanks Cowen for a nice expansion of peter's work.

As I work a lot with MQTT-LV applications I'd love to share my findings and contribute to your project. Have you considered publishing it on github or similar platform to make collaboration easier and more efficient?

Member cowen71

Hi mRadziwon.

I would be very happy to do this actually.

I try and find time over the weekend to organise this.


Member cowen71


My first experience of using GitHub to share my code - of course used it to access code previously.

It is here:

If I have something incorrect, please shout.


Member ssingh1

Hello cowen71,


Thanks for your MQTT Driver implementation for LabVIEW. I was waiting for something like this for a long time.


I am getting error "OpenSSL Error: error:140760FC: SSL routines: SSL23_GET_CLIENT_HELLO:unknown protocol" when connecting to CloudMQTT Server.


The local instance when connecting to broker on my PC is working fine. Can we connect to MQTT Server without SSL Port, as error seems something related to SSL?



Member ssingh1

Regarding my above Post the problem was solved after Selecting User Name and Password Flags in Connection Info.

NI Employee

I think, what i found error in your code.

For example, client recieved connection refused (error 66 from TCP write) from broker (i don`t know why):

TCP connection in this time remain open. Next subVI set connection ID in 0.

In next iteration, you run MQTT open again, but TCP connection from client is opened. In this case, connection ID use old (what was refused by server). Error loop.


I place connection ID away from case:


Then, subVI "MQTT close" get connection ID, clouse it. In next iteration connection is established.


Member Alexandra11

Hello, good afternoon.
We are trying to connect a publisher and subscriber in a NI MyRIO, but the connection is not done correctly, how I could have several clients in the same computer?

Member Cedric51



Very nice job!

I would like to test this library but unfortunately, I have Labview 2011. Is it possible to convert the code for Labview 2011 or older and share it on this page? thank you.



Member EstebanVS

Hello, i know this is too much to ask, but, can anybody can share this AWESOME Driver but for LabView 2011, will be vey nice if anybody can do,

thanks in advance!!!! and for what i can see, awesome job!

Member Hatim



I am slightly new to MQTT protocol. I am using the code provided by Cowen71, thanks by the way for sharing the code, it really helpful. I can send the data to my local computer using local mosquito broker (MQTT.fx) as described in the overview of MQTT at the top of this page. The problem is that I cannot send data to the Azure Internet of Things (IoT) hub using this code as the data is not secured. I am using share access signature (SAS) to access the hub.  I am not sure how to secure the data sent by the code provided by Cowen71 (e.g. to include CA cerfificate) in the code. Any help is greatly appreciated. Many thanks in advance.

Member shrofsp


Thanks a ton for providing such a useful MQTT library. I want ot develop a MQTT subscriber with TLS ( a CA certificate enabled option). How could I do it? As I donot have have option of identifying the certificate files and key files which is what is needed for a typical subscriber application in Certificate mode.

Any pointers on how implement it also would be very helpful.

Looking forward to prompt responses.

Best regards