【发布时间】:2022-06-19 21:43:38
【问题描述】:
我正在使用 mosquitto MQTT 代理(ip:192.168.1.61 和端口:1883) 这是我的 HTML 代码:
<html>
<head>
<title>My First Value</title>
<h1>Main Body</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
</head>
<body>
<h1><div id="connstatus">
Mqtt Not connected.</div></h1>
</body>
<script>
var host = "192.168.1.61";
var port=1883;
var user="Fares";
var pass="1+4=5";
// Create a client instance
client = new Paho.MQTT.Client(host,1883, "clientId");
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("World");
message = new Paho.MQTT.Message("Hello");
message.destinationName = "World";
client.send(message);
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
}
</script>
</html>
这是我的 .config 文件:
听众 8883
keyfile /mosquitto/config/certs/broker.key
监听 8083 协议 websockets
keyfile /mosquitto/config/certs/broker.key
require_certificate false
persistence true persistence_location /mosquitto/data/
错误: 控制台:
WebSocket connection to 'wss://192.168.1.61:1883/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_RESET
Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:977
Paho.MQTT.ClientImpl._disconnected @ mqttws31.js:1459
Paho.MQTT.ClientImpl._on_socket_error @ mqttws31.js:1347
(anonymous) @ mqttws31.js:157
【问题讨论】:
-
请不要发布文本图像,日志文件应以文本形式发布并格式化(例如作为代码)。因为对于使用屏幕阅读器或搜索的人来说,它很难阅读并且不可能。
-
知道了,抱歉,我要编辑一下
-
我的意思是两个日志。