首页 > 解决方案 > Error wss://mqtt.eclipse.org when create mqtt client

问题描述

I am in my first mqtt project and my project is ok in local. But when I deployed it to heroku, It failed. This is the error:

Mixed Content: The page at 'https://showbd.herokuapp.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://mqtt.eclipse.org/mqtt'. This request has been blocked; this endpoint must be available over WSS. k._doConnect @ mqttws31.min.js:36 k.connect @ mqttws31.min.js:31 I.connect @ mqttws31.min.js:65 (anonymous) @ app.js:10

I declared client in app.js file.

    var MQTT_CLIENT = new Paho.MQTT.Client("mqtt.eclipse.org", Number(80), "/mqtt", MQTT_CLIENT_ID);

Thanks for help!

标签: javascripteclipsewebsocketmqtt

解决方案


这是在同源策略下确保您安全的浏览器

您部署的网页已通过 HTTPS 安全加载,为防止不安全的内容混入其中,它将阻止与非 TLS 保护位置的任何连接。在这种情况下,您尝试mqtt.eclipse.org在端口 80 上建立不安全的连接。

解决方案是告诉 Paho 客户端连接到端口 443 上的 Secure Websocket 端点。您可以通过将完整 URL 传递给 Paho 客户端构造函数来完成此操作

var MQTT_CLIENT = new Paho.MQTT.Client("wss://mqtt.eclipse.org", MQTT_CLIENT_ID);

推荐阅读