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.
CN
in the certificate, does it include localhost? – hardillb