当前位置:网站首页>Quanzhi technology T3 development board (4-core arm cortex-a7) - mqtt communication protocol case
Quanzhi technology T3 development board (4-core arm cortex-a7) - mqtt communication protocol case
2022-06-11 18:27:00 【Tronlong】
This article mainly introduces based on T3 The processor MQTT Communication protocol development case , The explanation mainly includes MQTT Introduction to communication protocol 、 summary 、 Application scenarios and Mosquitto Tool installation 、mqtt_client Cases and mqtt_sinewave_pub Case etc. .
This guidance document is applicable to the development environment :
Windows development environment :Windows 7 64bit、Windows 10 64bit
virtual machine :VMware15.1.0
Linux development environment :Ubuntu18.04.4 64bit
U-Boot:U-Boot-2014.07
Kernel:Linux-3.10.65
LinuxSDK:LinuxSDK_AA_BB_CC_DD( be based on T3_LinuxSDK_V1.3_20190122)
The test board is based on Chuang long technology TLT3-EVM It is based on Quanzhi technology T3 Processor design 4 nucleus ARM Cortex-A7 Domestic evaluation board with high performance and low power consumption , The dominant frequency of each core is up to 1.2GHz.

Evaluation board interface resources are rich , Lead out the double road network port 、 dual CAN、 dual USB、 dual RS485 And so on , On board Bluetooth、WIFI、4G( Optional ) modular , At the same time lead to MIPI LCD、LVDS LCD、TFT LCD、CVBS OUT、CAMERA、LINE IN、H/P OUT Audio and video multimedia interface , Support dual screen display 、[email protected] H.264 Video hardware encoding and decoding , And support SATA Mass storage interface .
MQTT Introduction to communication protocol
summary
MQTT(Message Queuing Telemetry Transport, Message queuing telemetry transmission protocol ), It's based on publishing / subscribe (Publish/Subscribe) Mode “ Lightweight ” Communication protocol , The agreement is built on TCP/IP Agreement on , from IBM stay 1999 Released in .MQTT The biggest advantage is , Very little code and limited bandwidth , Provide real-time and reliable message services for connecting remote devices .
MQTT It's lightweight 、 Simple 、 Open and easy to implement , At the same time, as a low cost 、 Low bandwidth instant messaging protocol , Make it in the Internet of things 、 Small equipment 、 Mobile applications are widely used .

chart 1
MQTT It has the following characteristics :
- Lightweight and reliable :MQTT The message format is simplified 、 compact , Available in severely limited hardware devices and low bandwidth 、 Stable transmission over high latency networks .
- Release / A subscription model (Publish/Subscribe): Release / The advantage of the subscription model is the decoupling of publishers and subscribers , Implement asynchronous protocol . That is, subscribers and publishers do not need to establish a direct connection , There is no need to be online at the same time .
- Born for the Internet of things : Provide heartbeat mechanism 、 Will news 、QoS Quality grade + offline message 、 Comprehensive Internet of things application features such as theme and security management .
- Better Ecology : Wide coverage , It has become the standard communication protocol for many cloud manufacturers' Internet of things platforms .
Application scenarios
MQTT As a low cost , Low bandwidth instant messaging protocol , It can provide real-time and reliable message services for networked devices with very little code and bandwidth , It is suitable for devices with limited hardware resources and network environments with limited bandwidth . The common application scenarios are as follows :
- The Internet of things M2M signal communication , Internet of things big data collection .
- Mobile instant messaging and message push .
- Smart hardware 、 Smart home 、 Intelligent electrical apparatus .
- Vehicle networking communication , Electric vehicle station pile collection .
- Smart city 、 telemedicine 、 distance learning .
- Electric energy 、 Petroleum Energy .
Mosquitto Tool installation
Mosquitto It's an open source MQTT The message broker ( The server ) Software , Offer lightweight 、 Support for releasable / Subscribable message push mode . The evaluation board file system provided by our company has supported Mosquitto Tools , this paper mqtt_client Case with Mosquitto Tool demonstration MQTT Communication function of communication protocol . Because the upper computer Ubuntu The system is the object of communication , Therefore, it is necessary to Ubuntu The terminal executes the following commands to install Mosquitto Tools .
Host# sudo apt-get install mosquitto-clients

chart 2
mqtt_client Case study
Case description
Case function : Use libmosquitto(MQTT version 3.1.1 client library) Of API And MQTT Proxy server communication . be based on MQTT Communication protocol , Realize the function of publishing and subscribing to messages .
The program flow chart is shown in the following figure .

chart 3
Case test
This case uses the public network MQTT HiveMQ Server and upper computer Ubuntu Mosquitto Tool communication . Please connect the evaluation board to the Gigabit network port through the network cable RGMII ETH And the upper computer are connected to the public network , Ensure normal access to the Internet .
The following table provides the available online public MQTT The server , It can switch on its own as needed .
surface 1
Server name | Broker Address | TCP port | WebSocket |
HiveMQ | broker.hivemq.com | 1883 | 8000 |
Mosquitto | test.mosquitto.org | 1883 | 80 |
Eclipse | mqtt.eclipseprojects.io | 1883 | 80/443 |
EMQ X( At home ) | broker-cn.emqx.io | 1883 | 8083/8084 |
The evaluation board starts , The case bin Under the table of contents mqtt_client Copy the executable file to any directory of the evaluation board file system , Execute the following command to view the program parameter description .
Target# ./mqtt_client --help

chart 4
Evaluation board release / The upper computer subscribes
Execute the following commands on the upper computer , Use mosquitto_sub Tool subscription MQTT The theme .
Host# mosquitto_sub -h broker.hivemq.com -p 1883 -t test/data
Argument parsing :
-h: Appoint MQTT The server ;
-p: Appoint MQTT The server TCP port ;
-t: Definition MQTT The theme , You can customize the name .

chart 5
Execute the following command in the evaluation board file system to publish a message to MQTT The server .
Target# ./mqtt_client -h broker.hivemq.com -p 1883 -M publish -t test/data -m 'www.tronlong.com'

chart 6 Evaluation board release
After the message is successfully published , The upper computer will start from MQTT The server receives the corresponding message .

chart 7 The upper computer subscribes
Evaluation board subscription / The upper computer releases
Execute the following command on the evaluation board file system to subscribe MQTT The theme .
Target# ./mqtt_client -h broker.hivemq.com -p 1883 -M subscribe -t test/data

chart 8
Execute the following commands on the upper computer to issue messages to MQTT The server .
Host# mosquitto_pub -h broker.hivemq.com -p 1883 -t test/data -m www.tronlong.com

chart 9 The upper computer releases
After the message is successfully published , The evaluation board will start from MQTT The server receives the corresponding message .

chart 10 Evaluation board subscription
Case compilation
The case src Copy the folder to Ubuntu Working directory , Please make sure you have referred to Linux The system user manual has been compiled LinuxSDK, structure T3 The processor corresponds to GCC compiler . Get into src The directory executes the following command , Use LinuxSDK Under the development package directory GCC Compiler for case compilation . After compilation , The executable will be generated in the current directory .
Host# CC=/home/tronlong/T3/lichee/out/sun8iw11p1/linux/common/buildroot/host/usr/bin/arm-linux-gnueabihf-gcc make

chart 11
Key code
establish Mosquitto example .

chart 12
Set the callback function .

chart 13
Connect MQTT The server .

chart 14
Release the news .

chart 15
Subscribe to topics .

chart 16
mqtt_sinewave_pub Case study
Case description
Case function : Use libmosquitto(MQTT version 3.1.1 client library) Of API And MQTT Proxy server communication . Evaluation board generates sine wave data , Send... Every second 512 Data from sampling points to MQTT The server ; Upper computer passes Web Page from MQTT After the server receives the data , The waveform will be drawn .
The program flow chart is shown in the following figure .

chart 17
Case test
This case uses the public network MQTT HiveMQ Server and upper computer Ubuntu Web Program communication . Please connect the evaluation board to the Gigabit network port through the network cable RGMII ETH And the upper computer are connected to the public network , Ensure normal access to the Internet .
The evaluation board starts , The case bin Under the table of contents mqtt_sinewave_pub Copy the executable file to any directory of the evaluation board file system , Execute the following command to view the program parameter description .
Target# ./mqtt_sinewave_pub --help

chart 18
Execute the following command to run the program , Connect MQTT The server , And send sine wave data to MQTT The server .
Target# ./mqtt_sinewave_pub -h broker.hivemq.com -p 1883

chart 19
After the evaluation board program runs , The case "tools\web_mqtt_sub\" Under the table of contents index.html file , Use the upper computer browser to open . In the pop-up Web page ( Here's the picture ), Input in sequence MQTT The server :broker.hivemq.com, Port number :8000, Finally, click Connect ,Web The page will start from MQTT The server obtains the sine wave data and draws the waveform .
remarks :ARM End MQTT The communication protocol is based on TCP agreement ,Web End MQTT The communication protocol is based on WebSocket agreement , Therefore, different port numbers are used .

chart 20

chart 21
Case compilation
The case src Copy the folder to Ubuntu Working directory , Please make sure you have referred to Linux The system user manual has been compiled LinuxSDK, structure T3 The processor corresponds to GCC compiler . Get into src The directory executes the following command , Use LinuxSDK Under the development package directory GCC Compiler for case compilation . After compilation , The executable will be generated in the current directory .
Host# CC=/home/tronlong/T3/lichee/out/sun8iw11p1/linux/common/buildroot/host/usr/bin/arm-linux-gnueabihf-gcc make

chart 22
Want to get mqtt_sinewave_pub The key code of the case and the detailed description of more test cases , Leave a comment in the comments section ~
边栏推荐
猜你喜欢

全志科技T3开发板(4核ARM Cortex-A7)——MQTT通信协议案例

牛客刷题——把字符串转换成整数

TI AM64x——最新16nm处理平台,专为工业网关、工业机器人而生

Cryptology Summary

Common interview questions of network and concurrent programming

* Jetpack 笔记 使用DataBinding
![[C语言]用结构体把平均分和低于等于平均分的学生数据输出](/img/c4/263301a22b61c86a3e0df6ad2596f1.png)
[C语言]用结构体把平均分和低于等于平均分的学生数据输出

Say no to credit card fraud! 100 lines of code to realize simplified real-time fraud detection
![[golang] leetcode - 292 Nim games (Mathematics)](/img/82/54c3f6be9d08687b42cba0487380f0.png)
[golang] leetcode - 292 Nim games (Mathematics)

viso的常见操作
随机推荐
. Net core redis hyperloglog type
[Golang]力扣Leetcode - 349. 两个数组的交集(哈希表)
SISO decoder for min sum (supplementary Chapter 2)
使用Transformers将TF模型转化成PyTorch模型
SISO Decoder for Repetition(补充章节4)
[C语言]用结构体把输入的指定分数范围内的学生输出
MMA-Self-defining function
单选按钮 文字背景同时改变
ACL 2022: is it no longer difficult to evaluate word polysemy? A new benchmark "dibimt"
力扣31 下一个排列
使用mysql判断日期是星期几
Some problems of DC-DC bootstrap capacitor
[FAQs for novices on the road] about project management
On the problem that the while loop condition in keil does not hold but cannot jump out
SISO decoder for a general (n,n-1) SPC code(补充章节3)
01.电信_领域业务经验
牛客刷题——把字符串转换成整数
vim常用命令
Monitoring loss functions using visdom
软件需求工程复习