{"id":958,"date":"2018-07-25T13:16:53","date_gmt":"2018-07-25T05:16:53","guid":{"rendered":"https:\/\/blog.laszlo.tw\/?p=958"},"modified":"2021-05-04T04:30:17","modified_gmt":"2021-05-04T04:30:17","slug":"mqtt%e5%88%9d%e6%8e%a2","status":"publish","type":"post","link":"https:\/\/blog.laszlo.tw\/?p=958","title":{"rendered":"MQTT\u521d\u63a2"},"content":{"rendered":"<p>\u6700\u8fd1\u56e0\u63a5\u6536\u5373\u6642\u8a0a\u606f \u610f\u5916\u8a8d\u8b58MQTT\u9019\u6b3eIOT\u767c\u5e03\/\u8a02\u95b1\u67b6\u69cb\u7684\u5354\u5b9a<br \/>\n<!--more--><\/p>\n<h3><strong>\u5de5\u5177<\/strong><\/h3>\n<p style=\"padding-left: 30px;\">CLI\u53ef\u4ee5\u5b89\u88ddmosquitto-clients \u5167\u6709mosquitto_pub\u00a0mosquitto_sub\u6307\u4ee4\u4f9b\u4f7f\u7528<\/p>\n<p style=\"padding-left: 30px;\">Python\u53ef\u4ee5\u900f\u904epip install paho-mqtt<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/www.eclipse.org\/paho\/clients\/python\/docs\/\">Python subscribe example in Eclipse paho Getting Started<\/a><\/p>\n<h3><strong>Topic\u7b26\u865f\u610f\u7fa9<\/strong><\/h3>\n<p style=\"padding-left: 30px;\">+ \u4e00\u968e\u5c64\u4efb\u610f\u6578(foo\/+ \u4e0d\u5305\u542bfoo\/+\/bar)<br \/>\n# \u591a\u968e\u5c64\u4efb\u610f\u6578(foo\/#\u5305\u542bfoo\/\u4ee5\u4e0b\u4efb\u4f55\u7bc0\u9ede)<br \/>\n$SYS\u7cfb\u7d71\u8a0a\u606f(\u5982$SYS\/# \u6709loading, users info\u7b49)<br \/>\n<a href=\"http:\/\/test.mosquitto.org\/sys\/\">\u8996\u89ba\u5316$SYS Tree<\/a><\/p>\n<h3><strong>CLI\u53c3\u6578<\/strong><\/h3>\n<p style=\"padding-left: 30px;\">default port 1883 (non-tls) 8883 (over tls)<\/p>\n<p style=\"padding-left: 30px;\">\u53c3\u6578 -h [host] -p [port] -t [topic] -u [username] -P [password] -i [client_id] -m [msg]<br \/>\n-d \u986f\u793adebug\u9023\u63a5\u8a0a\u606f -v \u8a0a\u606f\u8f38\u51fatopic\u540d\u7a31<\/p>\n<p style=\"padding-left: 30px;\">over tls\u7684\u90e8\u4efd\u9700\u6307\u5b9a&#8211;cafile or &#8211;capath \/etc\/ssl\/certs<br \/>\n\u6216\u662f\u66f4\u56b4\u8b39\u7c3d\u767cclient\u5bc6\u9470 &#8211;cert [client.crt] &#8211;key [client.key]<\/p>\n<h3><strong>Mosquitto Client Debug\u8a0a\u606f<\/strong><\/h3>\n<p style=\"padding-left: 30px;\">\u6301\u7e8c\u986f\u793asending CONNECT\u662fover tls\u672a\u6307\u5b9a\u6191\u8b49<\/p>\n<p style=\"padding-left: 30px;\">Error: A TLS error occurred. \u6307\u5b9a\u932f\u8aa4\u7684\u6191\u8b49<\/p>\n<p style=\"padding-left: 30px;\">Connection Refused: identifier rejected. \u5e33\u865f\u6216\u5bc6\u78bc\u932f\u8aa4<\/p>\n<h3><strong>Connack\u00a0Return\u00a0Codes<\/strong><\/h3>\n<p style=\"padding-left: 30px;\">0 Connection accepted<br \/>\n1 The Server does not support the level of the MQTT protocol requested by the Client<br \/>\n2 The Client identifier is correct UTF-8 but not allowed by the Server<br \/>\n3 The Network Connection has been made but the MQTT service is unavailable<br \/>\n4 The data in the user name or password is malformed<br \/>\n5 The Client is not authorized to connect<\/p>\n<h3><strong>\u597d\u7528\u7db2\u7ad9<\/strong><\/h3>\n<p style=\"padding-left: 30px;\"><a href=\"http:\/\/www.hivemq.com\/demos\/websocket-client\/\">Web Client #1<\/a><\/p>\n<p style=\"padding-left: 30px;\"><a href=\"http:\/\/mitsuruog.github.io\/what-mqtt\/\">Web Client #2<\/a><\/p>\n<p style=\"padding-left: 30px;\"><a href=\"http:\/\/test.mosquitto.org\/\">mosquiito test server<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u56e0\u63a5\u6536\u5373\u6642\u8a0a\u606f \u610f\u5916\u8a8d\u8b58MQTT\u9019\u6b3eIOT\u767c\u5e03<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/blog.laszlo.tw\/?p=958\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">MQTT\u521d\u63a2<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[14],"tags":[56,57,55,58],"class_list":["post-958","post","type-post","status-publish","format-standard","hentry","category-linux","tag-iot","tag-mosquitto","tag-mqtt","tag-paho-mqtt","entry"],"_links":{"self":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts\/958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=958"}],"version-history":[{"count":29,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts\/958\/revisions"}],"predecessor-version":[{"id":1006,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=\/wp\/v2\/posts\/958\/revisions\/1006"}],"wp:attachment":[{"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.laszlo.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}