当前位置:网站首页>[mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
[mqtt from getting started to improving series | 01] quickly build an mqtt test environment from 0 to 1
2022-07-06 06:23:00 【I machine future】
This is the third of the future of machines 24 An article
The original address :https://blog.csdn.net/RobotFutures/article/details/125532208
1. mosquitto summary
Eclipse mosquitto It's open source (EPL/EDL Permitted ) The message broker , It has achieved MQTT Protocol version 5.0、3.1.1 and 3.1.mosquito It's lightweight , For all equipment , From low-power single board computer to complete server .
MQTT The protocol provides for the use of publishing / The subscription model is a lightweight way to perform messaging . This makes it suitable for Internet of things messaging , Such as low-power sensors or mobile devices , Such as mobile phone 、 Embedded computer or microcontroller .
mosquito to The project also provides an implementation for MQTT Of the client C library , And very popular mosquito to_pub and mosquito to_sub Command line MQTT The client .
2. download MQTT Deploy software
Download address : Portal
3. Quick start mosquitto
3.1 start-up mqtt broker
Start the command line tool , Switch to mosquitto The installation directory , Execute the following command , start-up broker
mosquitto.exe -v
The default open port is 1883.
The details of the order are as follows :
mosquitto [-c config file] [ -d | --daemon ] [-p port number] [-v]
-c Specify the profile path , The default configuration path is... Under the installation directory mosquitto.conf
-d Start up and run in the background
-p Designated port , The default is 1883
-v Turn on log output
matters needing attention : If you don't specify a profile , Only... Is supported by default 127.0.0.1 Local loopback network card connection , If you want to connect LAN or extranet clients , Then be sure to specify the configuration file mosquitto.conf:
listener 1883
allow_anonymous true # Allow anonymous access
The start command is as follows :
mosquitto.exe -c mosquitto.conf -v
Due to computer configuration problems , Here we use the custom port test
#mosquitto.exe -v -p 6969
1647942133: mosquitto version 2.0.14 starting
1647942133: Using default config.
1647942133: Starting in local only mode. Connections will only be possible from clients running on this machine.
1647942133: Create a configuration file which defines a listener to allow remote access.
1647942133: For more details see https://mosquitto.org/documentation/authentication-methods/
1647942133: Opening ipv4 listen socket on port 6969.
1647942133: Opening ipv6 listen socket on port 6969.
1647942133: mosquitto version 2.0.14 running
3.2 Subscribe to topics
mosquitto_sub.exe -t sensors/temperature -q 1 -p 6969
-t Appoint topic, Here is the sensor temperature value sensors/temperature
-q Appoint qos quality , Here for 1
-p Designated port , Here for 6969
After the execution of the command ,broker The log of is described as follows :
1647942590: New connection from 127.0.0.1:1746 on port 6969.
1647942590: New client connected from 127.0.0.1:1746 as auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 (p2, c1, k60).
1647942590: No will message specified.
1647942590: Sending CONNACK to auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 (0, 0)
1647942591: Received SUBSCRIBE from auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0
1647942591: sensors/temperature (QoS 1)
1647942591: auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 1 sensors/temperature
1647942591: Sending SUBACK to auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0
auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 - After successful connection ,broker Assigned session ID
CONNACK: Yes Connect Command response
SUBSCRIBE : Subscription requests initiated by clients
SUBACK :broker Client side auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 Of SUBSCRIBE Command feedback
3.3 Release theme
mosquitto_pub.exe -t sensors/temperature -m 32 -q 1 -p 6969
-t Appoint topic, Here is the sensor temperature value sensors/temperature
-q Appoint qos quality , Here for 1
-p Designated port , Here for 6969
-m Specify the message , The message here is 32
After the execution of the command :
- broker The log output of is as follows
1647942676: New connection from 127.0.0.1:1914 on port 6969.
1647942676: New client connected from 127.0.0.1:1914 as auto-BADB5BE4-8FF4-C9F8-DD05-955CEC58CA3D (p2, c1, k60).
1647942676: No will message specified.
1647942676: Sending CONNACK to auto-BADB5BE4-8FF4-C9F8-DD05-955CEC58CA3D (0, 0)
1647942676: Received PUBLISH from auto-BADB5BE4-8FF4-C9F8-DD05-955CEC58CA3D (d0, q1, r0, m1, 'sensors/temperature', ... (2 bytes))
1647942676: Sending PUBLISH to auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 (d0, q1, r0, m1, 'sensors/temperature', ... (2 bytes))
1647942676: Sending PUBACK to auto-BADB5BE4-8FF4-C9F8-DD05-955CEC58CA3D (m1, rc0)
1647942676: Received PUBACK from auto-651BD76A-09A1-67FD-1DF9-AF36BEADB2D0 (Mid: 1, RC:0)
1647942676: Received DISCONNECT from auto-BADB5BE4-8FF4-C9F8-DD05-955CEC58CA3D
1647942676: Client auto-BADB5BE4-8FF4-C9F8-DD05-955CEC58CA3D disconnected.
- The output of the subscribed client log is as follows :
PS E:\Tools\mosquitto> mosquitto_sub.exe -t sensors/temperature -q 1 -p 6969
32
You can see , The subscription client has received the message published by the publisher : Temperature value 32
3.4 Simple subscription / Publish workflow
4. Problems encountered during the test
4.1 Record mosquitto Port access failure debugging record
- By order
mosquitto -v
start-up MQTT broker The port opening of is as follows :
PS X:> netstat -an |findstr "1883"
TCP 127.0.0.1:1883 0.0.0.0:0 LISTENING
TCP [::1]:1883 [::]:0 LISTENING
- By order
mosquitto -c .\mosquitto.conf -v
start-up MQTT broker The port opening of is as follows :
PS C:\Users\25267> netstat -an |findstr "1883"
TCP 0.0.0.0:1883 0.0.0.0:0 LISTENING
TCP 192.168.149.108:1883 192.168.149.162:59826 ESTABLISHED
TCP [::]:1883 [::]:0 LISTENING
You can see that when the configuration file is not loaded , Only loopback network card is supported by default .
Write at the end :
- Blog profile : focus AIoT field , Chasing the pulse of the future era , Record the technological growth on the way !
- Column Introduction : from 0 To 1 Master distributed messaging middleware MQTT Use .
- Face the crowd : A programmer with basic embedded development experience or above
- Column plan : Next, we will gradually publish a series of blog posts into artificial intelligence , Coming soon
- Python Zero foundation quick start series
- Quick start Python Data Science Series
- Artificial intelligence development environment building series
- Machine learning series
- Object detection quick start series
- Autopilot Simulator AirSim Introductory series
- Automatic driving object detection series
- …
边栏推荐
- Basic knowledge of MySQL
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- MySQL之基础知识
- LeetCode 732. 我的日程安排表 III
- 记一个基于JEECG-BOOT的比较复杂的增删改功能的实现
- Set the print page style by modifying style
- Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
- 黑猫带你学UFS协议第4篇:UFS协议栈详解
- MFC 动态创建的对话框及改变控件的大小和位置
- 技术分享 | 常见接口协议解析
猜你喜欢
Data type of MySQL
Hypothesis testing learning notes
数据库-当前读与快照读
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
JWT-JSON WEB TOKEN
How to extract login cookies when JMeter performs interface testing
Construction and integration of Zipkin and sleuth for call chain monitoring
Black cat takes you to learn EMMC Protocol Part 10: EMMC read and write operation details (read & write)
把el-tree选中的数组转换为数组对象
Nodejs realizes the third-party login of Weibo
随机推荐
ESP32 ESP-IDF看门狗TWDT
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
Win10 cannot operate (delete, cut) files
技术分享 | 常见接口协议解析
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
Left matching principle of joint index
【Postman】动态变量(也称Mock函数)
sourceInsight中文乱码
Manage configuration using Nacos
MFC on the conversion and display of long string unsigned char and CString
G - Supermarket
LeetCode 731. 我的日程安排表 II
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
LeetCode 729. 我的日程安排表 I
[postman] the monitors monitoring API can run periodically
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
LeetCode 1200. 最小绝对差
模拟卷Leetcode【普通】1219. 黄金矿工
二维码的前世今生 与 六大测试点梳理
leaflet 地图