Error connect to serve Mosca MQTT
Closed this issue · 2 comments
tqthong0911 commented
This is my code serve.
// server tcp
var mosca = require('mosca');
var settings = {
port: 1883
};
var server = new mosca.Server(settings);
server.on('clientConnected', function (client) {
console.log('client connected', client.id);
});
// fired when a message is received
server.on('published', function (packet, client) {
console.log('Published _ ', packet.payload);
console.log(packet.payload.toString('utf8'));
});
server.on('ready', setup);
// fired when the mqtt server is ready
function setup() {
console.log('Mosca server is up and running');
}
My chip Esp8266 can connect this server, but why i clone you project not work ???
My chip esp 8266 using library Paho mqtt.
sjmf commented
Hi @tqthong0911 – can you be sure that your Mosca instance is serving MQTT over websocket?
As you have specified port 1183, this is usually used for raw MQTT. For mosca, see https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets for running via websocket– the example uses port 3000 for this.
Many connection problems are a result of trying to connect to a raw MQTT socket. Your ESP will be happy to connect to this, but a web browser can not.
tqthong0911 commented
I really appreciate your help with my project!
I did it.