当前位置:网站首页>[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
- …
边栏推荐
- Simulation volume leetcode [general] 1249 Remove invalid parentheses
- 模拟卷Leetcode【普通】1447. 最简分数
- Customize the gateway filter factory on the specified route
- 数据库隔离级别
- 【Postman】测试(Tests)脚本编写和断言详解
- 全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
- 黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
- 把el-tree选中的数组转换为数组对象
- Redis core technology and basic architecture of actual combat: what does a key value database contain?
- Past and present lives of QR code and sorting out six test points
猜你喜欢
[postman] test script writing and assertion details
Basic knowledge of MySQL
Postman核心功能解析-参数化和测试报告
B - The Suspects
D - How Many Answers Are Wrong
Convert the array selected by El tree into an array object
Summary of anomaly detection methods
Past and present lives of QR code and sorting out six test points
sourceInsight中文乱码
On weak network test of special test
随机推荐
D - How Many Answers Are Wrong
Online and offline problems
sourceInsight中文乱码
模拟卷Leetcode【普通】1447. 最简分数
keil MDK中删除添加到watch1中的变量
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
LeetCode 732. 我的日程安排表 III
Selenium source code read through · 9 | desiredcapabilities class analysis
模拟卷Leetcode【普通】1109. 航班预订统计
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
MySQL之数据类型
数据库隔离级别
F - True Liars (种类并查集+DP)
模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
[postman] collections configuration running process
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
进程和线程的理解
Simulation volume leetcode [general] 1447 Simplest fraction
Réflexions sur la sécurité des données (réimpression)