{"id":25372,"date":"2025-04-19T12:26:14","date_gmt":"2025-04-19T04:26:14","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/25372.html"},"modified":"2025-04-19T12:26:14","modified_gmt":"2025-04-19T04:26:14","slug":"esp32c3%e5%bc%80%e5%8f%91%e6%9d%bf%e9%80%9a%e8%bf%87micropython%e7%9a%84mqtt%e5%ba%93%e8%bf%9emqtt%e7%89%a9%e8%81%94%e7%bd%91%e6%b6%88%e6%81%af%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/25372.html","title":{"rendered":"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668"},"content":{"rendered":"<h2>MQTT\u4ecb\u7ecd<\/h2>\n<p>MQTT&#xff08;Message Queuing Telemetry Transport&#xff09;\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6d88\u606f\u534f\u8bae&#xff0c;\u65e8\u5728\u8bbe\u5907\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1&#xff0c;\u5c24\u5176\u662f\u5728\u7f51\u7edc\u6761\u4ef6\u8f83\u5dee\u7684\u60c5\u51b5\u4e0b\u3002MQTT v3.1.1 \u548c MQTT v5 \u662f\u8be5\u534f\u8bae\u7684\u4e24\u4e2a\u4e3b\u8981\u7248\u672c\u3002<\/p>\n<p>MQTT v3.1.1&#xff1a;<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<ul>\n<li>\u6210\u719f\u548c\u5e7f\u6cdb\u652f\u6301&#xff1a;\u4f5c\u4e3a\u8f83\u65e9\u7684\u7248\u672c&#xff0c;v3.1.1 \u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5b9e\u73b0\u548c\u652f\u6301&#xff0c;\u5305\u62ec\u5404\u79cd\u5ba2\u6237\u7aef\u5e93\u548c\u670d\u52a1\u5668&#xff08;\u4ee3\u7406&#xff09;\u3002<\/li>\n<li>\u7a33\u5b9a\u6027&#xff1a;\u7531\u4e8e\u957f\u65f6\u95f4\u7684\u4f7f\u7528&#xff0c;v3.1.1 \u7248\u672c\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u5f97\u5230\u4e86\u9a8c\u8bc1\u3002<\/li>\n<li>\u8d44\u6e90\u6d88\u8017\u4f4e&#xff1a;\u8bbe\u8ba1\u4e0a\u8003\u8651\u4e86\u4f4e\u5e26\u5bbd\u548c\u4f4e\u529f\u8017\u8bbe\u5907&#xff0c;\u56e0\u6b64\u975e\u5e38\u9002\u5408\u7269\u8054\u7f51&#xff08;IoT&#xff09;\u5e94\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<ul>\n<li>\u529f\u80fd\u9650\u5236&#xff1a;\u4e0e v5 \u76f8\u6bd4&#xff0c;v3.1.1 \u7f3a\u5c11\u4e00\u4e9b\u9ad8\u7ea7\u529f\u80fd&#xff0c;\u5982\u6d88\u606f\u7684\u7cbe\u786e\u4e00\u6b21\u6027\u4f20\u9012&#xff08;Exactly-Once Delivery&#xff09;\u548c\u7528\u6237\u5c5e\u6027&#xff08;User Properties&#xff09;\u3002<\/li>\n<li>\u53ef\u6269\u5c55\u6027&#xff1a;v3.1.1 \u7684\u4e00\u4e9b\u9650\u5236\u53ef\u80fd\u4f7f\u5f97\u5728\u67d0\u4e9b\u9ad8\u7ea7\u573a\u666f\u4e0b\u7684\u4f7f\u7528\u53d7\u5230\u9650\u5236\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>MQTT v5&#xff1a;<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<ul>\n<li>\u589e\u5f3a\u7684\u529f\u80fd&#xff1a;v5 \u5f15\u5165\u4e86\u8bb8\u591a\u65b0\u7279\u6027&#xff0c;\u5305\u62ec\u6d88\u606f\u7684\u7cbe\u786e\u4e00\u6b21\u6027\u4f20\u9012\u3001\u7528\u6237\u5c5e\u6027\u3001\u5171\u4eab\u8ba2\u9605&#xff08;Shared Subscriptions&#xff09;\u3001\u52a8\u6001\u6d88\u606f\u8fc7\u6ee4&#xff08;Dynamic Message Filters&#xff09;\u7b49&#xff0c;\u8fd9\u4e9b\u7279\u6027\u63d0\u9ad8\u4e86\u534f\u8bae\u7684\u7075\u6d3b\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/li>\n<li>\u66f4\u597d\u7684\u9519\u8bef\u5904\u7406&#xff1a;v5 \u63d0\u4f9b\u4e86\u66f4\u8be6\u7ec6\u7684\u9519\u8bef\u4ee3\u7801&#xff0c;\u6709\u52a9\u4e8e\u5ba2\u6237\u7aef\u66f4\u597d\u5730\u7406\u89e3\u548c\u5904\u7406\u9519\u8bef\u60c5\u51b5\u3002<\/li>\n<li>\u6539\u8fdb\u7684\u4f1a\u8bdd\u6062\u590d&#xff1a;v5 \u6539\u8fdb\u4e86\u4f1a\u8bdd\u6062\u590d\u673a\u5236&#xff0c;\u4f7f\u5f97\u5ba2\u6237\u7aef\u53ef\u4ee5\u5728\u65ad\u5f00\u8fde\u63a5\u540e\u66f4\u5feb\u5730\u6062\u590d\u72b6\u6001\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<ul>\n<li>\u517c\u5bb9\u6027\u95ee\u9898&#xff1a;\u7531\u4e8e\u662f\u8f83\u65b0\u7684\u7248\u672c&#xff0c;v5 \u7684\u652f\u6301\u53ef\u80fd\u4e0d\u5982 v3.1.1 \u5e7f\u6cdb&#xff0c;\u8fd9\u53ef\u80fd\u5bfc\u81f4\u4e0e\u65e7\u7cfb\u7edf\u6216\u5ba2\u6237\u7aef\u7684\u4e0d\u517c\u5bb9\u95ee\u9898\u3002<\/li>\n<li>\u5b9e\u73b0\u590d\u6742\u6027&#xff1a;\u65b0\u7279\u6027\u7684\u5f15\u5165\u53ef\u80fd\u589e\u52a0\u4e86\u5b9e\u73b0\u7684\u590d\u6742\u6027&#xff0c;\u5bf9\u4e8e\u8d44\u6e90\u53d7\u9650\u7684\u8bbe\u5907\u6765\u8bf4&#xff0c;\u8fd9\u53ef\u80fd\u662f\u4e00\u4e2a\u6311\u6218\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u603b\u7684\u6765\u8bf4&#xff0c;MQTT v3.1.1 \u7531\u4e8e\u5176\u6210\u719f\u5ea6\u548c\u5e7f\u6cdb\u652f\u6301&#xff0c;\u4ecd\u7136\u662f\u8bb8\u591a\u5e94\u7528\u7684\u9996\u9009\u3002\u800c MQTT v5 \u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u9ad8\u7ea7\u529f\u80fd\u548c\u66f4\u597d\u7684\u9519\u8bef\u5904\u7406&#xff0c;\u9002\u5408\u9700\u8981\u8fd9\u4e9b\u7279\u6027\u7684\u65b0\u5e94\u7528\u3002\u9009\u62e9\u54ea\u4e2a\u7248\u672c\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u9700\u6c42\u3001\u8d44\u6e90\u9650\u5236\u4ee5\u53ca\u5bf9\u65b0\u7279\u6027\u7684\u9700\u6c42\u3002\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb&#xff0c;v5 \u7684\u652f\u6301\u548c\u91c7\u7528\u53ef\u80fd\u4f1a\u589e\u52a0&#xff0c;\u4ece\u800c\u51cf\u5c11\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n<h2>mqtt\u670d\u52a1\u5668\u8f6f\u4ef6Mosquitto<\/h2>\n<p>\u5f53\u524d\u6bd4\u8f83\u6d41\u884c\u7684mqtt\u670d\u52a1\u5668\u662f&#xff1a;Mosquitto\u3001EMQTT\u3001HiveMQ\u7b49&#xff0c;\u7ecf\u8fc7\u77ed\u6682\u7684\u4e86\u89e3&#xff0c;\u6700\u7ec8\u51b3\u5b9a\u4f7f\u7528Mosquitto\u3002<\/p>\n<h3 style=\"background-color:transparent\">FreeBSD\u4e0b\u5b89\u88c5<\/h3>\n<p>pkg install mosquitto <\/p>\n<p>\u5b89\u88c5\u597d\u540e\u63d0\u793a&#xff1a;<\/p>\n<p>Message from mosquitto-2.0.18:<\/p>\n<p>The mosquitto MQTT Python driver is now provided by net\/py-paho-mqtt<\/p>\n<p>FreeBSD\u4e0b\u542f\u52a8\u670d\u52a1&#xff0c;\u82e5\u6ca1\u6709\u5199\u5165rc.conf\u6587\u4ef6&#xff0c;\u5219\u542f\u52a8\u65f6\u9700\u8981\u52a0\u4e0aonestart<\/p>\n<p>sudo service mosquitto start<br \/>\nsudo service mosquitto onestart <\/p>\n<h3>Ubuntu\u4e0b\u5b89\u88c5<\/h3>\n<p>\u5b89\u88c5\u670d\u52a1\u5668<\/p>\n<p>sudo apt install mosquitto <\/p>\n<p>\u5b89\u88c5\u5ba2\u6237\u7aef<\/p>\n<p>sudo apt install mosquitto-clients <\/p>\n<h2>\u542f\u52a8\u5e76\u914d\u7f6e\u670d\u52a1<\/h2>\n<p>\u4ee5Ubuntu\u4e0b\u4e3a\u4f8b\u3002<\/p>\n<h3 style=\"background-color:transparent\">\u542f\u52a8\u670d\u52a1<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528service\u542f\u52a8\u670d\u52a1&#xff1a;<\/p>\n<p>\u200bsudo service mosquitto start<\/p>\n<p>\u5f53\u7136\u4e00\u5f00\u59cb\u4e0d\u77e5\u9053&#xff0c;\u76f4\u63a5\u4f7f\u7528\u8fd0\u884cmosquitto\u547d\u4ee4\u542f\u52a8\u4e86\u670d\u52a1&#xff1a;\u00a0<\/p>\n<p>mosquitto <\/p>\n<p>1731855204: Warning: Unable to drop privileges to &#039;mosquitto&#039; because this user does not exist. Trying &#039;nobody&#039; instead.<\/p>\n<p>1731855204: mosquitto version 2.0.18 starting<\/p>\n<p>1731855204: Using default config.<\/p>\n<p>1731855204: Starting in local only mode. Connections will only be possible from clients running on this machine.<\/p>\n<p>1731855204: Create a configuration file which defines a listener to allow remote access.<\/p>\n<p>1731855204: For more details see https:\/\/mosquitto.org\/documentation\/authentication-methods\/<\/p>\n<p>1731855204: Opening ipv4 listen socket on port 1883.<\/p>\n<p>1731855204: Opening ipv6 listen socket on port 1883.<\/p>\n<p>1731855204: mosquitto version 2.0.18 running<\/p>\n<p>\u540e\u6765\u624d\u77e5\u9053\u53ef\u4ee5\u7528service\u542f\u52a8\u548c\u505c\u6b62\u670d\u52a1<\/p>\n<\/p>\n<p>\u540e\u6765\u53d1\u73b0\u7aef\u53e3\u53ea\u7ed1\u5b9a\u4e86\u672c\u5730ip&#xff0c;\u8981\u7ed1\u5b9a0.0.0.0&#xff0c;\u5219\u9700\u8981\u4fee\u6539\u914d\u7f6e\u3002<\/p>\n<h3>\u5ba2\u6237\u7aef\u6d4b\u8bd5&#xff1a;<\/h3>\n<p>\u9996\u5148\u5728\u670d\u52a1\u5668\u672c\u673a\u6d4b\u8bd5<\/p>\n<h4 style=\"background-color:transparent\">\u6267\u884cmosquitto_sub\u5ba2\u6237\u7aef\u4fa6\u542c\u670d\u52a1&#xff1a;<\/h4>\n<p>mosquitto_sub -t &#034;mytopic&#034; <\/p>\n<h4>\u6267\u884cmosquitto_pub\u53d1\u5e03\u4fe1\u606f<\/h4>\n<p>\u53e6\u4e00\u4e2a\u7ec8\u7aef\u6267\u884c&#xff1a;<\/p>\n<p>mosquitto_pub -t &#034;mytopic&#034; -m &#034;Hello, MQTT!!&#034;<br \/>\n1731855866: New connection from 127.0.0.1:29987 on port 1883.<br \/>\n1731855866: New client connected from 127.0.0.1:29987 as auto-E0721C4C-5B09-EF6C-E3B3-892DBEDC9C05 (p2, c1, k60).<br \/>\n1731855866: Client auto-E0721C4C-5B09-EF6C-E3B3-892DBEDC9C05 disconnected.<\/p>\n<p>\u00a0\u5c31\u4f1a\u53d1\u73b0\u521a\u624d\u7684\u4fe1\u606fHello, MQTT!!\u88ab\u4fa6\u542c\u7aef\u6536\u5230\u4e86&#xff1a;<\/p>\n<p>mosquitto_sub -t &#034;mytopic&#034;<br \/>\nHello, MQTT!! <\/p>\n<p>\u53d1\u9001\u6d88\u606f\u7684\u8be6\u7ec6\u547d\u4ee4&#xff1a;<\/p>\n<p>mosquitto_pub -t &#034;mytopic&#034; -m &#034;Hello, MQTTexitlast1&#034; -h &#034;192.168.0.13&#034;<\/p>\n<p>\u8bbe\u7f6e\u4e86\u7528\u6237\u9a8c\u8bc1\u540e&#xff0c;\u5c31\u9700\u8981\u5e26\u7528\u6237\u540d\u548c\u53e3\u4ee4\u53c2\u6570&#xff0c;\u6bd4\u5982<\/p>\n<p>mosquitto_pub -t &#034;mytopic&#034; -m &#034;Hello, MQTT!!&#034;\u00a0-h 192.168.0.13 -u ral -P ral <\/p>\n<h3>\u4fee\u6539mosquitto\u914d\u7f6e<\/h3>\n<h4>\u6dfb\u52a0\u7528\u6237<\/h4>\n<p>\u5728\/etc\/mosquitto\u76ee\u5f55\u4e0b\u4fee\u6539\u914d\u7f6e\u6587\u4ef6&#xff0c;\u4fee\u6539mosquitto.conf\u6587\u4ef6&#xff0c;\u52a0\u5165\u8fd9\u6837\u4e24\u53e5&#xff1a;<\/p>\n<p>allow_anonymous false<br \/>\npassword_file \/etc\/mosquitto\/passwd <\/p>\n<p>\u6267\u884cmosquitto_passwd\u521b\u5efa\u7528\u6237ral\u5e76\u5199\u5165\/etc\/mosquitto\/passwd\u6587\u4ef6&#xff1a;<\/p>\n<p>sudo mosquitto_passwd -c \/etc\/mosquitto\/passwd ral<br \/>\nPassword:<br \/>\nReenter password: <\/p>\n<p>\u8fd9\u6837\u53d1\u9001\u548c\u63a5\u6536\u4fe1\u606f\u90fd\u9700\u8981\u7528\u6237\u9a8c\u8bc1\u3002<\/p>\n<\/p>\n<h4 style=\"background-color:transparent\">\u4fee\u6539\u7ed1\u5b9a\u670d\u52a1\u52300.0.0.0\u00a0<\/h4>\n<p>\u5728\/etc\/mosquitto\/conf.d\u76ee\u5f55\u91cc\u521b\u5efabindip.conf\u6587\u4ef6&#xff0c;\u52a0\u5165\u8fd9\u4e00\u53e5&#xff1a;<\/p>\n<p>bind_address 0.0.0.0 <\/p>\n<p>\u8fd9\u6837\u670d\u52a1\u5c31\u80fd\u76d1\u542c0.0.0.0 &#xff0c;\u4e5f\u5c31\u662f\u5176\u5b83\u975e\u672c\u673a\u4e5f\u53ef\u4ee5\u8fde\u5b83\u3002<\/p>\n<\/p>\n<p>\u00a0\u5982\u679c\u539f\u6765ufw\u9632\u706b\u5899\u6ca1\u6709\u653e\u5f00&#xff0c;\u90a3\u4e48\u9700\u8981\u653e\u5f001883\u7aef\u53e3&#xff1a;<\/p>\n<p>sudo ufw allow 1883 <\/p>\n<p>\u00a0\u8fd9\u65f6\u5019\u518d\u6d4b\u8bd5\u4e00\u4e0b\u4fe1\u606f&#xff1a;<\/p>\n<p>mosquitto_pub -t &#039;mytopic&#039; -m &#039;ehllo&#039; -u &#039;ral&#039; -P &#039;ral&#039;<\/p>\n<p>\u5ba2\u6237\u7aef\u5e94\u8be5\u80fd\u63a5\u6536\u5230\u4fe1\u606f&#xff1a;<\/p>\n<p>mosquitto_sub -t &#034;mytopic&#034;<br \/>\nHello, MQTT!! <\/p>\n<h4 style=\"background-color:transparent\">\u91cd\u542fmosquitto\u670d\u52a1<\/h4>\n<p>\u6bcf\u6b21\u4fee\u6539mosquitto\u914d\u7f6e\u540e&#xff0c;\u90fd\u8981\u91cd\u542f\u670d\u52a1<\/p>\n<p>sudo service mosquitto restart <\/p>\n<h3>\u5e26\u7528\u6237\u9a8c\u8bc1\u7684\u6d4b\u8bd5<\/h3>\n<p>\u6d88\u606f\u63a5\u6536&#xff1a;<\/p>\n<p># \u5e26\u4e0a\u7528\u6237\u9a8c\u8bc1<br \/>\nmosquitto_sub -t &#034;mytopic&#034; -u &#039;ral&#039; -P &#039;ral&#039;<br \/>\n# \u6216\u662f\u5e26\u4e0a\u5730\u5740<br \/>\nmosquitto_sub -t &#034;mytopic&#034; -u &#039;ral&#039; -P &#039;ral&#039;  -h &#039;192.168.0.13&#039; <\/p>\n<p>\u6d88\u606f\u53d1\u9001&#xff1a;<\/p>\n<p># \u5e26\u7528\u6237\u9a8c\u8bc1\u7684\u6d88\u606f\u53d1\u9001<br \/>\nmosquitto_pub -t &#039;mytopic&#039; -m &#039;hello world&#039; -u &#039;ral&#039; -P &#039;ral&#039;<br \/>\n# \u5e26\u4e0a\u670d\u52a1\u5668ip\u5730\u5740<br \/>\nmosquitto_pub -t &#039;mytopic&#039; -m &#039;hello world2&#039; -u &#039;ral&#039; -P &#039;ral&#039; -h &#039;192.168.0.13&#039; <\/p>\n<p>\u63a5\u6536\u7aef\u63a5\u6536\u5230\u4fe1\u606f&#xff1a;<\/p>\n<p>mosquitto_sub -t &#034;mytopic&#034; -u &#039;ral&#039; -P &#039;ral&#039;  -h &#039;192.168.0.13&#039;<br \/>\nhello world<\/p>\n<p>\u8bc1\u660e\u914d\u7f6e\u8bbe\u7f6e\u7684\u6b63\u786e&#xff0c;\u670d\u52a1\u5668\u4e00\u5207\u6b63\u5e38&#xff01;\u00a0<\/p>\n<h2>esp32c3\u5f00\u53d1\u677f\u914d\u7f6e<\/h2>\n<\/p>\n<p>esp32c3\u5f00\u53d1\u677f\u70e7\u5f55micropython \u4ea4\u4e92\u73af\u5883&#xff0c;\u53c2\u89c1&#xff1a;esp32c3\u5b89\u88c5micropython\u73af\u5883-CSDN\u535a\u5ba2<\/p>\n<p>\u70e7\u5f55\u597d\u56fa\u4ef6&#xff0c;\u542f\u52a8\u5f00\u53d1\u677f&#xff0c;\u8fdb\u5165micropython\u4ea4\u4e92\u73af\u5883\u3002\u53c2\u89c1&#xff1a;esp32-c3\u5f00\u53d1\u677f\u5f00\u7bb1\u7b2c\u4e00\u6b65&#xff1a;\u8fde\u4e0ausb\u53e3\u770blog\u4fe1\u606f-CSDN\u535a\u5ba2<\/p>\n<\/p>\n<h3>\u5f00\u53d1\u677f\u542f\u52a8wifi\u8fde\u4e0a\u7f51<\/h3>\n<p>\u4ea4\u4e92\u754c\u9762\u91cc\u6267\u884c\u4e0b\u9762\u4ee3\u7801\u8fdewifi&#xff0c;\u6ce8\u610fwifi\u7684\u540d\u5b57\u548c\u5bc6\u7801\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539&#xff1a;<\/p>\n<p>import network<br \/>\nimport time<br \/>\nnic &#061; network.WLAN(network.STA_IF)<br \/>\nnic.active(True)<br \/>\n# nic.scan()<br \/>\nif not nic.isconnected():<br \/>\n    nic.connect(&#034;wifi\u540d\u5b57&#034;, &#034;wifi\u5bc6\u7801&#034;)<br \/>\n    print(&#034;Waiting for connection&#8230;&#034;)<br \/>\n    while not nic.isconnected():<br \/>\n        time.sleep(1)<\/p>\n<p>print(nic.ipconfig(&#034;addr4&#034;))<\/p>\n<p>\u00a0\u5982\u679c\u80fd\u8f93\u51fa\u7f51\u7edc\u4fe1\u606f&#xff0c;\u90a3\u4e48\u5c31\u8bc1\u660e\u8fde\u4e0a\u4e86wifi<\/p>\n<p>&gt;&gt;&gt; print(nic.ipconfig(&#034;addr4&#034;))<br \/>\n(&#039;192.168.0.104&#039;, &#039;255.255.255.0&#039;) <\/p>\n<h3>\u5f00\u53d1\u677f\u63a5\u6536mqtt\u6d88\u606f\u4ee3\u7801<\/h3>\n<p>\u00a0\u7ee7\u7eed\u6267\u884cesp32c3\u5f00\u53d1\u677f\u91cc\u7684micropython\u4ee3\u7801&#xff1a;<\/p>\n<p>from umqtt.simple import MQTTClient<\/p>\n<p># \u5b9a\u4e49 MQTT \u4ee3\u7406\u7684\u5730\u5740\u548c\u7aef\u53e3<br \/>\nSERVER &#061; &#034;192.168.0.13&#034;<br \/>\nPORT &#061; 1883<\/p>\n<p># \u5b9a\u4e49\u5ba2\u6237\u7aef ID\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801<br \/>\nCLIENT_ID &#061; &#034;my_client_id&#034;<br \/>\nUSERNAME &#061; &#034;ral&#034;<br \/>\nPASSWORD &#061; &#034;ral&#034;<\/p>\n<p># \u5b9a\u4e49\u8981\u8ba2\u9605\u7684\u4e3b\u9898<br \/>\nTOPIC &#061; b&#034;mytopic&#034;<\/p>\n<p># \u521b\u5efa MQTTClient \u5b9e\u4f8b&#xff0c;\u5e76\u4f20\u9012\u7528\u6237\u540d\u548c\u5bc6\u7801\u53c2\u6570<br \/>\nclient &#061; MQTTClient(CLIENT_ID, SERVER, PORT, user&#061;USERNAME, password&#061;PASSWORD)<\/p>\n<p># \u8fde\u63a5\u5230 MQTT \u4ee3\u7406<br \/>\nclient.connect()<\/p>\n<p># \u8ba2\u9605\u4e3b\u9898<br \/>\nclient.subscribe(TOPIC)<\/p>\n<p># \u5b9a\u4e49\u6d88\u606f\u56de\u8c03\u51fd\u6570<br \/>\ndef sub_cb(topic, msg):<br \/>\n    print(&#034;Received message: &#034;, msg)<\/p>\n<p># \u8bbe\u7f6e\u6d88\u606f\u56de\u8c03\u51fd\u6570<br \/>\nclient.set_callback(sub_cb)<\/p>\n<p># \u8fdb\u5165\u6d88\u606f\u5faa\u73af<br \/>\nwhile True:<br \/>\n    client.wait_msg()<\/p>\n<p>\u00a0\u4e2d\u6587\u4f1a\u5360\u7528\u8f93\u5165\u7f13\u51b2\u533a\u5927\u5c0f&#xff0c;\u6709\u70b9\u5e72\u6270\u8f93\u5165&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u9ecf\u8d34\u4e0b\u9762\u53bb\u6389\u4e2d\u6587\u6ce8\u91ca\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>from umqtt.simple import MQTTClient<\/p>\n<p>SERVER &#061; &#034;192.168.0.13&#034;<br \/>\nPORT &#061; 1883<\/p>\n<p>CLIENT_ID &#061; &#034;my_client_id&#034;<br \/>\nUSERNAME &#061; &#034;ral&#034;<br \/>\nPASSWORD &#061; &#034;ral&#034;<\/p>\n<p>TOPIC &#061; b&#034;mytopic&#034;<\/p>\n<p>client &#061; MQTTClient(CLIENT_ID, SERVER, PORT, user&#061;USERNAME, password&#061;PASSWORD)<\/p>\n<p>client.connect()<\/p>\n<p>def sub_cb(topic, msg):<br \/>\n    print(&#034;Received message: &#034;, msg)<\/p>\n<p>client.set_callback(sub_cb)<\/p>\n<p>client.subscribe(TOPIC)<\/p>\n<p>while True:<br \/>\n    client.wait_msg()<\/p>\n<p>\u4e0d\u8981\u4e00\u6b21\u9ecf\u8d34\u4e00\u5927\u6bb5&#xff0c;\u53ef\u4ee52-3\u53e5\u9ecf\u8d34&#xff0c;\u6bd4\u5982\u50cf\u8fd9\u53e5&#xff1a;client &#061; MQTTClient(CLIENT_ID, SERVER, PORT, user&#061;USERNAME, password&#061;PASSWORD) \u6bd4\u8f83\u957f&#xff0c;\u5c31\u5355\u72ec\u9ecf\u8d34\u3002<\/p>\n<p>\u5f00\u53d1\u677f\u8fd0\u884c\u540e&#xff0c;\u7528\u4e00\u4e2a\u5ba2\u6237\u7aef\u53d1\u9001\u6d88\u606f\u00a0<\/p>\n<p># \u672c\u673a<br \/>\nmosquitto_pub -t &#039;mytopic&#039; -m &#039;hello world&#039; -u &#039;ral&#039; -P &#039;ral&#039;<br \/>\n# \u975e\u672c\u673a<br \/>\nmosquitto_pub -t &#039;mytopic&#039; -m &#039;hello world2&#039; -u &#039;ral&#039; -P &#039;ral&#039; -h &#039;192.168.0.13&#039; <\/p>\n<p>\u8fd9\u65f6\u5019\u5f00\u53d1\u677f\u4ea4\u4e92\u754c\u9762\u91cc\u5c31\u80fd\u63a5\u6536\u5230\u53d1\u9001\u7684\u4fe1\u606f\u4e86&#xff01;<\/p>\n<p>&gt;&gt;&gt; while True:<br \/>\n&#8230;     client.wait_msg()<br \/>\n&#8230;<br \/>\nReceived message:  b&#039;hello&#039;<br \/>\n48 <\/p>\n<p>\u8fd9\u6837\u6211\u4eec\u8fd9\u6b21\u5b9e\u8df5\u5c31\u5b8c\u6210\u4e86&#xff01;<\/p>\n<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u603b\u4f53\u662f\u4e00\u6b21\u975e\u5e38\u6109\u5feb\u7684esp32c3\u5f00\u53d1\u677f\u4e0emqtt\u670d\u52a1\u5668\u901a\u4fe1\u7684\u5b9e\u8df5\u64cd\u4f5c\u3002\u4f46\u662f\u7531\u4e8e\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528mosquitto&#xff0c;\u5bf9\u5b83\u7684\u914d\u7f6e\u4e0d\u719f\u6089&#xff0c;\u540c\u65f6\u4e5f\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528micropython\u91cc\u7684mqtt\u6a21\u5757&#xff08;umqtt&#xff09;\u8fdb\u884c\u901a\u4fe1&#xff0c;\u5bf9\u5b83\u4e5f\u4e0d\u719f\u6089&#xff0c;\u6240\u4ee5\u8fd9\u6b21\u5b9e\u8df5\u4e2d\u7bad\u8d70\u4e86\u5f88\u591a\u5f2f\u8def&#xff0c;\u78b0\u5230\u5f88\u591a\u95ee\u9898&#xff0c;\u5e78\u8fd0\u7684\u662f\u90fd\u89e3\u51b3\u4e86\u3002<\/p>\n<p>mqtt\u670d\u52a1\u5668&#xff0c;\u7528\u4e86\u534a\u5929\u65f6\u95f4\u9009\u578b\u4e3amosquitto&#xff0c;\u5927\u7ea6\u8fd9\u5c31\u662f\u773c\u7f18\u5427&#xff0c;\u6bd5\u7adf\u5b83\u662feclicps\u65d7\u4e0b\u7684&#xff0c;\u800c\u4e14FreeBSD\u8fd8\u6709\u5b83\u7684pkg\u5305\u3002\u5b89\u88c5mosquitto\u540e&#xff0c;\u9700\u8981\u4fee\u6539\u5176\u914d\u7f6e&#xff0c;\u6bd4\u5982\u6dfb\u52a0\u7528\u6237\u548c\u5bc6\u7801\u5230\u6307\u5b9a\u7684\u6587\u4ef6&#xff0c;\u4fee\u6539\u7ed1\u5b9aip\u52300.0.0.0&#xff0c;\u5728Ubuntu\u670d\u52a1\u5668ufw\u9632\u706b\u5899\u4e2d\u653e\u5f001883\u7aef\u53e3\u3002<\/p>\n<p>esp32c3\u5f00\u53d1\u677f\u8fd9\u5757&#xff0c;\u9996\u5148\u9700\u8981\u70e7micropython\u4ea4\u4e92\u73af\u5883\u7684\u56fa\u4ef6&#xff0c;\u7136\u540eusb\u4e32\u53e3\u767b\u5f55\u5230micropython\u7684\u4ea4\u4e92\u754c\u9762&#xff0c;\u8f93\u5165python\u4ee3\u7801\u3002\u5148\u8981\u914d\u7f6e\u597dWiFi\u542f\u52a8tcp\/ip\u7f51\u7edc&#xff0c;\u7136\u540e\u5c31\u662f\u8c03\u7528umqtt\u6a21\u5757\u8fdb\u884c\u4fa6\u542cmqtt\u6d88\u606f\u3002micropython\u7684\u7f13\u51b2\u533a\u8f83\u5c0f&#xff0c;\u4e0d\u80fd\u50cf\u666e\u901apython\u91cc\u9762\u90a3\u6837\u4e00\u4e0b\u5b50\u53ef\u4ee5\u9ecf\u8d34\u592a\u957f\u7684\u4ee3\u7801\u6bb5&#xff0c;\u8fd9\u4e5f\u9700\u8981\u6ce8\u610f\u3002<\/p>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419042612-680325e4e3171.png\" \/><\/p>\n<h2>\u8c03\u8bd5<\/h2>\n<h3 style=\"background-color:transparent\">esp32c3\u4e0amqtt\u8fde\u63a5\u5931\u8d25<\/h3>\n<p>\u5176\u5b9e\u8fd9\u662f\u4e00\u4e2a\u5927\u95ee\u9898&#xff0c;\u540e\u6765\u662f\u5206\u89e3\u6210\u51e0\u4e2a\u5c0f\u95ee\u9898\u4e00\u4e00\u89e3\u51b3\u7684\u3002<\/p>\n<p>&gt;&gt;&gt; mqtt_client &#061; connect_mqtt()<\/p>\n<p>Traceback (most recent call last):<\/p>\n<p>\u00a0 File &#034;&lt;stdin&gt;&#034;, line 1, in &lt;module&gt;<\/p>\n<p>\u00a0 File &#034;&lt;stdin&gt;&#034;, line 3, in connect_mqtt<\/p>\n<p>\u00a0 File &#034;umqtt\/simple.py&#034;, line 66, in connect<\/p>\n<p>OSError: [Errno 104] ECONNRESET<\/p>\n<p>\u60f3\u8d77\u6765\u4e86&#xff0c;\u539f\u6765\u662fmqtt\u670d\u52a1\u5668\u8de8\u4e86\u7f51\u6bb5&#xff0c;\u4e3a\u4e86\u7b80\u5316\u6d4b\u8bd5&#xff0c;\u540e\u6765\u5c31\u7528\u4e86linux\u5ba2\u6237\u7aefmosquitto_pub\u548cmosquitto_sub -t &#034;mytopic&#034; \u5148\u8fdb\u884c\u6d4b\u8bd5\u3002&#xff08;\u5176\u5b9eesp32\u7684\u7f51\u7edc\u6a21\u5757\u662f\u53ef\u4ee5\u8054\u7f51\u3001\u8de8\u7f51\u6bb5\u901a\u4fe1\u7684&#xff09;<\/p>\n<\/p>\n<p>\u5728\u540c\u4e00\u7f51\u6bb5\u5f00\u670d\u52a1\u5668&#xff0c;\u8fd8\u662f\u4e0d\u884c<\/p>\n<p>\u539f\u6765\u662fufw\u9632\u706b\u5899\u6ca1\u6709\u653e\u5f00&#xff0c;\u653e\u5f001883\u7aef\u53e3<\/p>\n<p>sudo ufw allow 1883 <\/p>\n<p>\u53d1\u73b0\u6ca1\u6709\u7ed1\u5b9a0.0.0.0&#xff0c;\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/etc\/mosquitto\/conf.d\/bindip.conf&#xff0c;\u52a0\u5165\u8fd9\u53e5&#xff1a;<\/p>\n<p>bind_address 0.0.0.0<\/p>\n<p>\u7136\u540e\u91cd\u542f\u670d\u52a1<\/p>\n<p>sudo service mosquitto restart <\/p>\n<p>\u7528\u5ba2\u6237\u7aefmosquitto_pub\u518d\u6d4b\u8bd5\u6709\u5982\u4e0b\u62a5\u9519&#xff1a;\u00a0<\/p>\n<h3 style=\"background-color:transparent\">\u53d1\u9001\u4fe1\u606f\u62a5\u9519Connection Refused: not authorised.<\/h3>\n<p>mosquitto_pub -t &#034;mytopic&#034; -m &#034;Hello, MQTTexitlast1&#034; -h &#034;192.168.0.13&#034;<\/p>\n<p>Connection error: Connection Refused: not authorised.<\/p>\n<p>\u6dfb\u52a0\u7528\u6237&#xff1a;<\/p>\n<p>sudo mosquitto_passwd -c \/etc\/mosquitto\/passwd ral<br \/>\nPassword:<br \/>\nReenter password: <\/p>\n<p>\u5728\/etc\/mosquitto\u76ee\u5f55\u4e0b\u7684mosquitto.conf\u6587\u4ef6\u4e2d\u52a0\u5165\u4fe1\u606f&#xff1a;<\/p>\n<p>allow_anonymous false<br \/>\npassword_file \/etc\/mosquitto\/passwd <\/p>\n<p>\u91cd\u542f\u670d\u52a1\u540e\u6d4b\u8bd5&#xff1a;\u00a0<\/p>\n<p>mosquitto_pub -t &#034;mytopic&#034; -m &#034;Hello, MQTT!!&#034;\u00a0-h 192.168.0.13 -u ral -P ral <\/p>\n<p>\u7ec8\u4e8e\u4e0d\u62a5\u7528\u6237\u9a8c\u8bc1\u9519\u4e86&#xff0c;\u73b0\u5728\u62a5\u9519&#xff1a;<\/p>\n<h3 style=\"background-color:transparent\">esp32\u8fdemosquitto\u62a5\u9519 Subscribe callback is not set<\/h3>\n<p>&gt;&gt;&gt; client.subscribe(TOPIC)<\/p>\n<p>Traceback (most recent call last):<\/p>\n<p>\u00a0 File &#034;&lt;stdin&gt;&#034;, line 1, in &lt;module&gt;<\/p>\n<p>\u00a0 File &#034;umqtt\/simple.py&#034;, line 152, in subscribe<\/p>\n<p>AssertionError: Subscribe callback is not set<\/p>\n<p>\u662f\u90a3\u6bb5\u4ee3\u7801\u53c8\u95ee\u9898&#xff0c;\u6362\u4ee3\u7801&#xff1a;<\/p>\n<p>from umqtt.simple import MQTTClient<\/p>\n<p>SERVER &#061; &#034;mqtt.eclipse.org&#034;<br \/>\nPORT &#061; 1883<\/p>\n<p>CLIENT_ID &#061; &#034;my_client_id&#034;<br \/>\nUSERNAME &#061; &#034;my_username&#034;<br \/>\nPASSWORD &#061; &#034;my_password&#034;<\/p>\n<p>TOPIC &#061; b&#034;test\/topic&#034;<\/p>\n<p>SERVER &#061; &#034;192.168.0.13&#034;<br \/>\nPORT &#061; 1883<\/p>\n<p>CLIENT_ID &#061; &#034;my_client_id&#034;<br \/>\nUSERNAME &#061; &#034;ral&#034;<br \/>\nPASSWORD &#061; &#034;ral&#034;<\/p>\n<p>TOPIC &#061; b&#034;mytopic&#034;<\/p>\n<p>client &#061; MQTTClient(CLIENT_ID, SERVER, PORT, user&#061;USERNAME, password&#061;PASSWORD)<\/p>\n<p>client.connect()<\/p>\n<p>def sub_cb(topic, msg):<br \/>\n    print(&#034;Received message: &#034;, msg)<\/p>\n<p>client.set_callback(sub_cb)<\/p>\n<p>client.subscribe(TOPIC)<\/p>\n<p>while True:<br \/>\n    client.wait_msg()<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u5c31ok\u4e86&#xff01;<\/p>\n<\/p>\n<h3>esp32 micropython\u91cc\u9ecf\u8d34python\u4ee3\u7801\u6709\u65f6\u5019\u4f1a\u51fa\u9519<\/h3>\n<p>\u53d1\u73b0\u9ecf\u8d34\u4ee3\u7801\u5230\u540e\u9762\u5c31\u4e71\u4e86&#xff0c;\u4f30\u8ba1\u662f\u9ecf\u8d34\u957f\u5ea6\u8d85\u9650\u5bfc\u81f4\u7684&#xff0c;\u51cf\u5c11\u9ecf\u8d34\u957f\u5ea6&#xff0c;\u95ee\u9898\u89e3\u51b3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.3k\u6b21\uff0c\u70b9\u8d5e44\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u603b\u4f53\u662f\u4e00\u6b21\u975e\u5e38\u6109\u5feb\u7684esp32c3\u5f00\u53d1\u677f\u4e0emqtt\u670d\u52a1\u5668\u901a\u4fe1\u7684\u5b9e\u8df5\u64cd\u4f5c\u3002\u4f46\u662f\u7531\u4e8e\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528mosquitto\uff0c\u5bf9\u5b83\u7684\u914d\u7f6e\u4e0d\u719f\u6089\uff0c\u540c\u65f6\u4e5f\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528micropython\u91cc\u7684mqtt\u6a21\u5757\uff08umqtt\uff09\u8fdb\u884c\u901a\u4fe1\uff0c\u5bf9\u5b83\u4e5f\u4e0d\u719f\u6089\uff0c\u6240\u4ee5\u8fd9\u6b21\u5b9e\u8df5\u4e2d\u7bad\u8d70\u4e86\u5f88\u591a\u5f2f\u8def\uff0c\u78b0\u5230\u5f88\u591a\u95ee\u9898\uff0c\u5e78\u8fd0\u7684\u662f\u90fd\u89e3\u51b3\u4e86\u3002mqtt\u670d\u52a1\u5668\uff0c\u7528\u4e86\u534a\u5929\u65f6\u95f4\u9009\u578b\u4e3amosquitto\uff0c\u5927\u7ea6\u8fd9\u5c31\u662f\u773c\u7f18\u5427\uff0c\u6bd5\u7adf\u5b83\u662feclicps\u65d7\u4e0b\u7684\uff0c\u800c\u4e14FreeBSD\u8fd8\u6709\u5b83\u7684pkg\u5305\u3002_micropython mqtt\u5e93<\/p>\n","protected":false},"author":2,"featured_media":25371,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[179,2001,320,270,220,1281],"topic":[],"class_list":["post-25372","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-esp32","tag-micropython","tag-mqtt","tag-270","tag-220","tag-1281"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668 - \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\/25372.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.3k\u6b21\uff0c\u70b9\u8d5e44\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u603b\u4f53\u662f\u4e00\u6b21\u975e\u5e38\u6109\u5feb\u7684esp32c3\u5f00\u53d1\u677f\u4e0emqtt\u670d\u52a1\u5668\u901a\u4fe1\u7684\u5b9e\u8df5\u64cd\u4f5c\u3002\u4f46\u662f\u7531\u4e8e\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528mosquitto\uff0c\u5bf9\u5b83\u7684\u914d\u7f6e\u4e0d\u719f\u6089\uff0c\u540c\u65f6\u4e5f\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528micropython\u91cc\u7684mqtt\u6a21\u5757\uff08umqtt\uff09\u8fdb\u884c\u901a\u4fe1\uff0c\u5bf9\u5b83\u4e5f\u4e0d\u719f\u6089\uff0c\u6240\u4ee5\u8fd9\u6b21\u5b9e\u8df5\u4e2d\u7bad\u8d70\u4e86\u5f88\u591a\u5f2f\u8def\uff0c\u78b0\u5230\u5f88\u591a\u95ee\u9898\uff0c\u5e78\u8fd0\u7684\u662f\u90fd\u89e3\u51b3\u4e86\u3002mqtt\u670d\u52a1\u5668\uff0c\u7528\u4e86\u534a\u5929\u65f6\u95f4\u9009\u578b\u4e3amosquitto\uff0c\u5927\u7ea6\u8fd9\u5c31\u662f\u773c\u7f18\u5427\uff0c\u6bd5\u7adf\u5b83\u662feclicps\u65d7\u4e0b\u7684\uff0c\u800c\u4e14FreeBSD\u8fd8\u6709\u5b83\u7684pkg\u5305\u3002_micropython mqtt\u5e93\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/25372.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-19T04:26:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419042612-680325e4e3171.png\" \/>\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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/25372.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/25372.html\",\"name\":\"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T04:26:14+00:00\",\"dateModified\":\"2025-04-19T04:26:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/25372.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/25372.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/25372.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668\"}]},{\"@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":"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668 - \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\/25372.html","og_locale":"zh_CN","og_type":"article","og_title":"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.3k\u6b21\uff0c\u70b9\u8d5e44\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u603b\u4f53\u662f\u4e00\u6b21\u975e\u5e38\u6109\u5feb\u7684esp32c3\u5f00\u53d1\u677f\u4e0emqtt\u670d\u52a1\u5668\u901a\u4fe1\u7684\u5b9e\u8df5\u64cd\u4f5c\u3002\u4f46\u662f\u7531\u4e8e\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528mosquitto\uff0c\u5bf9\u5b83\u7684\u914d\u7f6e\u4e0d\u719f\u6089\uff0c\u540c\u65f6\u4e5f\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528micropython\u91cc\u7684mqtt\u6a21\u5757\uff08umqtt\uff09\u8fdb\u884c\u901a\u4fe1\uff0c\u5bf9\u5b83\u4e5f\u4e0d\u719f\u6089\uff0c\u6240\u4ee5\u8fd9\u6b21\u5b9e\u8df5\u4e2d\u7bad\u8d70\u4e86\u5f88\u591a\u5f2f\u8def\uff0c\u78b0\u5230\u5f88\u591a\u95ee\u9898\uff0c\u5e78\u8fd0\u7684\u662f\u90fd\u89e3\u51b3\u4e86\u3002mqtt\u670d\u52a1\u5668\uff0c\u7528\u4e86\u534a\u5929\u65f6\u95f4\u9009\u578b\u4e3amosquitto\uff0c\u5927\u7ea6\u8fd9\u5c31\u662f\u773c\u7f18\u5427\uff0c\u6bd5\u7adf\u5b83\u662feclicps\u65d7\u4e0b\u7684\uff0c\u800c\u4e14FreeBSD\u8fd8\u6709\u5b83\u7684pkg\u5305\u3002_micropython mqtt\u5e93","og_url":"https:\/\/www.wsisp.com\/helps\/25372.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T04:26:14+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419042612-680325e4e3171.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/25372.html","url":"https:\/\/www.wsisp.com\/helps\/25372.html","name":"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T04:26:14+00:00","dateModified":"2025-04-19T04:26:14+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/25372.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/25372.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/25372.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"esp32c3\u5f00\u53d1\u677f\u901a\u8fc7micropython\u7684mqtt\u5e93\u8fdeMQTT\u7269\u8054\u7f51\u6d88\u606f\u670d\u52a1\u5668"}]},{"@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\/25372","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=25372"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/25372\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/25371"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=25372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=25372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=25372"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=25372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}