打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
MQTT学习笔记-让Mosquitto支持Websocket
  新的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————


注意:

如果提示uuid/uuid.h: 没有那个文件或目录,则需要使用命令sudo apt-get install uuid-dev安装uuid


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
树莓派上的MQTT环境搭建
编译mosquitto-1.4.2错误解决
物联网的基础协议之MQTT
Mosquitto安装及使用
在CentOS7 上安装mosquitto1.4.1服务器,实现MQTT信息推送功能并增加websocket功能
【Python】Ubuntu 18.04 安装 python3.7
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服