Mqtt over websocket
jersoncarin opened this issue · 12 comments
Hi there. I'm not really needing WebSocket support myself and I'm quite short on time at the moment, so I'm not sure I'll be able to work on this. But if you want to give it a try, I'm totally open to a PR which adds support for it. I guess it would require quite a few breaking changes and some sort of adapter design for the transport, though.
@jersoncarin there is no need to modify this library, you just need to modify the configuration of the mosquitto server to communicate on web sockets and you can send this library via MQTT to a web socket such as WS or WSS
@jersoncarin there is no need to modify this library, you just need to modify the configuration of the mosquitto server to communicate on web sockets and you can send this library via MQTT to a web socket such as WS or WSS
Have you tested this? WebSockets is its own binary protocol which would have to be implemented on top of MQTT - and this library currently doesn't do this. Furthermore, it seems counter intuitive to even wanting to use an additional protocol which causes more traffic on top of an IoT protocol like MQTT.
I use it that way, he's more of a trick or a Mosquitto (https://mosquitto.org/man/mosquitto-conf-5.html) program that can create a Bridge to WS and MQTT at the same time
If I understand you correctly, you are deploying a bridge which offers the standard MQTT protocol on the same machine as the client and forward traffic to a remote MQTT broker using the WebSockets protocol? Sounds like a reasonable solution, but still doesn't mean this library implements the WebSockets protocol...
@Namoshek look, JS: https://github.com/mqttjs/MQTT.js#client, mqtt server: https://mosquitto.org/man/mosquitto-conf-5.html and your php client, all comunication is in MQTT format (topic, data, qos...). Mqtt port is 1883, ws eg: 1884 (via configure in mosquito mqtt server). Both mqtt client is connent on same mqtt server, but different port. I publish message in (JS -> server -> PHP) and i subscribe in PHP, and revert mode, I publish on php (php->server->js) then I subscribe data on JS in browser :) It is simple solution, MQTT via WS :) source: https://www.emqx.com/en/blog/mqtt-js-tutorial or maybe: https://www.eclipse.org/paho/index.php?page=clients/js/index.php
@geniv I totally understand, but that doesn't answer/solve the initial request of this library being able to use WebSockets as transport. There might be scenarios where one has an MQTT broker which does not support the normal MQTT protocol for some reason, e.g. because it has to be deployed behind a proxy with authentication.
@geniv I totally understand, but that doesn't answer/solve the initial request of this library being able to use WebSockets as transport. There might be scenarios where one has an MQTT broker which does not support the normal MQTT protocol for some reason, e.g. because it has to be deployed behind a proxy with authentication.
Yes this true, I need implementation like the JS library that can use websocket as transport, note that the the mqtt over websocket server is not controlled by me, so I'm looking for implementation like JS lib or give me insight how to implement like clue so I can get idea.
You would need to write the implementation of the WebSocket client protocol around the existing implementation of MQTT, which seems doable, but definitely not trivial. I'm not sure if there are (good) existing client implementations of the WebSocket protocol available for PHP. A quick search did not yield any promising results, to be honest.
You would need to write the implementation of the WebSocket client protocol around the existing implementation of MQTT, which seems doable, but definitely not trivial. I'm not sure if there are (good) existing client implementations of the WebSocket protocol available for PHP. A quick search did not yield any promising results, to be honest.
Yeah thanks, Pawl PHP seems good, because it's uses ReactPHP Socket, I wonder how the implementation can be done, or some insight.
I found this discussion as well, hoping to find a websocket support for php. The reason being, it is more likely if developing software for many enterprise clients, to have some that block traffic of various ports or protocols. But since websockets is http, it is the simplest pattern to design and only support 1 protocol for your mqtt.
It is true it is very common for libraries to simply allow you to choose mqtts or wss, likewise on the server. So it is unfortunate that this is only supporting mqtts.
Totally respectful of not having the time to do such an implementation, but hopefully the context makes sense for why this would be a desired feature.