{"id":10020535,"date":"2024-12-22T13:06:32","date_gmt":"2024-12-22T05:06:32","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020535"},"modified":"2024-12-22T13:06:32","modified_gmt":"2024-12-22T05:06:32","slug":"%e9%a1%b9%e7%9b%ae%ef%bc%9a%e8%bf%9c%e7%a8%8b%e6%b8%a9%e6%b9%bf%e5%ba%a6%e6%a3%80%e6%b5%8b%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020535","title":{"rendered":"\u9879\u76ee\uff1a\u8fdc\u7a0b\u6e29\u6e7f\u5ea6\u68c0\u6d4b\u7cfb\u7edf"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u4e4b\u524d\u6211\u4eec\u505a\u4e86\u6e29\u6e7f\u5ea6\u76d1\u6d4b\u5c0f\u9879\u76ee\uff0c\u53ea\u662f\u628a\u6e29\u6e7f\u5ea6\u6570\u636e\u4e0a\u4f20\u5230 OneNET\uff0c\u73b0\u5728\u6211\u4eec\u6765\u4f18\u5316\u8fd9\u4e2a\u5c0f\u9879\u76ee\uff0c\u8ba9\u5b83\u66f4\u5b8c\u6574\uff0c\u66f4\u4eba\u6027\u3002\u6211\u4eec\u5728\u539f\u6709\u7684\u57fa\u7840\u4e0a\u52a0\u4e0a\u8702\u9e23\u5668\u548c LED \u706f\uff0c\u5f53\u6e29\u6e7f\u5ea6\u6b63\u5e38\uff0c\u8702\u9e23\u5668\u4e0d\u62a5\u8b66\uff0cLED \u706f\u4e0d\u4eae\uff1b\u5f53\u6e29\u6e7f\u5ea6\u8d85\u51fa\u8bbe\u5b9a\u9608\u503c\u65f6\u8702\u9e23\u5668\u62a5\u8b66\uff0cLED \u706f\u95ea\u70c1\u3002\u662f\u4e0d\u662f\u6709\u7535\u5f71\u91cc\u4fdd\u9669\u67dc\u7ea2\u5916\u68c0\u6d4b\u5230\u4eba\u5077\u7a83\uff0c\u7ea2\u706f\u8fde\u95ea\uff0c\u62a5\u8b66\u58f0\u957f\u9e23\u90a3\u611f\u89c9\u4e86\u3002<\/p>\n<h2>1. \u6e90\u7801\u4e0b\u8f7d\u53ca\u524d\u7f6e\u9605\u8bfb<\/h2>\n<p>\u672c\u6587\u9996\u53d1 <strong>\u826f\u8bb8\u5d4c\u5165\u5f0f\u7f51<\/strong> \uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=6BAxhD%2BLxUiWGczOvCmGKQ%3D%3D.Kea3ac52Ud58CqhpIpBiYCD3O7JY6Dso0B27v9mH078%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/e\/<\/a> \uff0c\u6b22\u8fce\u5173\u6ce8\uff01<\/p>\n<p>\u672c\u6587\u6240\u6d89\u53ca\u7684\u6e90\u7801\u53ca\u5b89\u88c5\u5305\u5982\u4e0b\uff08\u7531\u4e8e\u5e73\u53f0\u9650\u5236\uff0c\u8bf7\u70b9\u51fb\u4ee5\u4e0b\u94fe\u63a5\u9605\u8bfb\u539f\u6587\u4e0b\u8f7d\uff09\uff1a<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=%2FH3aliy%2BRuEowtkGVQUZDQ%3D%3D.JrODuKtmLjxSvvxbvM5AwrCkfv%2B8LZvwt6hxqUsuwhmPfS9i%2BhUPQlXoOlYU8DfJlFyXP80%2Bka8Z1mzEX%2FLH%2BA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/e\/stm32\/temp-humi-detection-system.html<\/a><\/p>\n<p>\u5982\u679c\u4f60\u662f\u5d4c\u5165\u5f0f\u5f00\u53d1\u5c0f\u767d\uff0c\u90a3\u4e48\u5efa\u8bae\u4f60\u5148\u8bfb\u8bfb\u4e0b\u9762\u51e0\u7bc7\u6587\u7ae0\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=iB7yI9YwHH2wieIRmWttUQ%3D%3D.bmy2d6PYZKEiNkMuz%2FTD932vun6GHG%2FBw2wobYLBXBJnVyYEquQQpD4zX2Tr9362HKY9qyaSxl4PzsD4r9ffZ7j4DjVcGO6ruVO4Hf7Smxs%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">STM32\u4e0b\u8f7d\u7a0b\u5e8f\u7684\u4e94\u79cd\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=G%2FkWoGAn6vdu41JnqypqJQ%3D%3D.8QYg2VDT5%2FzL9jrKgkWTXZA%2B0rNHdH%2BUIM7ynN%2BPVCurWMT%2BXbUPPsMLDs7tzWk%2BU7IX4eNxMj%2F7n8SoD%2Flv%2F1nXkxXjsbTcmB47Cxc8qr4%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u4e00\u6587\u6559\u4f60\u4f7f\u7528MDK\u5f00\u53d1\u5de5\u5177<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=5iKXq5x4bFexINrZLWn0RQ%3D%3D.CnS6ufLU%2Fs1ky%2Bj%2B%2BhCSXG95O7i8GVmhZG34mljZTxwbJ8Zyp52uoOMdFjRaXqUAtFcG8Iei7Hlayc2N%2FLj04hUgbLR9j2NvD2OxyOsb4nk%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u96f6\u57fa\u7840\u5feb\u901f\u4e0a\u624bSTM32\u5f00\u53d1\uff08\u624b\u628a\u624b\u4fdd\u59c6\u7ea7\u6559\u7a0b\uff09<\/a><\/li>\n<\/ul>\n<p>\u524d\u671f\u6559\u7a0b\uff0c\u6ca1\u770b\u8fc7\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u5148\u770b\u4e0b\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=nsD%2BdPFrm7Fyh1cJ0bVuXQ%3D%3D.SThDd44MihGsnA2nSPXyE0r7L1pONeS5eU%2F3sKIdHyKGhXDPXbBZlLE0Xe9hfUSwM9mhHxo4DvAtPAWLPdUM2g%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u624b\u628a\u624b\u6559\u4f60\u73a9\u8f6cESP8266\uff08\u539f\u7406+\u9a71\u52a8\uff09<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=%2FSdQab6eOdZThQZfZnEjcw%3D%3D.g9GQni1rjPj0mQ%2FZtfM4s0nAqd0h56ftqDZFeHXqkW0gkgMuU5JJ6brjfxaOlsapafR37Zju32G8Dj3NxlVj7w%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u624b\u628a\u624b\u6559\u4f60\u73a9\u8f6cDHT11\uff08\u539f\u7406+\u9a71\u52a8\uff09<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=%2BGj2GwkX9K4PJJnkAXN8Fg%3D%3D.dwrrgQqGF46rSUMin5U5pVvIUAFzd6Ua%2F%2BlxXoDhusBDf7OvRO%2FnmBNEXaEUAW95E7j21buzJFG%2B4TCHnLbbjA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u4e07\u5b57\u731b\u6587\uff1aMQTT\u539f\u7406\u53ca\u6848\u4f8b<\/a><\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u4f5c\u8005\u7b80\u4ecb<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">\u5927\u5bb6\u597d\uff0c\u6211\u662f\u826f\u8bb8\uff0c\u535a\u5ba2\u91cc\u6240\u6709\u7684\u6587\u7ae0\u7686\u4e3a\u6211\u7684\u539f\u521b\u3002<br \/>\u4e0b\u9762\u662f\u6211\u7684\u4e00\u4e9b\u4e2a\u4eba\u4ecb\u7ecd\uff0c\u6b22\u8fce\u4ea4\u4e2a\u670b\u53cb\uff1a<br \/>\u00b7 211\u5de5\u79d1\u7855\u58eb\uff0c\u56fd\u5bb6\u5956\u5b66\u91d1\u83b7\u5f97\u8005\uff1b<br \/>\u00b7 \u6df1\u8015\u5d4c\u5165\u5f0f11\u5e74\uff0c\u524d\u4e16\u754c500\u5f3a\u5916\u4f01\u9ad8\u7ea7\u5d4c\u5165\u5f0f\u5de5\u7a0b\u5e08\uff1b<br \/>\u00b7 \u4e66\u7c4d\u300a\u901f\u5b66Linux\u4f5c\u8005\u300b\uff0c\u673a\u68b0\u5de5\u4e1a\u51fa\u7248\u793e\u4e13\u5bb6\u59d4\u5458\u4f1a\u6210\u5458\uff1b<br \/>\u00b7 \u5168\u7f5160W\u7c89\u4e1d\uff0c\u535a\u5ba2\u5206\u4eab\u5927\u91cf\u539f\u521b\u6210\u4f53\u7cfb\u6587\u7ae0\uff0c\u5168\u7f51\u9605\u8bfb\u91cf\u7d2f\u8ba1\u8d854000\u4e07\uff1b<br \/>\u00b7 \u9760\u81ea\u5a92\u4f53\u8fde\u7eed\u5e74\u5165\u767e\u4e07\uff0c\u9760\u81ea\u5df1\u4e70\u623f\u4e70\u8f66\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u672c\u79d1\u53ca\u7855\u58eb\u90fd\u662f\u5b66\u673a\u68b0\uff0c\u901a\u8fc7\u81ea\u5b66\u6210\u529f\u8fdb\u5165\u4e16\u754c500\u5f3a\u5916\u4f01\u3002\u6211\u5df2\u7ecf\u5c06\u81ea\u5df1\u7684\u5b66\u4e60\u7ecf\u9a8c\u5199\u6210\u4e86\u4e00\u672c\u7535\u5b50\u4e66\uff0c\u8d85\u5343\u4eba\u901a\u8fc7\u6b64\u4e66\u5b66\u4e60\u5e76\u8f6c\u884c\u6210\u529f\u3002\u73b0\u5728\u5c06\u8fd9\u672c\u7535\u5b50\u4e66\u514d\u8d39\u5206\u4eab\u7ed9\u5927\u5bb6\uff0c\u5e0c\u671b\u5bf9\u4f60\u4eec\u6709\u5e2e\u52a9\uff1a<\/p>\n<p>\u7535\u5b50\u4e66\u94fe\u63a5\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=UdI4SmKYCFip1Nc4spFTMQ%3D%3D.%2FBB5sqRp1H7yeXGIWWQlhoohBPG8iE9KUuRPLjUhCHurh2%2BWyMMmMXJIMN1ax%2F8X\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.lxlinux.net\/1024.html<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"836\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfebd\" alt=\"\" title=\"\"><\/p>\n<h2>2. \u6574\u4f53\u7cfb\u7edf\u8bbe\u8ba1<\/h2>\n<p>\u4f7f\u7528 STM32 \u4f5c\u4e3b\u63a7\uff0c\u914d\u5408 DHT11 \u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\uff0c\u5b9e\u65f6\u76d1\u6d4b\u5468\u56f4\u73af\u5883\u7684\u6e29\u6e7f\u5ea6\u53d8\u5316\u3002\u901a\u8fc7 ESP8266 \u6a21\u5757\u4ee5 MQTT \u534f\u8bae\u5c06\u83b7\u53d6\u5230\u7684\u6e29\u6e7f\u5ea6\u6570\u636e\u901a\u8fc7\u65e0\u7ebf\u7f51\u7edc\u8fde\u63a5\u4e0a\u4f20\u81f3  OneNET \u5e73\u53f0\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u968f\u65f6\u968f\u5730\u901a\u8fc7\u624b\u673a\u6216\u7535\u8111\u67e5\u770b\u6570\u636e\u3002\u6e29\u6e7f\u5ea6\u5982\u6709\u5f02\u5e38\uff0c\u8702\u9e23\u5668\u62a5\u8b66\uff0cLED \u706f\u95ea\u70c1\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"284\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmz\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>3. \u786c\u4ef6\u9009\u578b<\/h2>\n<p>\u672c\u6559\u7a0b\u4f7f\u7528\u7684\u786c\u4ef6\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5355\u7247\u673a\uff1aSTM32F103C8T6<\/li>\n<\/ul>\n<p>\u8fd9\u6b3e\u5355\u7247\u673a\u5177\u6709 64K flash\uff0c20K RAM\uff0c4 \u4e2a\u5b9a\u65f6\u5668\uff0c3 \u4e2a\u4e32\u53e3\uff0c\u7f51\u7edc\u4e0a\u8d44\u6599\u597d\u51e0\u5428\uff0c\u975e\u5e38\u9002\u5408\u521d\u5b66\u8005\u5165\u95e8\uff0c\u5f3a\u70c8\u63a8\u8350\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"441\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaoHJ\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>WiFi\u6a21\u5757\uff1aESP-01S\uff08ESP8266\uff09<\/li>\n<\/ul>\n<p>ESP8266 \u53ef\u4ee5\u5229\u7528\u4e32\u53e3\u4e0e\u5355\u7247\u673a\u8fdb\u884c\u901a\u8baf\uff0c\u4ece\u800c\u7f16\u7a0b\u5b9e\u73b0\u63a7\u5236\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"299\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaI0f\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\uff1aDHT11<\/li>\n<\/ul>\n<p>DHT11 \u6709 3 \u811a\u548c 4 \u811a\u4e24\u6b3e\uff0c\u5728\u4f7f\u7528\u4e0a\u6ca1\u6709\u5dee\u522b\uff0c\u63a5\u7ebf\u90fd\u4e00\u6837\uff0c\u4e3b\u8981\u63a5\u4e09\u6839\uff0c\u56db\u811a\u7684\u6b3e\u5f0f\u6709\u4e00\u811a\u60ac\u7a7a\u3002\u56db\u811a\u6b3e\u63a5\u675c\u90a6\u7ebf\u4f1a\u6709\u70b9\u4e0d\u7a33\uff0c\u9002\u5408\u63d2\u9762\u5305\u677f\u6216\u5f00\u53d1\u677f\u4e0a\u3002<\/p>\n<p>DHT11 \u5de5\u4f5c\u53c2\u6570\uff1a<\/p>\n<ol>\n<li>\u6e7f\u5ea6\u6d4b\u91cf\u8303\u56f4\uff1a20~90%RH<\/li>\n<li>\u6e7f\u5ea6\u6d4b\u91cf\u7cbe\u5ea6\uff1a\u00b15%RH<\/li>\n<li>\u6e29\u5ea6\u6d4b\u91cf\u8303\u56f4\uff1a0~50\u2103<\/li>\n<li>\u6e29\u5ea6\u6d4b\u91cf\u7cbe\u5ea6\uff1a\u00b12\u2103<\/li>\n<li>\u5de5\u4f5c\u7535\u538b\uff1aDC 3.3V\/5V<\/li>\n<\/ol>\n<p>&lt;img src=&quot;https:\/\/lxlinux.superbed.verylink.top\/item\/655b12b2c458853aef4b8a5b.jpg&quot; style=&quot;zoom: 67%;&quot; \/&gt;<\/p>\n<ul>\n<li>\u8702\u9e23\u5668<\/li>\n<\/ul>\n<p>\u8702\u9e23\u5668\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u7535\u5b50\u8bbe\u5907\u4e2d\uff0c\u4f8b\u5982\u8b66\u62a5\u5668\u3001\u8ba1\u65f6\u5668\u3001\u7535\u5b50\u949f\u3001\u96f7\u8fbe\u7b49\u3002\u5b83\u4eec\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u63d0\u9192\u3001\u62a5\u8b66\u3001\u6307\u793a\u7b49\uff0c\u901a\u8fc7\u53d1\u51fa\u7279\u5b9a\u7684\u58f0\u97f3\u9891\u7387\u6765\u5f15\u8d77\u7528\u6237\u7684\u6ce8\u610f\u3002\u53ef\u5206\u4e3a\u65e0\u6e90\u8702\u9e23\u5668\u548c\u6709\u6e90\u8702\u9e23\u5668\u3002<\/p>\n<p><img decoding=\"async\" width=\"525\" height=\"473\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmA\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>LED\u706f<\/li>\n<\/ul>\n<p>LED\u706f\u662f\u4e00\u79cd\u534a\u5bfc\u4f53\u5149\u6e90\uff0c\u5177\u6709\u9ad8\u6548\u3001\u8010\u7528\u548c\u53ef\u9760\u7684\u7279\u70b9\uff0c\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u7535\u5b50\u8bbe\u5907\u548c\u7167\u660e\u7cfb\u7edf\u4e2d\uff0c\u4e3a\u6211\u4eec\u7684\u751f\u6d3b\u548c\u5de5\u4f5c\u63d0\u4f9b\u4e86\u53ef\u9760\u7684\u5149\u6e90\u3002\u5b83\u53ef\u4ee5\u53d1\u51fa\u591a\u79cd\u989c\u8272\u7684\u5149\uff0c\u5982\u4e0b\u6a21\u5757\u5c31\u6709\u7ea2\u3001\u9ec4\u3001\u84dd\u3001\u7eff\u3001\u767d\u7684\u989c\u8272\uff0c3.3~5V \u7684\u7535\u538b\u8303\u56f4\u5185\u4f9b\u7535\u3002<\/p>\n<p><img decoding=\"async\" width=\"630\" height=\"516\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmB\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>\u4e32\u53e3\uff1aUSB \u8f6c TTL<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u8bbe\u5907\u4e3b\u8981\u4f5c\u7528\u662f\u7528\u6765\u8c03\u8bd5\u6216\u4e0b\u8f7d\u7a0b\u5e8f\uff0c\u672c\u6587\u7528\u4e8e\u4e32\u53e3\u8f93\u51fa\u4f5c\u8c03\u8bd5\u3002\u4ef7\u683c\u4e5f\u5f88\u4fbf\u5b9c\uff0c\u666e\u904d 5~8 \u5143\u3002<\/p>\n<p><img decoding=\"async\" width=\"454\" height=\"348\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaoHL\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>\u70e7\u5f55\u5668\uff1aST-LINK V2<\/li>\n<\/ul>\n<p>ST-Link \u662f\u4e00\u79cd\u7528\u4e8e STM32 \u5fae\u63a7\u5236\u5668\u7684\u8c03\u8bd5\u548c\u7f16\u7a0b\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7 SWD \u6216 JTAG \u63a5\u53e3\u4e0e\u5f00\u53d1\u677f\u8fdb\u884c\u901a\u4fe1\u3002\u672c\u6587\u7528\u505a\u70e7\u5f55\u3002\u4e00\u822c\u4e5f\u5f88\u4fbf\u5b9c\uff0c\u4e03\u516b\u5143\u5de6\u53f3\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"732\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaoHN\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>4. OneNET\u7269\u8054\u7f51\u5e73\u53f0<\/h2>\n<p>\u6211\u4eec\u4e0a\u4e00\u7bc7\u5df2\u7ecf\u914d\u7f6e\u8fc7 OneNET \u4e86\uff0c\u8fd9\u91cc\u5c31\u4e0d\u4ece\u5934\u6559\u4e86\uff0c\u6ca1\u770b\u7684\u540c\u5b66\u53ef\u4ee5\u53bb\u770b\u770b\u3010MQTT+DHT11\u94fe\u63a5\u3011<\/p>\n<h3>4.1 OneNET\u914d\u7f6e<\/h3>\n<p>\u4e66\u63a5\u4e0a\u56de\uff0c\u6211\u4eec\u9700\u8981\u5728\u4e4b\u524d\u7684\u57fa\u7840\u4e0a\u521b\u5efa\u4ee5\u4e0b\u7269\u6a21\u578b\uff1a<\/p>\n<ul>\n<li>\u5f53\u524d\u6e7f\u5ea6\uff0c\u7528\u4e8e\u5b58\u50a8\u5b9e\u65f6\u6e7f\u5ea6\u6570\u636e\u3002<\/li>\n<li>\u5f53\u524d\u6e29\u5ea6\uff0c\u7528\u4e8e\u5b58\u50a8\u5b9e\u65f6\u6e29\u5ea6\u6570\u636e\u3002<\/li>\n<li>\u6e7f\u5ea6\u4e0a\u9650\uff0c\u7528\u4e8e\u663e\u793a\u8bbe\u5b9a\u7684\u6e7f\u5ea6\u4e0a\u9650\uff0c\u6e7f\u5ea6\u9ad8\u4e8e\u4e0a\u9650\u5c31\u62a5\u8b66\u3002<\/li>\n<li>\u6e29\u5ea6\u4e0a\u9650\uff0c\u7528\u4e8e\u663e\u793a\u8bbe\u5b9a\u7684\u6e29\u5ea6\u4e0a\u9650\uff0c\u6e29\u5ea6\u9ad8\u4e8e\u4e0a\u9650\u5c31\u62a5\u8b66\u3002<\/li>\n<li>\u6e7f\u5ea6\u4e0b\u9650\uff0c\u7528\u4e8e\u663e\u793a\u8bbe\u5b9a\u7684\u6e7f\u5ea6\u4e0b\u9650\uff0c\u6e7f\u5ea6\u4f4e\u4e8e\u4e0b\u9650\u5c31\u62a5\u8b66\u3002<\/li>\n<li>\u6e29\u5ea6\u4e0b\u9650\uff0c\u7528\u4e8e\u663e\u793a\u8bbe\u5b9a\u7684\u6e29\u5ea6\u4e0b\u9650\uff0c\u6e29\u5ea6\u4f4e\u4e8e\u4e0b\u9650\u5c31\u62a5\u8b66\u3002<\/li>\n<li>\u6e7f\u5ea6\u544a\u8b66\uff0c\u82e5\u6e7f\u5ea6\u8d85\u51fa\u9608\u503c\u5373\u8bb0\u5f55\u4e8b\u4ef6\u3002<\/li>\n<li>\u6e29\u5ea6\u544a\u8b66\uff0c\u82e5\u6e29\u5ea6\u8d85\u51fa\u9608\u503c\u5373\u8bb0\u5f55\u4e8b\u4ef6\u3002<\/li>\n<\/ul>\n<p><img decoding=\"async\" width=\"723\" height=\"374\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdbizH\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>4.2 MQTT\u4e09\u5143\u7ec4<\/h3>\n<p>\u300cMQTT \u4e09\u5143\u7ec4\u300d\u7684\u83b7\u53d6\u65b9\u5f0f\u4e5f\u5728\u4e0a\u4e00\u7bc7\u8be6\u7ec6\u4ecb\u7ecd\u8fc7\u4e86\uff0c\u8fd9\u8fb9\u4e0d\u8d58\u8ff0\u5566\uff0c\u76f4\u63a5\u7ed9\u51fa\uff0c\u6ca1\u770b\u7684\u540c\u5b66\u53ef\u4ee5\u53bb\u770b\u770b\u3010MQTT+DHT11\u94fe\u63a5\u3011<\/p>\n<ul>\n<li>\u8bbe\u5907 ID\uff1atemp01<\/li>\n<li>\u4ea7\u54c1 ID\uff1aP2k4KV0low<\/li>\n<li>token\uff1aversion=2018-10-31&#038;res=products%2FP2k4KV0low%2Fdevices%2Ftemp01&#038;et=2017881776&#038;method=sha1&#038;sign=M3jVJvfeFLnggMrUPhYm5uRirXs%3D<\/li>\n<\/ul>\n<h2>5. STM32\u8bbe\u5907\u7aef\u5f00\u53d1<\/h2>\n<h3>5.1 \u786c\u4ef6\u63a5\u7ebf<\/h3>\n<p>\u63a5\u7ebf\u53ef\u53c2\u7167\u4e0b\u8868\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">ESP8266<\/th>\n<th align=\"center\">DHT11<\/th>\n<th align=\"center\">\u8702\u9e23\u5668<\/th>\n<th align=\"center\">LED<\/th>\n<th align=\"center\">STM32<\/th>\n<th align=\"center\">USB \u8f6c TTL<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">3V3<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">3.3<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\">TX<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">A3<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\">RX<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">A2<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">G<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\">VCC<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">3.3<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\">DATA<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">B9<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\">GND<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">G<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">I\/C<\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">C13<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">IN<\/td>\n<td align=\"center\">A6<\/td>\n<td align=\"center\"> <\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">A10<\/td>\n<td align=\"center\">TX<\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">A9<\/td>\n<td align=\"center\">RX<\/td>\n<\/tr>\n<tr>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\"> <\/td>\n<td align=\"center\">G<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u70e7\u5f55\u7684\u65f6\u5019\u63a5\u7ebf\u5982\u4e0b\u8868\uff0c\u5982\u679c\u4e0d\u4f1a\u70e7\u5f55\u7684\u8bdd\u53ef\u4ee5\u770b\u6211\u4e4b\u524d\u7684\u6587\u7ae0\u3010<a href=\"https:\/\/link.segmentfault.com\/?enc=p9WJcjSXfiAbRggWWWJhjg%3D%3D.yimZKhbuV2uYI9ZuI3fTuRXkSSq7ds%2BKt7qB0ssS11DeLlC9cQcO%2FQpUReILwn8FFNStUUotlP3pPUKO7O81VL7cVwgH6tBScmR7ns8h4h0%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">STM32\u4e0b\u8f7d\u7a0b\u5e8f\u7684\u4e94\u79cd\u65b9\u6cd5<\/a>\u3011\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">ST-Link V2<\/th>\n<th align=\"center\">STM32<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\">SWCLK<\/td>\n<td align=\"center\">SWCLK<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">SWDIO<\/td>\n<td align=\"center\">SWDIO<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">GND<\/td>\n<td align=\"center\">GND<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">3.3V<\/td>\n<td align=\"center\">3V3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>5.2 \u8bbe\u5907\u5b9e\u7269\u56fe<\/h3>\n<p>\u63a5\u597d\u5982\u4e0b\u56fe\uff0c\u6211\u7528\u7684\u662f\u6b63\u70b9\u539f\u5b50\u7684\u5f00\u53d1\u677f\uff0c\u5927\u5bb6\u7528\u522b\u7684\u677f\u5b50\u4e5f\u662f\u4e00\u6837\u53ef\u4ee5\u7684\uff0c\u53ea\u8981\u662f STM32F103C8T6 \u5c31\u884c\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"518\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmC\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>5.3 DHT11\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u4ee3\u7801<\/h3>\n<p>\u8be6\u7ec6\u4ee3\u7801\u89e3\u6790\u53ef\u4ee5\u770b<a href=\"https:\/\/link.segmentfault.com\/?enc=uHZ5dvERDEQCkop3%2FRXAVw%3D%3D.45x7alTZDC8uSjtKWE4c%2Fm2nj2gG2i6aXvU8MEGegO6yKyFWPdKcKOhtSgx70jI28oxhFS4cn1jOjuNESoBliA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u624b\u628a\u624b\u6559\u4f60\u73a9\u8f6cDHT11\uff08\u539f\u7406+\u9a71\u52a8\uff09<\/a>\u3002<\/p>\n<h3>5.4 ESP8266\u6a21\u5757\u4ee3\u7801<\/h3>\n<p>\u8be6\u7ec6\u4ee3\u7801\u89e3\u6790\u53ef\u4ee5\u770b<a href=\"https:\/\/link.segmentfault.com\/?enc=Erx3%2FqIaU4tHn3F%2BsCPTNA%3D%3D.glZGA%2F0ZkQrAGfN51yDyQ2l%2FM9kdahBP65x6hpIdjrBp0YaJBcSV1duHDqm3cwhtm1QAV4pIpEwEcjsfscXwvA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u624b\u628a\u624b\u6559\u4f60\u73a9\u8f6cESP8266\uff08\u539f\u7406+\u9a71\u52a8\uff09<\/a>\u3002<\/p>\n<h3>5.5 MQTT\u4ee3\u7801<\/h3>\n<p>CONNECT \u62a5\u6587\u548c PUBLISH \u62a5\u6587\u5df2\u7ecf\u5728\u4e0a\u4e00\u7bc7\u8bb2\u8fc7\uff0c\u6ca1\u770b\u7684\u540c\u5b66\u53ef\u4ee5\u53bb\u770b\u770b\u3010MQTT+DHT11\u94fe\u63a5\u3011<\/p>\n<p>\u6211\u4eec\u8bb2\u65b0\u589e\u7684\u3002<\/p>\n<h4>5.5.1 SUBSCRIBE \u62a5\u6587<\/h4>\n<p>SUBSCRIBE \u62a5\u6587\u7684\u7f16\u5199\u53ca\u53d1\u9001\u4ee3\u7801\uff0c\u62a5\u6587\u7f16\u5199\u5c31\u6309\u7167\u6211\u4eec <a href=\"https:\/\/link.segmentfault.com\/?enc=hKsV6t8spAmuSW2V62qMVw%3D%3D.oI%2BdlkbXmtXAxBiv50TFrh%2B6RmQJ0dGY75ogo%2FUBTLHZ%2BXuzOXnF%2FqY%2Bc13%2FkgaG%2BUIWnLnalOZ1uw4VC6JCgg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u4e07\u5b57\u731b\u6587\uff1aMQTT\u539f\u7406\u53ca\u6848\u4f8b<\/a> \u7684\u7406\u8bba\u7f16\u5199\u5373\u53ef\uff0c\u62a5\u6587\u5185\u5bb9\uff1a82+\u5269\u4f59\u957f\u5ea6+\u6807\u8bc6\u7b26+L+\u4e3b\u9898\u8fc7\u6ee4\u5668+QoS\u3002<\/p>\n<pre><code class=\"C\">uint8_t mqtt_subscribe_topic(char *topic,uint8_t qos,uint8_t whether)\n{    \n    uint8_t i,j;\n    mqtt_txlen=0;\n    int topiclen = strlen(topic);\n    \n    int DataLen = 2 + (topiclen+2) + (whether?1:0);\/\/\u53ef\u53d8\u62a5\u5934\u7684\u957f\u5ea6\uff082\u5b57\u8282\uff09\u52a0\u4e0a\u6709\u6548\u8f7d\u8377\u7684\u957f\u5ea6\n    \/\/\u56fa\u5b9a\u62a5\u5934\n    \/\/\u63a7\u5236\u62a5\u6587\u7c7b\u578b\n    if(whether)mqtt_txbuf[mqtt_txlen++] = 0x82; \/\/\u6d88\u606f\u7c7b\u578b\u548c\u6807\u5fd7\u8ba2\u9605\n    else    mqtt_txbuf[mqtt_txlen++] = 0xA2;    \/\/\u53d6\u6d88\u8ba2\u9605\n\n    \/\/\u5269\u4f59\u957f\u5ea6\n    do\n    {\n        uint8_t encodedByte = DataLen % 128;\n        DataLen = DataLen \/ 128;\n        \/\/ if there are more data to encode, set the top bit of this byte\n        if ( DataLen &gt; 0 )\n            encodedByte = encodedByte | 128;\n        mqtt_txbuf[mqtt_txlen++] = encodedByte;\n    }while ( DataLen &gt; 0 );    \n    \n    \/\/\u53ef\u53d8\u62a5\u5934\n    mqtt_txbuf[mqtt_txlen++] = 0;            \/\/\u6d88\u606f\u6807\u8bc6\u7b26 MSB\n    mqtt_txbuf[mqtt_txlen++] = 0x01;        \/\/\u6d88\u606f\u6807\u8bc6\u7b26 LSB\n    \/\/\u6709\u6548\u8f7d\u8377\n    mqtt_txbuf[mqtt_txlen++] = BYTE1(topiclen);\/\/\u4e3b\u9898\u957f\u5ea6 MSB\n    mqtt_txbuf[mqtt_txlen++] = BYTE0(topiclen);\/\/\u4e3b\u9898\u957f\u5ea6 LSB   \n    memcpy(&amp;mqtt_txbuf[mqtt_txlen],topic,topiclen);\n    mqtt_txlen += topiclen;\n    \n    if(whether)\n    {\n       mqtt_txbuf[mqtt_txlen++] = qos;\/\/QoS\u7ea7\u522b\n    }\n    \n    for(i=0;i&lt;10;i++)\n    {\n        memset(mqtt_rxbuf,0,mqtt_rxlen);\n        mqtt_send_data(mqtt_txbuf,mqtt_txlen);\n\n        for(j=0;j&lt;10;j++)\n        {\n            delay_ms(50);\n            if (esp8266_wait_receive() == ESP8266_EOK)\n                esp8266_copy_rxdata((char *)mqtt_rxbuf);\n\n            if(mqtt_rxbuf[0]==parket_subAck[0] &amp;&amp; mqtt_rxbuf[1]==parket_subAck[1]) \/\/\u8ba2\u9605\u6210\u529f               \n            {\n                return 0;\/\/\u8ba2\u9605\u6210\u529f\n            }\n        }\n    }\n    return 1; \/\/\u5931\u8d25\n}<\/code><\/pre>\n<h4>5.5.2 PINGREQ \u62a5\u6587<\/h4>\n<p>\u5fc3\u8df3\u8bf7\u6c42\u5c31\u5f88\u7b80\u5355\uff0cESP8266 \u53d1\u9001\u201cC0 D0\u201d\u5373\u53ef\u3002<\/p>\n<pre><code class=\"c\">const uint8_t parket_heart[] = {0xc0,0x00};\n\nvoid mqtt_send_heart(void)\n{\n    mqtt_send_data((uint8_t *)parket_heart,sizeof(parket_heart));\n}\n\nvoid mqtt_send_data(uint8_t *buf,uint16_t len)\n{\n    esp8266_send_data((char *)buf, len);\n}<\/code><\/pre>\n<h4>5.5.3 \u63a5\u6536\u53e5\u67c4<\/h4>\n<p>\u63a5\u6536 OneNET \u53d1\u6765\u7684\u6570\u636e\uff0c\u53bb\u6389\u6211\u4eec\u4e0d\u9700\u8981\u7684\u56fa\u5b9a\u62a5\u5934\u548c\u53ef\u53d8\u62a5\u5934\uff0c\u53ea\u4fdd\u5b58\u6709\u6548\u8f7d\u8377\u3002<\/p>\n<pre><code class=\"c\">uint8_t mqtt_receive_handle(uint8_t *data_received, Mqtt_RxData_Type *rx_data)\n{\n    uint8_t *p;\n    uint8_t encodeByte = 0;\n    uint32_t multiplier = 1, Remaining_len = 0;\n    uint8_t QS_level = 0;\n    \n    p = data_received;\n    memset(rx_data, 0, sizeof(Mqtt_RxData_Type));\n    \n    \/\/\u89e3\u6790\u63a5\u6536\u6570\u636e\n    if((*p != 0x30)&amp;&amp;(*p != 0x32)&amp;&amp;(*p != 0x34))   \/\/\u4e0d\u662f\u53d1\u5e03\u62a5\u6587\u5934\n        return 1;\n    \n    if(*p != 0x30) QS_level = 1;    \/\/\u6807\u8bb0qs\u7b49\u7ea7\u4e0d\u4e3a0\n    \n    p++;\n    \/\/\u63d0\u53d6\u5269\u4f59\u6570\u636e\u957f\u5ea6\n    do{\n        encodeByte = *p++;\n        Remaining_len += (encodeByte &amp; 0x7F) * multiplier;\n        multiplier *= 128;\n        \n        if(multiplier &gt; 128*128*128) \/\/\u8d85\u51fa\u5269\u4f59\u957f\u5ea6\u6700\u59274\u4e2a\u5b57\u8282\u7684\u8981\u6c42,\u9519\u8bef\n            return 2;\n    }while((encodeByte &amp; 0x80) != 0);\n    \n    \/\/\u63d0\u53d6\u4e3b\u9898\u6570\u636e\u957f\u5ea6\n    rx_data-&gt;topic_len = *p++;\n    rx_data-&gt;topic_len = rx_data-&gt;topic_len * 256 + *p++;\n    \/\/\u63d0\u53d6\u4e3b\u9898\n    memcpy(rx_data-&gt;topic,p,rx_data-&gt;topic_len);\n    p += rx_data-&gt;topic_len;\n    \n    if(QS_level != 0)  \/\/\u8df3\u8fc7\u62a5\u6587\u6807\u8bc6\u7b26\n        p += 2;\n    \n    \/\/\u63d0\u53d6payload\n    rx_data-&gt;payload_len = Remaining_len - rx_data-&gt;topic_len - 2;\n    memcpy(rx_data-&gt;payload, p, rx_data-&gt;payload_len);\n\n    return 0;\n}<\/code><\/pre>\n<h3>5.6 \u6570\u636e\u4e0a\u62a5<\/h3>\n<p>\u5c06\u6211\u4eec\u5f97\u5230\u7684\u6e29\u6e7f\u5ea6\u6570\u636e\u548c\u8bbe\u5b9a\u7684\u6e29\u6e7f\u5ea6\u9608\u503c\u901a\u8fc7 PUBLISH \u62a5\u6587\u4e0a\u62a5\u5230 OneNET\u3002<\/p>\n<pre><code class=\"c\">void status_post_task(void)\n{\n    if(!status_post_flag)\n        return;\n    \n    status_post_flag = 0;\n    \n    printf(&quot;\/r\/n~~~~~~~~\u4e3b\u52a8\u4e0a\u62a5\u7cfb\u7edf\u72b6\u6001~~~~~~~~\/r\/n&quot;);\n    memset(data_send_buff, 0, sizeof(data_send_buff));\n    sprintf((char *)data_send_buff,&quot;{\/&quot;id\/&quot;:\/&quot;1386772172\/&quot;,\/&quot;version\/&quot;:\/&quot;1.0\/&quot;,\/&quot;params\/&quot;:{\/&quot;CurrentTemperature\/&quot;:{\/&quot;value\/&quot;:%d},\/&quot;CurrentHumidity\/&quot;:{\/&quot;value\/&quot;:%d},\/&quot;MaxTempSet\/&quot;:{\/&quot;value\/&quot;:%d},\/&quot;MiniTempSet\/&quot;:{\/&quot;value\/&quot;:%d},\/&quot;MaxHumSet\/&quot;:{\/&quot;value\/&quot;:%d},\/&quot;MiniHumSet\/&quot;:{\/&quot;value\/&quot;:%d}}}&quot;,\n        temperature, humidity, temp_upper_limit, temp_lower_limit, humi_upper_limit, humi_lower_limit);\n    mqtt_publish_data(POST_TOPIC, (char *)data_send_buff, 0);\n    printf(&quot;%s\/r\/n&quot;, data_send_buff);\n    printf(&quot;~~~~~~~~\u4e0a\u62a5\u7ed3\u675f~~~~~~~~\/r\/n&quot;);\n}<\/code><\/pre>\n<h3>5.7 \u8d85\u51fa\u9608\u503c\u62a5\u8b66<\/h3>\n<p>\u5f53 alarm_post_flag \u4e3a1\uff0c\u5219\u8868\u793a\u8d85\u51fa\u8bbe\u5b9a\u7684\u6e29\/\u6e7f\u5ea6\u7684\u4e0a\/\u4e0b\u9650\uff0c\u5411 OneNET \u548c\u4e32\u53e3\u53d1\u5e03\u62a5\u8b66<\/p>\n<pre><code class=\"c\">void alarm_post_task(void)\n{\n    if(!alarm_post_flag)\n        return;\n    \n    alarm_post_flag = 0;\n    \n    if(alarm_flag){\n        printf(&quot;\/r\/n~~~~~~~~\u4e0a\u62a5\u544a\u8b66\u72b6\u6001~~~~~~~~\/r\/n&quot;);\n        memset(data_send_buff, 0, sizeof(data_send_buff));\n        sprintf((char *)data_send_buff,&quot;{\/&quot;id\/&quot;:\/&quot;1386772172\/&quot;,\/&quot;version\/&quot;:\/&quot;1.0\/&quot;,\/&quot;params\/&quot;:{\/&quot;TempAlarm\/&quot;:{\/&quot;value\/&quot;:{\/&quot;high\/&quot;:%d,\/&quot;low\/&quot;:%d}},\/&quot;HumAlarm\/&quot;:{\/&quot;value\/&quot;:{\/&quot;high\/&quot;:%d,\/&quot;low\/&quot;:%d}}}}&quot;,\n            alarm_status.temp_upper_alarm, alarm_status.temp_lower_alarm, alarm_status.humi_upper_alarm, alarm_status.humi_lower_alarm);\n        mqtt_publish_data(EVENT_PUBLISH_TOPIC, (char *)data_send_buff, 0);\n        printf(&quot;%s\/r\/n&quot;, data_send_buff);\n        printf(&quot;~~~~~~~~\u4e0a\u62a5\u7ed3\u675f~~~~~~~~\/r\/n&quot;);\n    }\n}<\/code><\/pre>\n<h3>5.8 \u5b9a\u65f6\u4efb\u52a1<\/h3>\n<p>\u5c06\u6211\u4eec\u9700\u8981\u7528\u5230\u7684\u8702\u9e23\u5668\u548c LED \u62a5\u8b66\u3001DHT11\u8bfb\u53d6\u3001\u6570\u636e\u4e0a\u62a5\u3001\u5fc3\u8df3\u8bf7\u6c42\u3001\u63a5\u6536\u6570\u636e\u3001\u62a5\u8b66\u4e0a\u4f20\u7684\u8fd9\u51e0\u4e2a\u4efb\u52a1\u5b9a\u65f6\u3002<\/p>\n<pre><code class=\"c\">void systick_isr(void)\n{\n    \/\/ sys\u4efb\u52a1\uff0c\u6bcf1000ms\u8fd0\u884c\u4e00\u6b21\n    if(sys_task_cnt &lt; 1000)\n        sys_task_cnt++;\n    else{\n        sys_task_cnt = 0;\n        if(alarm_flag){            \/* \u5982\u679c\u6e29\u6e7f\u5ea6\u5f02\u5e38 *\/\n            BEEP_TOGGLE();        \/* BEEP\u72b6\u6001\u7ffb\u8f6c *\/\n            LED2_TOGGLE();        \/*  LED\u72b6\u6001\u7ffb\u8f6c *\/\n        }else{\n            BEEP(0);\n            LED1(1);\n        }\n    }\n\n    \/\/ DHT11\u4efb\u52a1\uff0c\u6bcf1000ms\u8fd0\u884c\u4e00\u6b21\n    if(dht11_task_cnt &lt; 1000)\n        dht11_task_cnt++;\n    else{\n        dht11_task_cnt = 0;\n        dht11_update_flag = 1;\n    }\n    \n    \/\/ MQTT\u6570\u636e\u4e0a\u62a5\u4efb\u52a1\uff0c\u6bcf30s\u8fd0\u884c\u4e00\u6b21\n    if(status_post_task_cnt &lt; 10000)\n        status_post_task_cnt++;\n    else{\n        status_post_task_cnt = 0;\n        status_post_flag = 1;\n    }\n    \n    \/\/ MQTT\u5fc3\u8df3\u4efb\u52a1\uff0c\u6bcf30s\u8fd0\u884c\u4e00\u6b21\n    if(heart_task_cnt &lt; 30000)\n        heart_task_cnt++;\n    else{\n        heart_task_cnt = 0;\n        heart_send_flag = 1;\n    }\n\n    \/\/ MQTT\u63a5\u6536\u4efb\u52a1\uff0c\u6bcf30ms\u8fd0\u884c\u4e00\u6b21\n    if(mqtt_receive_task_cnt &lt; 30)\n        mqtt_receive_task_cnt++;\n    else{\n        mqtt_receive_task_cnt = 0;\n        mqtt_receive_flag = 1;\n    }\n    \n    \/\/ \u544a\u8b66\u4e0a\u4f20\u63a5\u6536\u4efb\u52a1\uff0c\u6bcf15s\u8fd0\u884c\u4e00\u6b21\n    if(alarm_post_task_cnt &lt; 15000)\n        alarm_post_task_cnt++;\n    else{\n        alarm_post_task_cnt = 0;\n        alarm_post_flag = 1;\n    }\n}<\/code><\/pre>\n<h3>5.9 \u8702\u9e23\u5668\u903b\u8f91\u4ee3\u7801<\/h3>\n<p>\u8702\u9e23\u5668\u7684\u4ee3\u7801\u7b80\u7b80\u5355\u5355\uff0c\u8fd9\u91cc\u5c31\u4e0d\u8d58\u8ff0\u4e86\uff0c\u4e0b\u9762\u662f\u8702\u9e23\u5668\u521d\u59cb\u5316\u4ee3\u7801\u3002<\/p>\n<pre><code class=\"C\">void beep_init(void)\n{\n    GPIO_InitTypeDef gpio_init_struct;\n    BEEP_GPIO_CLK_ENABLE();                             \/* BEEP\u65f6\u949f\u4f7f\u80fd *\/\n\n    gpio_init_struct.Pin = BEEP_GPIO_PIN;               \/* \u8702\u9e23\u5668\u5f15\u811a *\/\n    gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;        \/* \u63a8\u633d\u8f93\u51fa *\/\n    gpio_init_struct.Pull = GPIO_PULLUP;                \/* \u4e0a\u62c9 *\/\n    gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;      \/* \u9ad8\u901f *\/\n    HAL_GPIO_Init(BEEP_GPIO_PORT, &amp;gpio_init_struct);   \/* \u521d\u59cb\u5316\u8702\u9e23\u5668\u5f15\u811a *\/\n\n    BEEP(0);                                            \/* \u5173\u95ed\u8702\u9e23\u5668 *\/\n}<\/code><\/pre>\n<p>\u8702\u9e23\u5668\u7684 .h\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"C\">#ifndef __BEEP_H\n#define __BEEP_H\n\n#include &quot;sys.h&quot;\n\n\/******************************************************************************************\/\n\/* \u5f15\u811a \u5b9a\u4e49 *\/\n\n#define BEEP_GPIO_PORT                  GPIOC\n#define BEEP_GPIO_PIN                   GPIO_PIN_13\n#define BEEP_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOC_CLK_ENABLE(); }while(0)   \/* PB\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n\/******************************************************************************************\/\n\n\/* \u8702\u9e23\u5668\u63a7\u5236 *\/\n#define BEEP(x)         do{ x ? \/\n                            HAL_GPIO_WritePin(BEEP_GPIO_PORT, BEEP_GPIO_PIN, GPIO_PIN_SET) : \/\n                            HAL_GPIO_WritePin(BEEP_GPIO_PORT, BEEP_GPIO_PIN, GPIO_PIN_RESET); \/\n                        }while(0)\n\n\/* BEEP\u72b6\u6001\u7ffb\u8f6c *\/\n#define BEEP_TOGGLE()   do{ HAL_GPIO_TogglePin(BEEP_GPIO_PORT, BEEP_GPIO_PIN); }while(0)     \/* BEEP = !BEEP *\/\n\nvoid beep_init(void);   \/* \u521d\u59cb\u5316\u8702\u9e23\u5668 *\/\n\n#endif<\/code><\/pre>\n<h3>5.10 LED\u903b\u8f91\u4ee3\u7801<\/h3>\n<p>LED \u706f\u7684\u4ee3\u7801\u4e5f\u7b80\u7b80\u5355\u5355\uff0c\u6211\u4eec\u53ea\u7528\u4e86 LED1\uff0c\u6240\u4ee5\u53ea\u8bbe\u7f6e\u4e86 LED1 \u7684\u8f93\u51fa\u6a21\u5f0f\u3002<\/p>\n<pre><code class=\"C\">void led_init(void)\n{\n    GPIO_InitTypeDef gpio_init_struct;\n    LED1_GPIO_CLK_ENABLE();                                 \/* LED1\u65f6\u949f\u4f7f\u80fd *\/\n    LED2_GPIO_CLK_ENABLE();                                 \/* LED2\u65f6\u949f\u4f7f\u80fd *\/\n    LED3_GPIO_CLK_ENABLE();                                 \/* LED3\u65f6\u949f\u4f7f\u80fd *\/\n\n    gpio_init_struct.Pin = LED1_GPIO_PIN;                   \/* LED1\u5f15\u811a *\/\n    gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;            \/* \u63a8\u633d\u8f93\u51fa *\/\n    gpio_init_struct.Pull = GPIO_PULLUP;                    \/* \u4e0a\u62c9 *\/\n    gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;          \/* \u9ad8\u901f *\/\n    HAL_GPIO_Init(LED1_GPIO_PORT, &amp;gpio_init_struct);       \/* \u521d\u59cb\u5316LED1\u5f15\u811a *\/\n\n    gpio_init_struct.Pin = LED2_GPIO_PIN;                   \/* LED2\u5f15\u811a *\/\n    HAL_GPIO_Init(LED2_GPIO_PORT, &amp;gpio_init_struct);       \/* \u521d\u59cb\u5316LED2\u5f15\u811a *\/\n    \n    gpio_init_struct.Pin = LED3_GPIO_PIN;                   \/* LED3\u5f15\u811a *\/\n    HAL_GPIO_Init(LED3_GPIO_PORT, &amp;gpio_init_struct);       \/* \u521d\u59cb\u5316LED3\u5f15\u811a *\/\n\n    LED1(0);                                                \/* \u5173\u95ed LED1 *\/\n    LED2(0);                                                \/* \u5173\u95ed LED2 *\/\n    LED3(0);                                                \/* \u5173\u95ed LED3 *\/\n}<\/code><\/pre>\n<p>LED \u7684 .h\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"C\">#ifndef _LED_H\n#define _LED_H\n#include &quot;sys.h&quot;\n\n\n\/******************************************************************************************\/\n\/* \u5f15\u811a \u5b9a\u4e49 *\/\n\n#define LED1_GPIO_PORT                  GPIOA\n#define LED1_GPIO_PIN                   GPIO_PIN_6\n#define LED1_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)             \/* PA\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n#define LED2_GPIO_PORT                  GPIOA\n#define LED2_GPIO_PIN                   GPIO_PIN_7\n#define LED2_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)             \/* PA\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n#define LED3_GPIO_PORT                  GPIOB\n#define LED3_GPIO_PIN                   GPIO_PIN_0\n#define LED3_GPIO_CLK_ENABLE()          do{ __HAL_RCC_GPIOB_CLK_ENABLE(); }while(0)             \/* PB\u53e3\u65f6\u949f\u4f7f\u80fd *\/\n\n\/******************************************************************************************\/\n\/* LED\u7aef\u53e3\u5b9a\u4e49 *\/\n#define LED1(x)   do{ x ? \/\n                      HAL_GPIO_WritePin(LED1_GPIO_PORT, LED1_GPIO_PIN, GPIO_PIN_SET) : \/\n                      HAL_GPIO_WritePin(LED1_GPIO_PORT, LED1_GPIO_PIN, GPIO_PIN_RESET); \/\n                  }while(0)      \/* LED1\u7ffb\u8f6c *\/\n\n#define LED2(x)   do{ x ? \/\n                      HAL_GPIO_WritePin(LED2_GPIO_PORT, LED2_GPIO_PIN, GPIO_PIN_SET) : \/\n                      HAL_GPIO_WritePin(LED2_GPIO_PORT, LED2_GPIO_PIN, GPIO_PIN_RESET); \/\n                  }while(0)      \/* LED2\u7ffb\u8f6c *\/\n\n#define LED3(x)   do{ x ? \/\n                      HAL_GPIO_WritePin(LED3_GPIO_PORT, LED3_GPIO_PIN, GPIO_PIN_SET) : \/\n                      HAL_GPIO_WritePin(LED3_GPIO_PORT, LED3_GPIO_PIN, GPIO_PIN_RESET); \/\n                  }while(0)      \/* LED3\u7ffb\u8f6c *\/\n\n\/* LED\u53d6\u53cd\u5b9a\u4e49 *\/\n#define LED1_TOGGLE()   do{ HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_GPIO_PIN); }while(0)        \/* \u7ffb\u8f6cLED0 *\/\n#define LED2_TOGGLE()   do{ HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_GPIO_PIN); }while(0)        \/* \u7ffb\u8f6cLED1 *\/\n#define LED3_TOGGLE()   do{ HAL_GPIO_TogglePin(LED3_GPIO_PORT, LED3_GPIO_PIN); }while(0)        \/* \u7ffb\u8f6cLED1 *\/\n\n\/******************************************************************************************\/\n\/* \u5916\u90e8\u63a5\u53e3\u51fd\u6570*\/\nvoid led_init(void);                                                                            \/* \u521d\u59cb\u5316 *\/\n\n#endif<\/code><\/pre>\n<h3>5.11 \u4e3b\u51fd\u6570\u903b\u8f91\u4ee3\u7801<\/h3>\n<p>main.c \u5982\u4e0b\uff0c\u8c03\u7528\u5404\u4e2a\u51fd\u6570\u4ee5\u5b9e\u73b0\u6211\u4eec\u5f53\u6e29\u6e7f\u5ea6\u6b63\u5e38\uff0c\u8702\u9e23\u5668\u4e0d\u62a5\u8b66\uff0cLED \u706f\u4e0d\u4eae\uff1b\u5f53\u6e29\u6e7f\u5ea6\u8d85\u51fa\u8bbe\u5b9a\u9608\u503c\u65f6\u8702\u9e23\u5668\u62a5\u8b66\uff0cLED \u706f\u95ea\u70c1\u7684\u76ee\u6807\u3002<\/p>\n<pre><code class=\"c\">#include &quot;sys.h&quot;\n#include &quot;usart.h&quot;\n#include &quot;delay.h&quot;\n#include &quot;esp8266.h&quot;\n#include &quot;mqtt.h&quot;\n#include &quot;tasks.h&quot;\n#include &quot;systick.h&quot;\n#include &quot;led.h&quot;\n#include &quot;beep.h&quot;\n#include &quot;dht11.h&quot;\n\n\nint main(void)\n{\n    HAL_Init();                                 \/* \u521d\u59cb\u5316HAL\u5e93 *\/\n    sys_stm32_clock_init(RCC_PLL_MUL9);         \/* \u8bbe\u7f6e\u65f6\u949f,72M *\/\n    usart_init(115200);                         \/* \u6ce2\u7279\u7387\u8bbe\u4e3a115200 *\/\n    SysTick_Init(systick_isr);\n    led_init();\n    beep_init();\n\n    LED1(1);                                    \/\/\u7cfb\u7edf\u542f\u52a8\uff0cLED1\u957f\u4eae\n    network_connection();                       \/\/ESP8266\u8fde\u63a5OneNET\uff0c\u8ba2\u9605\u4e3b\u9898\n\n    while(1)\n    {\n        dht11_task();                           \/\/\u8bfb\u53d6\u6e29\u6e7f\u5ea6\n        status_post_task();                     \/\/\u6570\u636e\u4e0a\u62a5\n        heart_send_task();                      \/\/\u53d1\u9001\u5fc3\u8df3\u8bf7\u6c42\n        mqtt_receive_task();                    \/\/\u63a5\u6536\u5fc3\u8df3\u54cd\u5e94\n        alarm_post_task();                      \/\/\u53d1\u5e03\u62a5\u8b66\n    }\n}<\/code><\/pre>\n<h3>5.12 \u8fd0\u884c\u8fc7\u7a0b<\/h3>\n<p>\u70e7\u5f55\u597d\u540e\uff0c\u4e32\u53e3\u548c OneNET \u5e73\u53f0\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"394\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmD\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u82e5\u6e29\u5ea6\/\u6e7f\u5ea6\u8d85\u51fa\u9608\u503c\uff0c\u4e32\u53e3\u62a5\u8b66\uff0cOneNet \u4e0a\u4e8b\u4ef6\u544a\u8b66\u8bb0\u5f55\uff0c\u8702\u9e23\u5668\u9e23\u53eb\uff0cLED \u95ea\u70c1\u3002<\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"393\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmE\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" width=\"723\" height=\"528\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdfMmF\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u4f18\u5316\u540e\u7684\u6e29\u6e7f\u5ea6\u76d1\u6d4b\u662f\u4e0d\u662f\u66f4\u5b8c\u6574\uff0c\u66f4\u4eba\u6027\u4e86\u3002\u5e0c\u671b\u5927\u5bb6\u80fd\u591f\u6709\u6240\u6536\u83b7\uff0c\u63a5\u4e0b\u6765\u6709\u673a\u4f1a\u8fd8\u4f1a\u7ee7\u7eed\u4f18\u5316\u66f4\u65b0\u8fd9\u4e2a\u9879\u76ee\u3002\u611f\u8c22\u5404\u4f4d\u770b\u5b98\uff0clove and peace\uff01<\/p>\n<hr>\n<p><strong>\u53e6\u5916\uff0c\u60f3\u8fdb\u5927\u5382\u7684\u540c\u5b66\uff0c\u4e00\u5b9a\u8981\u597d\u597d\u5b66\u7b97\u6cd5\uff0c\u8fd9\u662f\u9762\u8bd5\u5fc5\u5907\u7684\u3002\u8fd9\u91cc\u51c6\u5907\u4e86\u4e00\u4efd BAT \u5927\u4f6c\u603b\u7ed3\u7684 LeetCode \u5237\u9898\u5b9d\u5178\uff0c\u5f88\u591a\u4eba\u9760\u5b83\u4eec\u8fdb\u4e86\u5927\u5382\u3002<\/strong><\/p>\n<p><img decoding=\"async\" width=\"286\" height=\"83\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaCCY\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=X%2FJJUn4Nsp44z5QaA1DTyQ%3D%3D.RMRKYOsvYK2%2FuF7nKRpV5ACU1ZVr7oADfJIIf2kMEFStfXajjlzlAzPZ41DLylyb\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5237\u9898 | LeetCode\u7b97\u6cd5\u5237\u9898\u795e\u5668\uff0c\u770b\u5b8c BAT \u968f\u4f60\u6311\uff01<\/a><\/p>\n<h3>\u6709\u6536\u83b7\uff1f\u5e0c\u671b\u8001\u94c1\u4eec\u6765\u4e2a\u4e09\u8fde\u51fb\uff0c\u7ed9\u66f4\u591a\u7684\u4eba\u770b\u5230\u8fd9\u7bc7\u6587\u7ae0<\/h3>\n<p><strong>\u63a8\u8350\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=sKkNfWw8CWjd3fNZD0MAUw%3D%3D.81zsjJm5UCjJT6pwvYwxdI8ALmkz7wnpcAnLJREKAp%2FDo%2BYbVuuIoTrkXCiujyVY\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u7f16\u7a0b\u8d44\u6599\u5927\u5168<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=7Zxx5fl%2B4toSp%2F33enEUUQ%3D%3D.ok23rURQToI9luTOpNM5MLWjCHMwaq0Nq2Sx72jqInZGfwDa8vD7Hohdxt3nO6GF\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u8f6f\u4ef6\u8d44\u6e90<\/a><\/li>\n<\/ul>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u535a\u5ba2\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=RK%2FVTZR010lOeFZuhptChg%3D%3D.fSTgQou7YqZi%2F3ga1%2BMWh84hxor30hFPFzqspqnw56Y%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u826f\u8bb8\u5d4c\u5165\u5f0f\u6559\u7a0b\u7f51<\/a>\uff0c\u6ee1\u6ee1\u90fd\u662f\u5e72\u8d27\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045667496\">https:\/\/segmentfault.com\/a\/1190000045667496<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4e4b\u524d\u6211\u4eec\u505a\u4e86\u6e29\u6e7f\u5ea6\u76d1\u6d4b\u5c0f\u9879\u76ee\uff0c\u53ea\u662f\u628a\u6e29\u6e7f\u5ea6\u6570\u636e\u4e0a\u4f20\u5230 OneNET\uff0c\u73b0\u5728\u6211\u4eec\u6765\u4f18\u5316\u8fd9\u4e2a\u5c0f\u9879\u76ee\uff0c\u8ba9\u5b83\u66f4\u5b8c\u6574 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020535","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020535"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020535\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}