Can a web browser use MQTT?

2020-02-07 16:49发布

We are looking at using MQTT as the messaging protocol on a new device we're building. We'd also like a web interface for the device. Does anyone know if you can implement a browser client app (without additional plugins) that talks MQTT?

标签: mqtt
8条回答
forever°为你锁心
2楼-- · 2020-02-07 17:17

Yes, as mentioned in Steve-o's comment MQTT via websockets is very possible.

There are 2 options at the moment

  1. IBM's MQ 7.5 comes with websockets support, you can find details here.
  2. The Mosquitto broker has a javascript client with an example running here.

To answer your second question lighttpd has a websockets module that can be used to do forwarding to an existing broker with details here.

I've not been able to find anything for Apache that doesn't need you to write your own library to do the forwarding.

查看更多
闹够了就滚
3楼-- · 2020-02-07 17:17

This link (Download codes) is useful. Download it and modify this file mosq-mqttws31.html. Instead of the embedded java script library use this cdn

https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js

and the client instantiation should be client = new Paho.MQTT.Client("test.mosquitto.org", 8080,"myclien256tiddd_" + parseInt(Math.random() * 100, 10));

查看更多
ゆ 、 Hurt°
4楼-- · 2020-02-07 17:19

To extend hardillbs answer:

There is a third option now:

HiveMQ supports native websockets without the need for any external web server. It works perfectly with the Javascript client of Eclipse Paho.

If you want to try it out, the public MQTTDashboard (which uses HiveMQ under the hoods) supports websockets on port 8000.

Disclosure: I am one of the developers of HiveMQ

查看更多
我命由我不由天
5楼-- · 2020-02-07 17:20

The blog by jpmens is a good starting point to get mosquitto setup with websocket feature. He's client javascript code based on Paho is on github.

This blog "How to run your web server and MQTT WebSockets broker on the same por" explains two ways for the server side:

  • mosquitto with http configuration
  • apache+mod_websocket_mosquitto
查看更多
我命由我不由天
6楼-- · 2020-02-07 17:23
姐就是有狂的资本
7楼-- · 2020-02-07 17:25

Not Apache, but you can follow this guide to install lighttpd with mod_websocket,

http://oriolrius.cat/blog/2013/09/25/server-send-push-notifications-to-client-browser-without-polling/

but for easy of use I highly recommend HiveMQ, as @Dominik recommends.

查看更多
登录 后发表回答