MQTT.fx 无法连接到 AWS IoT (MqttException)

MQTT.fx can't connect to AWS IoT (MqttException)

我正在尝试学习本教程https://circuitdigest.com/tutorial/getting-started-with-amazon-aws-for-iot-projects

我一次又一次地执行了所有步骤,但是在 MQTT.fx 中单击“连接”按钮时我无法摆脱 MqttException 错误。

我从 AWS IoT 下载证书并将它们保存在 C:\temp 文件夹中。我还检查了 MQTT.fx 中的日志选项卡,您可以在下面看到。您知道如何解决吗?

非常感谢!

2020-10-09 10:40:28,043 ERROR --- MqttFX ClientModel : Please verify your Settings (e.g. Broker Address, Broker Port & Client ID) and the user credentials! org.eclipse.paho.client.mqttv3.MqttException: MqttException at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:715) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_162] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_162] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(Unknown Source) ~[?:1.8.0_162] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:1.8.0_162] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_162] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_162] at java.lang.Thread.run(Unknown Source) [?:1.8.0_162] Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.fatalSE(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.fatalSE(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.processLoop(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.process_record(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[?:1.8.0_162] at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:108) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] ... 7 more Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(Unknown Source) ~[?:1.8.0_162] at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) ~[?:1.8.0_162] at sun.security.validator.Validator.validate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.processLoop(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.process_record(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[?:1.8.0_162] at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:108) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] ... 7 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source) ~[?:1.8.0_162] at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) ~[?:1.8.0_162] at java.security.cert.CertPathBuilder.build(Unknown Source) ~[?:1.8.0_162] at sun.security.validator.PKIXValidator.doBuild(Unknown Source) ~[?:1.8.0_162] at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) ~[?:1.8.0_162] at sun.security.validator.Validator.validate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.processLoop(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.Handshaker.process_record(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[?:1.8.0_162] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[?:1.8.0_162] at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:108) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701) ~[org.eclipse.paho.client.mqttv3-1.2.0.jar:?] ... 7 more 2020-10-09 10:40:28,045 INFO --- ScriptsController : Clear console. 2020-10-09 10:40:28,046 ERROR --- BrokerConnectService : MqttException

我解决了我的问题。 这是关于下载错误的证书。您可以在这里找到详细的解决方案。

在 AWS IoT 中创建事物后,下载所有 3 个证书。

如果你想获得 MQTT.fx 所需的 CA 证书,你需要去 here(你会在 AWS IoT 的下载证书部分看到这个 link你创建你的东西​​)并单击 RSA 2048 位密钥:Amazon Root CA 1 link。将打开新标签页。

将此证书复制并粘贴到您的记事本中。保存时将其命名为 Amazon_Root_CA_1.pem 和 select 所有文件类型。

将所有证书放在一个文件中。我把它们放在 C:\temp 文件夹下。

最后,我的配置是这样的:MQTT.fx configuration

现在 MQTT.fx 有望工作:)