Ubuntu compile mosquitto and simple test

The mosquitto version 2.0.14 is used here. I compiled it according to the following steps and tested it successfully.

1. Install dependencies

Depend on cjson, compile cjson first:

git clone https://github.com/DaveGamble/cJSON.git
cd cJSON
mkdir build
cd build
cmake ..
make
make instal

2. Compile mosquitto

After downloading and decompressing the mosquitto source code

cd mosquitto-2.0.14
mkdir build
cd build
cmake ../
make
make install

3. Test mosquitto

3.1 Start the service

After compilation, a mosquitto executable file will be generated. Here I am in the directory /home/thera/opensource/mosquitto-2.0.14/build/src.

mosquitto --help #查看启动参数

Insert image description here
Follow the prompts to start moquitto

./mosquitto -p 1883  #指定监听1883端口

This shows that mosquitto is running
Insert image description here

3.2 Subscription

Find the mosquitto_sub executable file, which is under the /home/thera/opensource/mosquitto-2.0.14/build/client path. Also check the parameters first.

./mosquitto_sub --help

Insert image description here

./mosquitto_sub -h 127.0.0.1  -p 1883 -u me -P 123456 -t me/you   #-h指定mosquitto地址 -p指定端口 -P 指定密码 -t指定主题
3.3 Release

Find the mosquitto_pub executable file, which is under the /home/thera/opensource/mosquitto-2.0.14/build/client path. Also check the parameters first.

./mosquitto_pub --help

Insert image description here

./mosquitto_pub -h 127.0.0.1  -p 1883 -u me -P 123456 -t me/you -m kkkkkk     # -m指定消息内容

4.Test results

mosquitto_sub subscribes to messages published by mosquitto_pub
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_43815862/article/details/130729414