{"id":13070,"date":"2025-04-18T20:13:03","date_gmt":"2025-04-18T12:13:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/13070.html"},"modified":"2025-04-18T20:13:03","modified_gmt":"2025-04-18T12:13:03","slug":"%e5%9f%ba%e4%ba%8e-ubuntu-%e6%90%ad%e5%bb%ba-mqtt-%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%b9%b6%e4%bd%bf%e7%94%a8-python-%e5%ae%a2%e6%88%b7%e7%ab%af%e8%bf%9e%e6%8e%a5%e7%9a%84%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/13070.html","title":{"rendered":"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5"},"content":{"rendered":"<h2>\u5728\u7269\u8054\u7f51\u548c\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d&#xff0c;MQTT \u4f5c\u4e3a\u8f7b\u91cf\u7ea7\u6d88\u606f\u534f\u8bae&#xff0c;\u8d8a\u6765\u8d8a\u53d7\u5230\u5f00\u53d1\u8005\u7684\u9752\u7750\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu \u4e0a\u642d\u5efa MQTT \u670d\u52a1\u5668&#xff08;\u4f7f\u7528 Mosquitto&#xff09;&#xff0c;\u5e76\u5728 Windows \u4e0a\u5229\u7528 Python \u7f16\u5199\u5ba2\u6237\u7aef\u8fde\u63a5\u548c\u6d4b\u8bd5\u6d88\u606f\u4f20\u8f93\u7684\u5168\u8fc7\u7a0b\u3002<\/h2>\n<hr \/>\n<h3>\u4e00\u3001\u5728 Ubuntu \u4e0a\u5b89\u88c5\u4e0e\u914d\u7f6e Mosquitto<\/h3>\n<h4>1. \u5b89\u88c5 Mosquitto \u670d\u52a1<\/h4>\n<p>\u9996\u5148&#xff0c;\u66f4\u65b0\u7cfb\u7edf\u540e\u5b89\u88c5 Mosquitto \u53ca\u5176\u5ba2\u6237\u7aef\u5de5\u5177&#xff1a;<\/p>\n<p>sudo apt update<br \/>\nsudo apt upgrade<br \/>\nsudo apt install mosquitto mosquitto-clients<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;Mosquitto \u670d\u52a1\u4f1a\u81ea\u52a8\u542f\u52a8\u3002\u4f60\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u67e5\u770b\u670d\u52a1\u72b6\u6001&#xff1a;<\/p>\n<p>sudo systemctl status mosquitto <\/p>\n<h4>2. \u914d\u7f6e Mosquitto<\/h4>\n<p>\u7f16\u8f91\u4e3b\u914d\u7f6e\u6587\u4ef6 \/etc\/mosquitto\/mosquitto.conf&#xff0c;\u793a\u4f8b\u5982\u4e0b&#xff1a;<\/p>\n<p>pid_file \/run\/mosquitto\/mosquitto.pid<\/p>\n<p>persistence true<br \/>\npersistence_location \/var\/lib\/mosquitto\/<\/p>\n<p>log_dest file \/var\/log\/mosquitto\/mosquitto.log<\/p>\n<p>include_dir \/etc\/mosquitto\/conf.d<\/p>\n<p># \u76d1\u542c\u7aef\u53e3<br \/>\nlistener 1883<\/p>\n<p># \u533a\u5206\u6d4b\u8bd5\u548c\u751f\u4ea7\u73af\u5883<br \/>\nallow_anonymous true  # \u6d4b\u8bd5\u73af\u5883\u5f00\u653e\u533f\u540d\u8bbf\u95ee<br \/>\n# \u5982\u679c\u9700\u8981\u4f7f\u7528\u7528\u6237\u540d\u5bc6\u7801\u8ba4\u8bc1&#xff0c;\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u914d\u7f6e&#xff0c;\u5e76\u5220\u9664\u4e0a\u9762\u7684 allow_anonymous true<br \/>\n# allow_anonymous false<br \/>\n# password_file \/etc\/mosquitto\/passwd<\/p>\n<p>\u6ce8\u610f&#xff1a; \u914d\u7f6e\u6587\u4ef6\u4e2d\u51fa\u73b0\u4e86\u91cd\u590d\u7684\u533f\u540d\u8bbf\u95ee\u8bbe\u7f6e&#xff08;\u4f8b\u5982\u5148 allow_anonymous true \u540e\u53c8\u8bbe\u7f6e allow_anonymous false&#xff09;&#xff0c;\u540e\u8005\u4f1a\u8986\u76d6\u524d\u8005\u3002\u5982\u679c\u662f\u751f\u4ea7\u73af\u5883&#xff0c;\u5efa\u8bae\u5173\u95ed\u533f\u540d\u8bbf\u95ee&#xff0c;\u542f\u7528\u5bc6\u7801\u8ba4\u8bc1&#xff0c;\u5e76\u7528\u547d\u4ee4\u751f\u6210\u5bc6\u7801\u6587\u4ef6&#xff1a;<\/p>\n<p>sudo mosquitto_passwd -c \/etc\/mosquitto\/passwd your_username <\/p>\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u540e&#xff0c;\u8bb0\u5f97\u91cd\u542f Mosquitto \u670d\u52a1&#xff1a;<\/p>\n<p>sudo systemctl restart mosquitto <\/p>\n<p>\u5982\u679c\u9700\u8981\u5f00\u653e\u8fdc\u7a0b\u8bbf\u95ee&#xff0c;\u8bf7\u786e\u4fdd Ubuntu \u9632\u706b\u5899\u5141\u8bb8 1883 \u7aef\u53e3&#xff1a;<\/p>\n<p>sudo ufw allow 1883\/tcp <\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5 MQTT \u670d\u52a1\u5668<\/h3>\n<p>\u5728 Windows \u4e0a&#xff0c;\u6211\u4eec\u91c7\u7528 Python \u7684 paho-mqtt \u5e93\u8fdb\u884c MQTT \u5ba2\u6237\u7aef\u5f00\u53d1\u3002<\/p>\n<h4>1. \u5b89\u88c5 paho-mqtt \u5e93<\/h4>\n<p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u6267\u884c&#xff1a;<\/p>\n<p>pip install paho-mqtt <\/p>\n<h4>2. \u7f16\u5199 Python \u5ba2\u6237\u7aef\u4ee3\u7801<\/h4>\n<p>\u65b0\u7248 paho-mqtt&#xff08;2.x&#xff09;\u4f7f\u7528\u65b0\u7248\u56de\u8c03 API&#xff0c;\u56de\u8c03\u51fd\u6570\u9700\u8981\u591a\u4e00\u4e2a properties \u53c2\u6570\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b&#xff1a;<\/p>\n<p>import paho.mqtt.client as mqtt<\/p>\n<p>def on_connect(client, userdata, flags, rc, properties&#061;None):<br \/>\n    print(&#034;Connected with result code:&#034;, rc)<br \/>\n    # \u8fde\u63a5\u6210\u529f\u540e\u8ba2\u9605 test\/topic<br \/>\n    client.subscribe(&#034;test\/topic&#034;)<br \/>\n    # \u540c\u65f6\u53d1\u5e03\u6d4b\u8bd5\u6d88\u606f<br \/>\n    client.publish(&#034;test\/topic&#034;, &#034;Hello MQTT&#034;)<\/p>\n<p>def on_message(client, userdata, msg):<br \/>\n    print(&#034;Received message:&#034;)<br \/>\n    print(&#034;Topic:&#034;, msg.topic)<br \/>\n    print(&#034;Payload:&#034;, msg.payload.decode())<\/p>\n<p>broker_address &#061; &#034;192.168.116.3&#034;  # \u66ff\u6362\u4e3a\u4f60\u7684 Ubuntu \u670d\u52a1\u5668 IP<br \/>\nport &#061; 1883<\/p>\n<p># \u521b\u5efa\u5ba2\u6237\u7aef\u5b9e\u4f8b<br \/>\nclient &#061; mqtt.Client(client_id&#061;&#034;WindowsClient&#034;)<br \/>\nclient.on_connect &#061; on_connect<br \/>\nclient.on_message &#061; on_message<\/p>\n<p>client.connect(broker_address, port, keepalive&#061;60)<br \/>\nclient.loop_forever()<\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d&#xff1a;<\/p>\n<ul>\n<li>on_connect \u56de\u8c03&#xff1a; \u6210\u529f\u8fde\u63a5\u540e&#xff0c;\u5ba2\u6237\u7aef\u8ba2\u9605\u4e86 test\/topic&#xff0c;\u5e76\u7acb\u5373\u53d1\u5e03\u4e00\u6761 &#034;Hello MQTT&#034; \u7684\u6d88\u606f\u3002<\/li>\n<li>on_message \u56de\u8c03&#xff1a; \u6536\u5230\u6d88\u606f\u540e&#xff0c;\u6253\u5370\u4e3b\u9898\u548c\u6d88\u606f\u5185\u5bb9\u3002<\/li>\n<\/ul>\n<p>\u63d0\u793a&#xff1a; \u5982\u679c\u4f60\u5e0c\u671b\u5728\u8fde\u63a5\u540e\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4efb\u52a1&#xff0c;\u800c\u4e0d\u662f\u88ab loop_forever() \u963b\u585e&#xff0c;\u53ef\u4ee5\u4f7f\u7528 client.loop_start() \u6765\u5f00\u542f\u540e\u53f0\u7ebf\u7a0b&#xff0c;\u518d\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u8c03\u7528 publish \u6216\u5176\u5b83\u64cd\u4f5c\u3002<\/p>\n<h4>3. \u8fd0\u884c\u4e0e\u6d4b\u8bd5<\/h4>\n<p>\u8fd0\u884c\u4e0a\u8ff0 Python \u811a\u672c\u540e&#xff0c;\u63a7\u5236\u53f0\u5e94\u9996\u5148\u8f93\u51fa\u7c7b\u4f3c&#xff1a;<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418121301-680241cdae986.jpg\" \/><\/p>\n<p>Connected with result code: 0 <\/p>\n<p>\u8bf4\u660e\u5ba2\u6237\u7aef\u4e0e MQTT \u670d\u52a1\u5668\u8fde\u63a5\u6210\u529f\u3002\u5f53\u6709\u6d88\u606f\u53d1\u5e03\u5230 test\/topic \u65f6&#xff0c;\u56de\u8c03\u51fd\u6570\u4f1a\u6253\u5370\u51fa\u63a5\u6536\u5230\u7684\u6d88\u606f\u5185\u5bb9\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<h4>1. \u8fde\u63a5\u88ab\u62d2\u7edd&#xff08;ConnectionRefusedError&#xff09;<\/h4>\n<ul>\n<li>\u539f\u56e0&#xff1a; \u53ef\u80fd\u662f\u670d\u52a1\u5668\u672a\u6b63\u786e\u914d\u7f6e\u76d1\u542c\u516c\u7f51\u63a5\u53e3\u6216\u9632\u706b\u5899\u672a\u5f00\u653e\u76f8\u5e94\u7aef\u53e3\u3002<\/li>\n<li>\u89e3\u51b3&#xff1a; \u68c0\u67e5 Mosquitto \u914d\u7f6e\u4e2d\u7684 listener 1883 \u662f\u5426\u6b63\u786e&#xff0c;\u5e76\u786e\u4fdd\u6ca1\u6709\u7ed1\u5b9a\u5230 127.0.0.1&#xff1b;\u540c\u65f6\u68c0\u67e5\u9632\u706b\u5899\u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n<h4>2. \u56de\u8c03 API \u7248\u672c\u9519\u8bef<\/h4>\n<ul>\n<li>\u539f\u56e0&#xff1a; paho-mqtt 2.x \u7248\u672c\u7684\u56de\u8c03\u51fd\u6570\u8981\u6c42\u591a\u4e00\u4e2a properties \u53c2\u6570&#xff0c;\u65e7\u7248\u4ee3\u7801\u4f1a\u62a5\u9519\u3002<\/li>\n<li>\u89e3\u51b3&#xff1a; \u66f4\u65b0\u56de\u8c03\u51fd\u6570\u7b7e\u540d&#xff0c;\u5982\u4e0a\u4f8b\u6240\u793a&#xff0c;\u52a0\u5165 properties&#061;None \u53c2\u6570\u3002<\/li>\n<\/ul>\n<h4>3. \u53d1\u5e03\u6d88\u606f\u4f4d\u7f6e\u95ee\u9898<\/h4>\n<ul>\n<li>\u539f\u56e0&#xff1a; client.loop_forever() \u4f1a\u963b\u585e\u7ebf\u7a0b&#xff0c;\u540e\u7eed\u4ee3\u7801\u65e0\u6cd5\u6267\u884c\u3002<\/li>\n<li>\u89e3\u51b3&#xff1a; \u5c06\u53d1\u5e03\u6d88\u606f\u7684\u4ee3\u7801\u653e\u5165 on_connect \u56de\u8c03\u4e2d&#xff0c;\u6216\u8005\u4f7f\u7528 client.loop_start() \u5f00\u542f\u540e\u53f0\u7ebf\u7a0b\u540e\u518d\u8c03\u7528\u53d1\u5e03\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5728 Ubuntu \u4e0a\u4f7f\u7528 Mosquitto \u642d\u5efa MQTT \u670d\u52a1\u5668\u7684\u57fa\u672c\u6b65\u9aa4&#xff0c;\u5e76\u8be6\u7ec6\u8bb2\u89e3\u4e86\u5982\u4f55\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u3001\u8ba2\u9605\u548c\u53d1\u5e03\u6d88\u606f\u3002\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u5e2e\u52a9\u4f60\u5feb\u901f\u5165\u95e8 MQTT \u7cfb\u7edf\u7684\u642d\u5efa\u4e0e\u8c03\u8bd5\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u6269\u5c55\u8ba4\u8bc1\u3001\u52a0\u5bc6&#xff08;TLS&#xff09;\u4ee5\u53ca\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u6539\u8fdb\u5efa\u8bae&#xff0c;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u8ba8\u8bba&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e46\u6b21\uff0c\u6536\u85cf41\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728 Ubuntu \u4e0a\u4f7f\u7528 Mosquitto \u642d\u5efa MQTT \u670d\u52a1\u5668\u7684\u57fa\u672c\u6b65\u9aa4\uff0c\u5e76\u8be6\u7ec6\u8bb2\u89e3\u4e86\u5982\u4f55\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u3001\u8ba2\u9605\u548c\u53d1\u5e03\u6d88\u606f\u3002\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u5e2e\u52a9\u4f60\u5feb\u901f\u5165\u95e8 MQTT \u7cfb\u7edf\u7684\u642d\u5efa\u4e0e\u8c03\u8bd5\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u6269\u5c55\u8ba4\u8bc1\u3001\u52a0\u5bc6\uff08TLS\uff09\u4ee5\u53ca\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u6539\u8fdb\u5efa\u8bae\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u8ba8\u8bba\uff01_python mqtt\u670d\u52a1\u5668<\/p>\n","protected":false},"author":2,"featured_media":13069,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[320,81,103,43],"topic":[],"class_list":["post-13070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-mqtt","tag-python","tag-ubuntu","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/13070.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e46\u6b21\uff0c\u6536\u85cf41\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728 Ubuntu \u4e0a\u4f7f\u7528 Mosquitto \u642d\u5efa MQTT \u670d\u52a1\u5668\u7684\u57fa\u672c\u6b65\u9aa4\uff0c\u5e76\u8be6\u7ec6\u8bb2\u89e3\u4e86\u5982\u4f55\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u3001\u8ba2\u9605\u548c\u53d1\u5e03\u6d88\u606f\u3002\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u5e2e\u52a9\u4f60\u5feb\u901f\u5165\u95e8 MQTT \u7cfb\u7edf\u7684\u642d\u5efa\u4e0e\u8c03\u8bd5\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u6269\u5c55\u8ba4\u8bc1\u3001\u52a0\u5bc6\uff08TLS\uff09\u4ee5\u53ca\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u6539\u8fdb\u5efa\u8bae\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u8ba8\u8bba\uff01_python mqtt\u670d\u52a1\u5668\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/13070.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T12:13:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418121301-680241cdae986.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/13070.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/13070.html\",\"name\":\"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T12:13:03+00:00\",\"dateModified\":\"2025-04-18T12:13:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/13070.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/13070.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/13070.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/13070.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e46\u6b21\uff0c\u6536\u85cf41\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728 Ubuntu \u4e0a\u4f7f\u7528 Mosquitto \u642d\u5efa MQTT \u670d\u52a1\u5668\u7684\u57fa\u672c\u6b65\u9aa4\uff0c\u5e76\u8be6\u7ec6\u8bb2\u89e3\u4e86\u5982\u4f55\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u3001\u8ba2\u9605\u548c\u53d1\u5e03\u6d88\u606f\u3002\u5e0c\u671b\u8fd9\u7bc7\u535a\u5ba2\u80fd\u5e2e\u52a9\u4f60\u5feb\u901f\u5165\u95e8 MQTT \u7cfb\u7edf\u7684\u642d\u5efa\u4e0e\u8c03\u8bd5\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u6269\u5c55\u8ba4\u8bc1\u3001\u52a0\u5bc6\uff08TLS\uff09\u4ee5\u53ca\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u6539\u8fdb\u5efa\u8bae\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u8ba8\u8bba\uff01_python mqtt\u670d\u52a1\u5668","og_url":"https:\/\/www.wsisp.com\/helps\/13070.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T12:13:03+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418121301-680241cdae986.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/13070.html","url":"https:\/\/www.wsisp.com\/helps\/13070.html","name":"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T12:13:03+00:00","dateModified":"2025-04-18T12:13:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/13070.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/13070.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/13070.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8e Ubuntu \u642d\u5efa MQTT \u670d\u52a1\u5668\u5e76\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b9e\u8df5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/13070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=13070"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/13070\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/13069"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=13070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=13070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=13070"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=13070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}