sjmf/ng2-mqtt-demo

Error connect to serve Mosca MQTT

Closed this issue · 2 comments

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.

This is text error.
image

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.

I really appreciate your help with my project!
I did it.