Connecting To The MQTT Broker Using The Open-source C Language ...
Có thể bạn quan tâm
检测到您已登录华为云国际站账号,为了您更好的体验,建议您访问国际站服务网站 https://www.huaweicloud.com/intl/zh-cn
不再显示此消息
- English
- Bahasa Indonesia
- Español
- Português
- Türkçe
- عربي
- ไทย
- 简体中文
- 日本語
- 简体中文
- English
- Deutsch
- Español
- Français
- Nederlands
- Activities
- Products
- Solutions
- Pricing
- KooGallery
- Partners
- Developers
- Support
- About Us
- Free Packages
- Elastic Cloud Server (ECS)
- Cloud Backup and Recovery (CBR)
- Host Security Service (HSS)
- Cloud Container Engine (CCE)
- Contact Us
- Documentation
- Console
-
- My Account
- Billing & Costs
- Service Tickets
- Unread Messages
- Console
- Sign In Sign Up
- Sign In
- Sign Up
-
- My Account Complete Sign Up
- Billing & Costs
- Service Tickets
- Unread Messages
- Console
- Log Out
- Free Packages
- Elastic Cloud Server (ECS)
- Cloud Backup and Recovery (CBR)
- Host Security Service (HSS)
- Cloud Container Engine (CCE)
- x.com
- Copy link
Copied.
Connecting to the MQTT Broker Using the Open-source C Language LibraryScenario
MQTT is a message protocol in publish/subscribe mode. It works even on remote devices with poor hardware performance and in poor network conditions.
This article describes how to connect and use IEF's built-in MQTT broker using an open-source C language library, Eclipse Paho C Client Library.
Procedure
- Prepare a Linux computer and download the source code.
git clone https://github.com/eclipse/paho.mqtt.c.git
You can also download the ZIP package from https://github.com/eclipse/paho.mqtt.c and decompress it.
- Install the compilation dependency tool.
For Ubuntu, run the following commands:
apt-get install build-essential gcc make cmake cmake-gui cmake-curses-gui
apt-get install fakeroot fakeroot devscripts dh-make lsb-release
apt-get install libssl-dev
apt-get install ninja-build
For CentOS, run the following commands:
yum install build-essential gcc make cmake cmake-gui cmake-curses-gui
yum install fakeroot fakeroot devscripts dh-make lsb-release
yum install openssl-devel
yum install ninja-build
- Modify the sample code.
Add the following line to the src/samples/ paho_cs_pub.c file of the source code.
ssl_opts.enableServerCertAuth =0;
Add the following line to the src/samples/paho_cs_sub.c file.
- Compile the sample program.
mkdir /tmp/build.paho
cd /tmp/build.paho
cmake -GNinja -DPAHO_BUILD_STATIC=TRUE -DPAHO_BUILD_SHARED=FALSE -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_SAMPLES=TRUE {paho.mqtt.c directory}
ninja package
{paho.mqtt.c directory} is the directory where the source code paho.mqtt.c is stored, for example, /root/work/paho.mqtt.c.
- Go to the directory where the compiled sample program is located, and copy the generated binary files paho_cs_pub and paho_cs_sub to the edge node.
cd /tmp/build.paho/src/samples/
- Download the edge node certificate.
- Log in to the IEF console, choose Managed Resources > Edge Nodes in the navigation pane, and click an edge node name on the displayed page to view the edge node details page. Click the Certificates tab, and click Add Certificate. Figure 1 Adding a certificate
- In the displayed dialog box, enter the certificate name and click OK.
- Copy the downloaded certificate to the edge node and decompress it.
- Run the sample program.
For example, to publish a message to a specified topic, run the following commands to view the paho_cs_pub command instructions.
The following is an example of publishing a message:
./paho_cs_pub -c ssl://127.0.0.1:8883 -q 0 -m "xxx" -t "aaa" --cert /root/mqtt_cert/xOEMIsYVpw_private_cert.crt --key /root/mqtt_cert/xOEMIsYVpw_private_cert.key
Running this command will send a message whose content is xxx to the aaa topic in the built-in MQTT broker. 127.0.0.1:8883 is the address of the built-in MQTT broker of the edge node. /root/mqtt_cert/xOEMIsYVpw_private_cert.crt and /root/mqtt_cert/xOEMIsYVpw_private_cert.key are the edge node certificates.
Previous topic: Connecting Edge Nodes to IEF Through Direct Connect or VPN
Feedback
Was this page helpful?
Helpful Not helpful Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.Which of the following issues have you encountered?
Content is inconsistent with the product UI Unclear descriptions Lack of examples or code Incorrect steps Can't find what I need Lack of best practicesFeedback (optional)
0/500Select at least one type of issue, and enter your comments or suggestions.
Enter a maximum of 500 characters.
Submit CancelFor any further questions, feel free to contact us through the chatbot.
Chatbot Contact Sales After-Sales Self Service- Site Terms
- Privacy Statement
Explore Huawei Cloud
Why Us Customer Stories Trust Center Legal Press ReleasesFeatured Services
Elastic Cloud Server (ECS) Elastic IP (EIP) RDS for MySQL Elastic Volume Service (EVS) MapReduce Service (MRS)Service and Support
Documentation Contact Us Public Notices Support Plans Service Health DashboardAccount and Payment
Top Up Invoices Billing Center My Account Payment MethodQuick Links
Huawei Corporate Huawei Enterprise Huawei Consumer Business Huawei Developers© 2025, Huawei Cloud Computing Technologies Co., Ltd. and/or its affiliates. All rights reserved.
- Site Terms
- Privacy Statement
Từ khóa » Mqtt Github C
-
Eclipse Paho C Client Library For The MQTT Protocol - GitHub
-
A Portable MQTT C Client For Embedded Systems And PCs Alike.
-
Eclipse Mosquitto - An Open Source MQTT Broker - GitHub
-
Eclipse Paho MQTT C/C++ Client For Embedded Platforms - GitHub
-
Awslabs/aws-c-mqtt: C99 Implementation Of The MQTT 3.1.1 ... - GitHub
-
Eclipse Paho MQTT-SN C/C++ Client For Embedded Platforms - GitHub
-
Paho MQTT C Client Library
-
MQTT C Client Library | EMQX 4.4 Documentation
-
Eclipse Paho MQTT C Client
-
Use The Paho MQTT C Client - Best Practices - Alibaba Cloud's
-
Eclipse Mosquitto
-
Mqtt - Go Packages
-
Eclipse Paho MQTT Go Client - Go Packages