# Troubleshoot MQTT Connection

This section provides troubleshooting instructions for the most common issues with establishing an MQTT Message Queue Telemetry Transport (MQTT) is a lightweight messaging protocol used to send and receive data between devices. connection.

## No Results Published

If you are not seeing any published results from your vision system, perform the following troubleshooting procedure:

1. Open the Enterprise Connectivity utility, and make sure that Enterprise Connectivity is enabled on your vision system.

2. Verify that the vision system is Online. Results are only published when the vision system is Online.

3. Make sure that results are sent on A0 triggers.

4. Open a browser and go to https://{deviceIp}/api/edge-agent/subscriptions/results to verify that Enterprise Connectivity is processing results.

   If Enterprise Connectivity is processing results, you can see results coming through on the page.

5. Open a browser and go to https://{deviceIp}/utilities/single/enterprise-connectivity/diagnostics to verify that the connection to the MQTT broker A broker is a server that receives messages from publishers and forwards them to subscribers. In MQTT, the broker acts as a central hub, managing topics and message delivery between devices and systems. is active.

   If your vision system is disconnected, you can see an error message under the Disconnected state on the diagnostics page.

## MQTT Broker Disconnected

If your MQTT broker is disconnected, perform the following troubleshooting procedure:

1. Set up a local MQTT broker to ensure that the vision system is working correctly:

   1. Download and install the latest version of mosquitto for Windows to a directory where you have full access.

   2. Uncheck the service option, as you are going to run the broker from the command prompt in order to see the logs.

   3. Allow the broker to receive connections from a different device by issuing the following command in PowerShell:

      @("listener 1883 0.0.0.0`nallow_anonymous true") + (Get-Content "c:\mqtt-broker\mosquitto.conf") | Set-Content "c:\mqtt-broker\mosquitto.conf"

   4. Run the broker by issuing the following command in PowerShell:

      & 'C:\mqtt-broker\mosquitto.exe' -v -c .\mosquitto.conf

2. Use an MQTT client such as MQTTX to test that you can publish and subscribe to topics on your broker.

3. Configure the MQTT connection to the address of the PC that is connected to your vision system.

4. Remove any credentials and certificates on your vision system.

5. Investigate any mismatches between the disconnected MQTT broker and your local test broker.

6. If there are no mismatches, verify that the credentials and certificates on your vision system are correct.

## MQTT Disconnected Error Messages

The following table lists the possible Disconnected error messages and the potential causes:

Error Message | Potential Cause or Resolution
--- | ---
failed to lookup address information: Temporary failure in name resolution | Unable to resolve the hostname. Check the In-Sight can reach that target
Network timeout | The target machine is not responding. Check the address again. Check that the In-Sight can reach that target.
Connection refused (os error 111) | Check that the port is correct. Check that the firewall of the host allows external connections.
Connection refused, return code: `NotAuthorized` | Incorrect username or password.
Connection refused, return code: `BadUserNamePassword` | Incorrect username or password.
Connection closed by peer abruptly | The broker stopped running. The server may require TLS.
TLS: Native TLS error Connection reset by peer (os error 104) | Requesting TLS, but the broker does not support it on that port.
Mqtt serialization/deserialization error: IO: error:0A000412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate:../openssl-3.0.17/ssl/record/rec_layer_s3.c:1605:SSL alert number 42 | Selected SSL/TLS mode does not match broker configuration .
Mqtt serialization/deserialization error: IO: error:0A000416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown:../openssl-3.0.17/ssl/record/rec_layer_s3.c:1605:SSL alert number 46 | The broker has rejected the certificate. Check that the certificate being used is signed by a CA trusted by the broker.

## Connection Fails with Valid Certificate and Configuration

If your connection is failing, and you have verified that your certificate is valid and your configuration is correct, perform the following troubleshooting procedure:

1. Verify that the time is correct on your vision system.

2. Make sure that you are using timestamps in UTC.

3. Make sure that your vision system is synchronized with a NTP server using the Time Settings utility.

## Commands Not Working

If incoming commands are not working, perform the following troubleshooting procedure:

1. Make sure that the JSON format is correct in incoming messages.

2. Add console.log("debug note") to your script to help isolate the issue. You can view log messages at the following address: https://{deviceIp}/utilities/single/enterprise-connectivity/diagnostics

## Unable to Toggle Online/Offline Mode Using Native Mode Commands (statusCode -5)

If you are trying to use native mode commands to toggle the Online/Offline state of the vision system, and are receiving a statusCode: -5 response, the reason is that In-Sight vision system cannot switch between Online and Offline states using native mode commands unless the vision system originally starts in Online mode.