MQTT LINUX 支持 websocket

未结帖
0 750
ajian lucy 2017-03-03
悬赏:5飞吻

 新的Mosquitto版本1.4.2已经支持WebSocket,这就为我们HTML5客户端使用MQTT提供了方法,但是MQTT连接默认不支持WebSocket连接,所以我们要首先设置让Mosquitto支持WebSocket:
(如果遇见有的步骤不能执行或者除错,请使用管理员权限sudo执行)废话不讲,开始:

第一步:安装前准备用到的依赖包:
$ sudo apt-get update
$ sudo apt-get install build-essential python quilt devscripts python-setuptools python3
$ sudo apt-get install libssl-dev
$ sudo apt-get install cmake
$ sudo apt-get install libc-ares-dev
$ sudo apt-get install  uuid-dev
$ sudo apt-get install daemon
第二步:下载并编译安装 libwebsockets
$ wget http://git.libwebsockets.org/cgi ... 3-firefox-36.tar.gz
$ tar zxvf libwebsockets-1.4-chrome43-firefox-36.tar.gz
$ cd libwebsockets-1.4-chrome43-firefox-36
$ mkdir build
$ cd build
$ cmake ..
$ make install
$ ldconfig
$ cd

第三步:下载并编译安装最新版 mosquitto 1.4.2

$ wget http://mosquitto.org/files/source/mosquitto-1.4.2.tar.gz
$ tar zxvf mosquitto-1.4.2.tar.gz
$ cd mosquitto-1.4.2
更改configure.mk中
WITH_WEBSOCKETS:=no
变成(这一步是做WebSocket支持)

WITH_WEBSOCKETS:=yes
$ make
$ make install
$ cp mosquitto.conf /etc/mosquitto
第四步:配置Mosquitto能够使用WebSocket

请在/etc/mosquitto/mosquitto.conf 的“Default Listener”  一节添加如下几行:
port 1883
listener 9001
protocol websockets
你添加过后此文件像这样的:
# =================================================================


# Default listener
# =================================================================
# IP address/hostname to bind the default listener to. If not
# given, the default listener will not be bound to a specific
# address and so will be accessible to all network interfaces.
# bind_address ip-address/host name
#bind_address
# Port to use for the default listener.
port 1883
listener 9001
protocol websockets
第五步:添加Mosquitto用户:


$ adduser mosquitto
$ reboot
第六步:运行Mosquitto:

$ mosquitto -c /etc/mosquitto/mosquitto.conf
现在你可以试试使用Websocket客户端来连接你的MQTT服务器的9001端口!!!!!!!

——————————本文章由damoyelang1992在开源智能家居论坛首发,转载请注明链接,并mail——iqinfei@163.com————



热忱回答0


最近热帖

近期热议

  1. javascript——prototype与__proto 9
  2. Mysql 中出现的Data truncated for column 3
  3. 在nginx中使用x-sendfile的解决方案 3
  4. 高版本jQuery面插件实现Ajax上传图片 1
  5. Thinkphp Socket.class.php 类的使用 1
  6. 使用ionic3创建第一个App 0
  7. ios-oc html5 0
  8. nginx.conf 0
  9. 基于ionic3.4.0的项目搭建 0
  10. php 缩略图 0