1. Today, I conducted a joint debugging with the customer. The customer reported that the mqtt server we built could not be connected. I had been connecting directly to the program before. In order to verify this problem, a client was specially installed.
First record the installation process as follows:
1. Download the client source code package. The most used online is mosquitto. I found a download address on the Internet:
http://www.eclipse.org/downloads/download.php?file=/mosquitto/source/mosquitto-1.4.15.tar.gz
2. Unzip to the /opt directory
tar -zxvf mosquitto-1.4.15.tar.gz
3. Make compilation, this process is more tortuous, and various errors are reported.
Error 1:
mosquitto.c:884: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:887: warning: implicit declaration of function ‘ares_fds’
mosquitto.c:887: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:992: error: ‘struct mosquitto’ has no member named ‘achan’
mosquitto.c:993: warning: implicit declaration of function ‘ares_process’
mosquitto.c:993: error: ‘struct mosquitto’ has no member named ‘achan’
solution:
Modify WITH_SRV=YES =>WITH_SRV=no in conifg.mk under the path of the decompressed package
# Build with SRV lookup support.
WITH_SRV:=no
Error 2:
g++: Command not found
solution:
Before compiling, you need to install the c++ plugin
yum install gcc gcc-c++
Error 3:
read_handle_server.c:31:25: error: uuid/uuid.h: No such file or directory
read_handle_server.c: In function ‘client_id_gen’:
read_handle_server.c:46: error: ‘uuid_t’ undeclared (first use in this function)
read_handle_server.c:46: error: (Each undeclared identifier is reported only once
read_handle_server.c:46: error: for each function it appears in.)
read_handle_server.c:46: error: expected ‘;’ before ‘uuid’
read_handle_server.c:59: warning: implicit declaration of function ‘uuid_generate_random’
read_handle_server.c:59: error: ‘uuid’ undeclared (first use in this function)
read_handle_server.c:60: warning: implicit declaration of function ‘uuid_unparse_lower’
Scenario 2:
yum install openssl-devel (as needed)
yum install c-ares-devel (required)
yum install libuuid-devel (required)
3. Installation
sudo make install // requires administrator privileges to install
4. After the installation is complete, verify
[root@localhost mosquitto-1.4.5]# mosquitto --help mosquitto version 1.4.5 (build date 2018-04-18 01:26:54-0700) mosquitto is an MQTT v3.1 broker.
....
5. Test
Switch between two windows:
Subscriber:
mosquitto_sub -t topicA -h 111.222.67.243 -u tbox-client -P 1qaz2wsx
Publisher:
mosquitto_pub -t topicA -m Msgfrom1 -h 111.222.67.243 -u tbox-client -P 1qaz2wsx
An unexpected state occurred:
Could not find libmosquitto.so.1
error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
Solution: Modify libmosquitto.so location
# create link
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
# Update dynamic link library
sudo ldconfig
Appendix parameter explanation:
-h broker address
-p port (do not specify default 1883)
-u username (username for connection, mqtt server is enabled for anonymous user access by default, no need)
-P password (connection password, mqtt server enables anonymous user access by default, no need)
-m message content
-t topic name
Reference documentation:
https://www.cnblogs.com/xiaoerhei/p/3777157.html
http://blog.163.com/allegro_tyc/blog/static/33743768201667101816858/
https://blog.csdn.net/laughing_cui/article/details/46530785