当前位置:网站首页>[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
- …
边栏推荐
- org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
- Leaflet map
- 10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
- 基于JEECG-BOOT制作“左树右表”交互页面
- [postman] collections - run the imported data file of the configuration
- 10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
- 【Postman】Collections-运行配置之导入数据文件
- Is the test cycle compressed? Teach you 9 ways to deal with it
- Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
- [postman] test script writing and assertion details
猜你喜欢
[C language] string left rotation
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
Win10 cannot operate (delete, cut) files
F - True Liars (种类并查集+DP)
浅谈专项测试之弱网络测试
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
二维码的前世今生 与 六大测试点梳理
【eolink】PC客户端安装
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?
技术分享 | 常见接口协议解析
随机推荐
通过修改style设置打印页样式
Manage configuration using Nacos
「 WEB测试工程师 」岗位一面总结
曼哈顿距离和-打印菱形
Testing of web interface elements
Aike AI frontier promotion (2.13)
win10无法操作(删除、剪切)文件
【无App Push 通用测试方案
F - True Liars (种类并查集+DP)
D - How Many Answers Are Wrong
Black cat takes you to learn EMMC Protocol Part 10: EMMC read and write operation details (read & write)
Reading notes of effective managers
【Postman】Collections配置运行过程
黑猫带你学UFS协议第4篇:UFS协议栈详解
Réflexions sur la sécurité des données (réimpression)
技术分享 | 常见接口协议解析
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
基于JEECG-BOOT制作“左树右表”交互页面
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?