I am trying to make a wss connection using JavaScript(mqttws31.js) client with generated self signed certificate but unable to create a connection and getting the below error.
- "Firefox can’t establish a connection to the server at wss://localhost:8883/mqtt."
- "Error: AMQJS0011E Invalid state not connected."
I have included the MQTT broker configuration details and JavaScript script code for reference.
MQTT Broker configuration( mosquitto.conf ).
port 8084
persistence true
persistence_file mosquitto.db
listener 1883 localhost
protocol mqtt
listener 8883
protocol websockets
allow_anonymous true
require_certificate false
cafile C:/Program Files/mosquitto/certs/certs/ca.crt
certfile C:/Program Files/mosquitto/certs/certs/server.crt
keyfile C:/Program Files/mosquitto/certs/certs/server.key
tls_version tlsv1.2
Javascript Client Code:
Below are inputs passing to the function.
host: localhost , port : 8883 and clientID : 1234.
function(){
that.client = new Paho.MQTT.Client(host, Number(port), clientId);
console.log("Connecting to " + host);
that.client.onConnectionLost = onConnectionLost;
that.client.onMessageArrived = onMessageArrived;
that.client.connect({
onSuccess : onConnect,
userName: 'user',
password:'password',
useSSL: true,
cleanSession : false
});
}
function onConnect() {
console.log('onConnect:');
that.client.subscribe("mgtl/#", {
qos : 2,
onSuccess : function(){
console.log('Acknowldgement recieved by sender');
},
onFailure : function(){
console.log('Subscribe request has failed or timed out');
}
});
that.client.subscribe("local/ack", {qos : 0});
console.log('mqtt connected');
}
Can anyone provide me the solution.
I am trying to make a wss connection using JavaScript(mqttws31.js) client with generated self signed certificate but unable to create a connection and getting the below error.
- "Firefox can’t establish a connection to the server at wss://localhost:8883/mqtt."
- "Error: AMQJS0011E Invalid state not connected."
I have included the MQTT broker configuration details and JavaScript script code for reference.
MQTT Broker configuration( mosquitto.conf ).
port 8084
persistence true
persistence_file mosquitto.db
listener 1883 localhost
protocol mqtt
listener 8883
protocol websockets
allow_anonymous true
require_certificate false
cafile C:/Program Files/mosquitto/certs/certs/ca.crt
certfile C:/Program Files/mosquitto/certs/certs/server.crt
keyfile C:/Program Files/mosquitto/certs/certs/server.key
tls_version tlsv1.2
Javascript Client Code:
Below are inputs passing to the function.
host: localhost , port : 8883 and clientID : 1234.
function(){
that.client = new Paho.MQTT.Client(host, Number(port), clientId);
console.log("Connecting to " + host);
that.client.onConnectionLost = onConnectionLost;
that.client.onMessageArrived = onMessageArrived;
that.client.connect({
onSuccess : onConnect,
userName: 'user',
password:'password',
useSSL: true,
cleanSession : false
});
}
function onConnect() {
console.log('onConnect:');
that.client.subscribe("mgtl/#", {
qos : 2,
onSuccess : function(){
console.log('Acknowldgement recieved by sender');
},
onFailure : function(){
console.log('Subscribe request has failed or timed out');
}
});
that.client.subscribe("local/ack", {qos : 0});
console.log('mqtt connected');
}
Can anyone provide me the solution.
Share Improve this question edited Dec 10, 2019 at 5:43 light_ray asked Dec 6, 2019 at 12:50 light_raylight_ray 6442 gold badges13 silver badges31 bronze badges 5- You have checked there is no firewall on the broker/windows machine? – hardillb Commented Dec 6, 2019 at 13:40
-
Also what is the
CN
in the certificate, does it include localhost? – hardillb Commented Dec 6, 2019 at 13:50 - yes, CN is localhost – light_ray Commented Dec 8, 2019 at 13:54
- Have you imported the CA cert into the browser? – hardillb Commented Dec 8, 2019 at 16:06
- I have manually imported the CA cert on the firefox and chrome browser but its not working in chrome however its working fine in firefox(I'm wondering). – light_ray Commented Dec 9, 2019 at 6:08
1 Answer
Reset to default 2As hashed out in the ments, it sounds like your browser didn't trust the CA you used to sign your brokers certificate.
Browsers do not pop up the same dialog about untrusted certificates as they do for HTTPS connection as they expect the code to make a decision about what to do with a connection failure (but I don't think they actually provide the reason in the error messages)
The best way to track this sort of thing down is usually to make sure you check the network
tab in the browsers developer tools.
As to why Chrome is not liking the imported CA cert, it may depend on what OS you are on as Chrome uses the system cert store unlike Firefox that maintains it's own iirc.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744962793a4603489.html
评论列表(0条)