You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
The client is running on Chrome.
Using the embedded MOSCA, it worked well.
But using the MQTT.js Browserify Bundle, it did not work.
My server side initialization is as follow:
//=============================================
// Mosca & Express initialization
var mosca = require("mosca");
var broker = new mosca.Server({});
var express = require("express");
var http = require("http");
var app = express()
var srv = http.createServer(app)
broker.attachHttpServer(srv);
// mqtt.js from node_modules/mosca/public was copied to the public folder
// thus the web root is the default public
app.use(express.static('public'));
app.listen(3000, () => console.log('WebApp listening on port 3000!'));
//=====================================
The express worked, it can serve the static HTML as well as the API.
However the MQTT client was failed with the following error:
WebSocket connection to 'ws://192.168.100.5:3000/' failed: Error during WebSocket handshake: Unexpected response code: 200
Please help. Thank you in advance.
The text was updated successfully, but these errors were encountered:
Just stumbling across your problem while looking for a different problem.
You should not need to connect to ws://...:3000 if :3000 is an HTTP-Endpoint serving the mqtt.js file (see Unexpected response code). The response should indicate a downgrade from http to ws.
Since you dont config any more details for mosca.Server I guess mosca sets up an mqtt-TCP-listener on 1883 - which would mean that you need another listener for WS-Connections with default port probably 9001.
It should also work with plain HTML + JS when loading MQTT-client by Backend-Endpoint '/mqtt-client'.
I know it is not the best version so far - make it work then make it right. In case you need a better version i might come up with some nicer implementation next days / weeks.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Dear sir.
I'm trying to use mqtt over web socket, as described
https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets
The client is running on Chrome.
Using the embedded MOSCA, it worked well.
But using the MQTT.js Browserify Bundle, it did not work.
My server side initialization is as follow:
//=============================================
// Mosca & Express initialization
var mosca = require("mosca");
var broker = new mosca.Server({});
var express = require("express");
var http = require("http");
var app = express()
var srv = http.createServer(app)
broker.attachHttpServer(srv);
// mqtt.js from node_modules/mosca/public was copied to the public folder
// thus the web root is the default public
app.use(express.static('public'));
app.listen(3000, () => console.log('WebApp listening on port 3000!'));
//=====================================
The express worked, it can serve the static HTML as well as the API.
However the MQTT client was failed with the following error:
WebSocket connection to 'ws://192.168.100.5:3000/' failed: Error during WebSocket handshake: Unexpected response code: 200
Please help. Thank you in advance.
The text was updated successfully, but these errors were encountered: