第一步:安装前准备用到的依赖包:
$ 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 https://launchpadlibrarian.net/288687040/libwebsockets_2.0.3.orig.tar.gz
$ tar zxvflibwebsockets_2.0.3.orig.tar.gz
$ cdlibwebsockets-2.0.3
$ 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 1884
protocol websockets
第五步:添加Mosquitto用户:
$ adduser mosquitto
$ reboot
第六步:运行Mosquitto:
$ mosquitto -c /etc/mosquitto/mosquitto.conf
现在你可以试试使用Websocket客户端来连接你的MQTT服务器的1884端口!!!!!!!