MQTT open source library mosquitto installation and use (1)

1. Download and install

1.1. Download address

https://mosquitto.org/download/
version: mosquitto-1.6.9

1.2. Installation

1.2.1. Binary installation

Quick installation (higher versions support snap mode, a quick way to solve dependency package problems)
snap install mosquitto

1.2.2. Windows version binary installation

1.2.2.1. Download and installation

mosquitto-1.6.8-install-windows-x64.exe (~1.4 MB) (64-bit build, Windows Vista and up, built with Visual Studio Community 2017)
Insert picture description here
Insert picture description here

1.2.2.2. Configure environment variables

Insert picture description here

1.2.2.3. Start the server

Switch to the installation directory D:\Program Files\mosquitto, and run
mosquitto -c mosquitto.conf

1.2.2.4. Subscription

mosquitto_sub -v -t {topic}

1.2.2.5. Release

mosquitto_pub -t {topic} -m {message}

1.2.3.Ubuntu compile and install

Dependent library installation
Install ssl dependency package
$ sudo apt-get install libssl-dev

mosquitto-1.6.9.tar.gz (319kB) (GPG signature)
Unzip
$ tar zxvf mosquitto-1.6.9.tar.gz
$ cd mosquitto -1.6.9
$ make
$ sudo make install
Start the service
$ mosquitto -v
Insert picture description here

2. Basic use of Ubuntu command line (QoS0)

2.1. Start the server

$mosquitto -v

2.2. A client A subscribes

mosquitto_sub -v -t aloha
Insert picture description here

2.3. A client B release

mosquitto_pub -t aloha -m hello After
client B connects to the server, it publishes a topic message and disconnects; the
server forwards it to client A;
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

2.4. Related messages (based on MQTTv3.1.1)

2.4.1. Connection message

Insert picture description here

2.4.2. Connection confirmation message

Insert picture description here

2.4.3. Subscription message

Insert picture description here

2.4.4. Subscription response

Insert picture description here

2.4.5. Release message

Insert picture description here

2.4.6. Disconnect message

Insert picture description here

2.4.7. Heartbeat request message

Insert picture description here

2.4.8. Heartbeat response message

Insert picture description here

Guess you like

Origin blog.csdn.net/skytering/article/details/104617812