Error 66 With MQTT on a Real-Time Controller in LabVIEW

Updated Jul 28, 2023

Reported In

Software

  • LabVIEW

Issue Details

  • I am using a Real-Time (RT) controller as an MQTT Publisher or Subscriber, but I keep seeing error 66. How can I fix this?
  • My MQTT Publisher or Subscriber does not connect to my Broker because "the network connection was closed by the peer". What's causing this?
  • My NI Linux Real-Time controller keeps producing the below error when I attempt to publish an MQTT message.

Error 66 occurred at TCP Write in <VI>
Possible reason(s):
LabVIEW: (Hex 0x42) The network connection was closed by the peer. If you are using the Open VI Reference function on a remote VI Server connection, verify that the machine is allowed access by selecting Tools>>Options>>VI Server on the server side.


Error 66 MQTT.PNG
 

Solution

This error can occur due to one of the following reasons:
  • Incorrect start-up procedure of the Broker and Publisher/Subscriber.
  • Communication being blocked by a Firewall.
  • Incorrect RT controller settings or configuration.
  • Invalid MQTT parameters.

Review the points below to resolve this error:
  • Ensure that the MQTT port is open on the Broker PC and that the client can reach it.
  • Make sure that the Broker is started/created before the Publisher or Subscriber.
  • Verify that TCP/IP is enabled on the RT controller.
    1. From the LabVIEW project window, right-click the controller and select Properties.
    2. In the pop-up window, select the VI Server tab.
    3. Ensure that the TCP/IP option is enabled and that Port contains your MQTT port number.
Enable TCP IP.PNG
  • If using an RT controller with dual Ethernet ports, ensure that the second port (eth1) is on a different subnet than the first port.
  • Depending on the MQTT toolkit used, enable or increase the time of the Keep Alive parameter.
  • If connection flags have been set, ensure that the required values are being passed into the configuration.
    • For example, if the Username or Password flags are true, a valid username and password must be passed into the MQTT connection function.

Additional Information

MQTT is a protocol built on top of TCP. As a result, troubleshooting that applies to TCP errors also apply when using MQTT.