{"id":637,"date":"2022-11-22T23:35:17","date_gmt":"2022-11-22T15:35:17","guid":{"rendered":"http:\/\/wordpress.loc\/?p=637"},"modified":"2023-02-22T20:48:44","modified_gmt":"2023-02-22T12:48:44","slug":"esp32_ch1-21","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/11\/22\/637\/","title":{"rendered":"\u7b2c20\u7bc7 ESP32 \u7279\u6b8a\u61c9\u7528\uff1a\u591a\u6838\u5fc3\u57f7\u884c"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>ESP32\u64c1\u6709\u5169\u500b\u6838\u5fc3\uff0c\u4e0d\u904e\u5e73\u5e38\u90fd\u53ea\u7528\u5230\u4e00\u500b\u6838\u5fc3\uff0c\u9019\u6a23\u662f\u4e0d\u662f\u5f88\u6d6a\u8cbb\uff0c\u6211\u5011\u5982\u4f55\u5584\u7528\u589e\u52a0\u6548\u80fd\u5462\uff1f\u6216\u8005\u5982\u4f55\u4f7f\u7528\u5e73\u884c\u8655\u7406\u5462\uff1f<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-ht-block-toc is-style-rounded htoc htoc--position-wide toc-list-style-plain\" data-htoc-state=\"expanded\"><span class=\"htoc__title\"><span class=\"ht_toc_title\">Table of Contents<\/span><span class=\"htoc__toggle\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"16\" height=\"16\"><g fill=\"#444\"><path d=\"M15 7H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><path d=\"M15 1H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1zM15 13H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><\/g><\/svg><\/span><\/span><div class=\"htoc__itemswrap\"><ul class=\"ht_toc_list\"><li class=\"\"><a href=\"#htoc-\">\u524d\u8a00<\/a><\/li><li class=\"\"><a href=\"#htoc-1\">\u4e00\u3001 \u591a\u6838\u5fc3\u662f\u4ec0\u9ebc\u6982\u5ff5\uff1f<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-11\">\u96d9\u6838\u5fc3\u57f7\u884c\u6709\u4ec0\u9ebc\u597d\u8655\uff1f<\/a><\/li><\/ul><\/li><li class=\"\"><a href=\"#htoc-esp32\">\u4e8c\u3001\u986f\u793aESP32\u57f7\u884c\u6838\u5fc3<\/a><\/li><li class=\"\"><a href=\"#htoc-esp321\">\u4e09\u3001\u96d9\u6838\u5fc3\u57f7\u884cESP32\u65b9\u6cd5<\/a><\/li><\/ul><\/div><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u524d\u8a00<\/h2>\n\n\n\n<p>ESP32\u64c1\u6709\u5169\u500b\u6838\u5fc3\uff0c\u4e0d\u904e\u5e73\u5e38\u90fd\u53ea\u7528\u5230\u4e00\u500b\u6838\u5fc3\uff0c\u9019\u6a23\u662f\u4e0d\u662f\u5f88\u6d6a\u8cbb\uff0c\u6211\u5011\u5982\u4f55\u5584\u7528\u589e\u52a0\u6548\u80fd\u5462\uff1f\u6216\u8005\u5982\u4f55\u4f7f\u7528\u5e73\u884c\u8655\u7406\u5462\uff1f\u672c\u7ae0\u5206\u70ba\u4e09\u500b\u90e8\u4efd\u89e3\u8aaa\uff1a<br>\u4e00\u3001 \u591a\u6838\u5fc3\u6982\u5ff5<br>\u4e8c\u3001 \u986f\u793a\u57f7\u884c\u6838\u5fc3<br>\u4e09\u3001 \u96d9\u6838\u5fc3\u57f7\u884c<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-1\">\u4e00\u3001 \u591a\u6838\u5fc3\u662f\u4ec0\u9ebc\u6982\u5ff5\uff1f<\/h2>\n\n\n\n<p>\u6211\u5011\u5e38\u807d\u5230\u8aaa\u6211\u7684\u624b\u6a5f\u67094\u6838\u5fc3\uff0c\u96fb\u8166\u67098\u6838\u5fc3\uff0c\u6240\u8b02\u7684\u591a\u6838\u5fc3\uff08Multi-core\uff09\u7c21\u55ae\u7684\u8aaa\u5c31\u662fCPU\u80fd\u540c\u6642\u8655\u7406\u8f03\u591a\u7684\u4efb\u52d9\u4e14\u4e0d\u6703\u4e92\u76f8\u5e72\u64fe\uff0c\u53e6\u5916\u4e00\u7a2e\u865b\u64ec\u7684\u591a\u6838\u5fc3\u7a31\u70ba\u591a\u57f7\u884c\u7dd2\uff08Thread\uff09\u5247\u662fCPU\u7684\u5206\u6642\u591a\u5de5\uff0c\u975e\u672c\u7bc7\u7684\u8a0e\u8ad6\u7bc4\u570d\uff0c\u7531\u65bcESP32\u6709\u8457240\/160MHz\u7684\u96d9\u6838\u5fc3CPU\uff0c\u56e0\u6b64\u672c\u7bc7\u5c07\u8981\u8aaa\u660e\u662f\u80fd\u5c07\u4efb\u52d9\u6307\u5b9a\u7d66\u6838\u5fc3\u57f7\u884c\u7684\u300cxTaskCreatePinnedToCore\u300d\u51fd\u6578\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-11\">\u96d9\u6838\u5fc3\u57f7\u884c\u6709\u4ec0\u9ebc\u597d\u8655\uff1f<\/h3>\n\n\n\n<p>\u4f8b\u5982\u53ef\u4ee5\u589e\u52a0\u6548\u80fd\uff0c\u6216\u8005\u5e73\u884c\u8655\u7406\uff0c\u8209\u4f8b\u800c\u8a00\uff0c\u6211\u5011\u6709\u4e00\u500b\u5de5\u4f5c\u662f\u8981\u5075\u6e2c\u73fe\u5834\u6eab\u6fd5\u5ea6\u4e26\u4e0a\u50b3\u8cc7\u6599\u5eab\u5b58\u6a94\uff0c\u6bcf20\u79d2\u611f\u6e2c\u4e0a\u50b3\u4e00\u6b21\uff0c\u5047\u5b9a\u9019\u9805\u898f\u5b9a\u5f88\u56b4\u683c\uff0c\u5fc5\u9808\u6e96\u6642\u4e0a\u50b3\u4e0d\u80fd\u6709\u5ef6\u9072\uff0c\u5728\u4ee5\u5f80\u7a0b\u5f0f\u7684\u64b0\u5beb\u6d41\u7a0b\u4e0b\uff0c\u611f\u6e2c\u8207\u7db2\u8def\u4e0a\u50b3\u662f\u5beb\u5728\u540c\u4e00\u500b\u7a0b\u5e8f\u5167\uff0c\u4e5f\u5c31\u662f\u8b80\u53d6\u6eab\u6fd5\u5ea6\u2192\u4e0a\u50b3\u8cc7\u6599\u5eab\u2192\u7b49\u501920\u79d2\uff0c\u4f46\u662f\u4e0a\u50b3\u8cc7\u6599\u5eab\u9808\u770b\u7db2\u8def\u662f\u5426\u64c1\u585e\uff0c\u5047\u8a2d\u4e0a\u50b3\u6642\u9593\u82b1\u4e863\u79d2\uff0c\u518d\u52a0\u4e0a\u7b49\u501920\u79d2\u5f8c\uff0c\u7b49\u65bc\u662f23\u79d2\u904e\u4e86\uff0c\u9577\u4e45\u4e0b\u4f86\u5c31\u6703\u5ef6\u9072\u8d8a\u4f86\u8d8a\u591a\u3002<\/p>\n\n\n\n<p>\u4e5f\u8a31\u4f60\u6703\u60f3\u8aaa\u6211\u5011\u53ef\u4ee5\u5c07\u7b49\u5019\u6642\u9593\u6539\u621017\u79d2\uff0c\u9019\u6a23\u4e0a\u50b3\u6642\u95933\u79d2\u52a0\u8d77\u4f86\u525b\u597d20\u79d2\uff0c\u4e0d\u904e\u4f60\u4e5f\u77e5\u9053\u7db2\u8def\u4e0d\u662f\u90a3\u9ebc\u597d\u9810\u4f30\uff0c\u6709\u6642\u5019\u9130\u5c45\u4e0b\u8f09\u8ff7\u7247\uff0c\u901f\u5ea6\u5c31\u6162\u4e86\uff0c\u800c\u534a\u591c\u6642\u6c92\u4eba\u901f\u5ea6\u53c8\u8b8a\u5f97\u98db\u5feb\uff0c\u9019\u6a23\u6211\u5011\u7e3d\u662f\u6c92\u8fa6\u6cd5\u627e\u5230\u4e00\u500b\u6642\u9593\u4f86\u88dc\u56de\u3002<\/p>\n\n\n\n<p>\u800c\u591a\u6838\u5fc3\u5728\u9019\u88e1\u5c31\u975e\u5e38\u9069\u7528\uff0c\u4e5f\u5c31\u662f\u4e00\u500b\u6838\u5fc3\u8ca0\u8cac\u8b80\u53d6\u6eab\u6fd5\u5ea6\u8cc7\u6599\uff0c\u53e6\u5916\u4e00\u500b\u6838\u5fc3\u5247\u5c07\u8cc7\u6599\u9001\u5230\u8cc7\u6599\u5eab\uff0c\u5e73\u884c\u8655\u7406\u5169\u8005\u4e92\u4e0d\u76f8\u5e72\uff0c\u5c31\u53ef\u4ee5\u56fa\u5b9a\u7e3d\u6642\u9593\u4e0d\u8b8a\uff0c\u800c\u9019\u5c31\u662f\u96d9\u6838\u5fc3CPU\u6642\u7684\u597d\u8655\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1584896202-4290209096_n.png?resize=841%2C519&#038;ssl=1\" alt=\"\" width=\"841\" height=\"519\"\/><figcaption class=\"wp-element-caption\">\u96d9\u6838\u5fc3\u6982\u5ff5\u5716<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-esp32\">\u4e8c\u3001\u986f\u793aESP32\u57f7\u884c\u6838\u5fc3<\/h2>\n\n\n\n<p>\u4e00\u822c\u6211\u5011\u7684\u7a0b\u5f0f\u90fd\u50c5\u5728ESP32\u7684\u6838\u5fc31\u57f7\u884c\uff08\u6838\u5fc3\u7de8\u865f1\uff09\uff0c\u6240\u4ee5\u6839\u672c\u6c92\u7528\u5230\u7b2c2\u500b\u6838\u5fc3\uff08\u6838\u5fc3\u7de8\u865f0\uff09\uff0c\u70ba\u4e86\u8b49\u660e\uff0c\u6211\u5011\u53ef\u4ee5\u900f\u904e<mark style=\"background-color:#fcb900\" class=\"has-inline-color has-black-color\">xPortGetCoreID()<\/mark>\u51fd\u6578\u4f86\u986f\u793a\u73fe\u5728\u4f7f\u7528\u5230\u54ea\u4e00\u500b\u6838\u5fc3\uff0c\u4f8b\u5982\u6211\u5011\u5beb\u4e00\u500b\u7c21\u55ae\u7684HelloWorld\uff0c\u4f86\u6e2c\u8a66\u770b\u770b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup() {\n  Serial.begin(115200);\n}\n\nvoid loop() {\n  Serial.println(\"HelloWorld!\");\n  Serial.print(\"\u4f7f\u7528\u6838\u5fc3\u7de8\u865f\uff1a\");\n  Serial.println(xPortGetCoreID());\/\/xPortGetCoreID()\u986f\u793a\u57f7\u884c\u6838\u5fc3\u7de8\u865f\ndelay(1000);\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1584896233-1958234897.png?resize=840%2C405&#038;ssl=1\" alt=\"\" width=\"840\" height=\"405\"\/><figcaption class=\"wp-element-caption\">\u986f\u793a\u4f7f\u7528\u6838\u5fc3\u7de8\u865f-\u57f7\u884c\u7d50\u679c<\/figcaption><\/figure>\n\n\n\n<p>\u4e0a\u5716\u53ef\u4ee5\u77e5\u9053\uff0c\u5728\u672a\u7279\u5225\u6307\u5b9a\u57f7\u884c\u6838\u5fc3\u524d\uff0c\u7a0b\u5e8f\u90fd\u5728\u6838\u5fc31\u4e2d\u57f7\u884c\uff0c\u6211\u5011\u7a31\u70ba\u55ae\u7dda\u7a0b\uff0c\u800c\u672a\u4f7f\u7528\u5230\u53e6\u5916\u4e00\u500b\u6838\u5fc3\uff0c\u6211\u5011\u518d\u62ff\u524d\u4e00\u7ae0ThingSpeak\u7684\u7bc4\u4f8b\u4f86\u6f14\u7df4\u770b\u770b\uff0c\u9806\u4fbf\u4e86\u89e3\u57f7\u884c\u7684\u6642\u9593\u8b8a\u5316\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h>\n#include &lt;HTTPClient.h>\n#include &lt;SimpleDHT.h>\n\/\/\u8acb\u4fee\u6539\u4ee5\u4e0b\u53c3\u6578--------------------------------------------\nchar ssid&#91;] = \"SSID\";\nchar password&#91;] = \"SSIDpassword\";\n\/\/\u8acb\u4fee\u6539\u70ba\u4f60\u81ea\u5df1\u7684API Key\uff0c\u4e26\u5c07https\u6539\u70bahttp\nString url = \"http:\/\/api.thingspeak.com\/update?api_key=\u63db\u6210\u4f60\u7684APIKey\";\nint pinDHT11 = 14;\/\/\u5047\u8a2dDHT11\u63a5\u5728\u8173\u4f4dGPIO14\uff0c\u9eb5\u5305\u677f\u5de6\u5074\u5e8f\u865f8\n\/\/---------------------------------------------------------\nSimpleDHT11 dht11(pinDHT11);\/\/\u5ba3\u544aSimpleDHT11\u7269\u4ef6\n\nvoid setup()\n{\n  Serial.begin(115200);\n  Serial.print(\"\u958b\u59cb\u9023\u7dda\u5230\u7121\u7dda\u7db2\u8defSSID:\");\n  Serial.println(ssid);\n  WiFi.mode(WIFI_STA);\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    Serial.print(\".\");\n    delay(1000);\n  }\n  Serial.println(\"\u9023\u7dda\u5b8c\u6210\");\n}\n\nvoid loop()\n{\n  Serial.print(\"\u4f7f\u7528\u6838\u5fc3\u7de8\u865f\uff1a\");\n  Serial.println(xPortGetCoreID());\n  \/\/\u5617\u8a66\u8b80\u53d6\u6eab\u6fd5\u5ea6\u5167\u5bb9\n  byte temperature = 0;\n  byte humidity = 0;\n  int err = SimpleDHTErrSuccess;\n  if ((err = dht11.read(&amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {\n    Serial.print(\"\u6eab\u5ea6\u8a08\u8b80\u53d6\u5931\u6557\uff0c\u932f\u8aa4\u78bc=\"); Serial.println(err); delay(1000);\n    return;\n  }\n  \/\/\u8b80\u53d6\u6210\u529f\uff0c\u5c07\u6eab\u6fd5\u5ea6\u986f\u793a\u5728\u5e8f\u5217\u8996\u7a97\n  Serial.print(\"\u6eab\u5ea6\u8a08\u8b80\u53d6\u6210\u529f: \");\n  Serial.print((int)temperature); Serial.print(\" *C, \");\n  Serial.print((int)humidity); Serial.println(\" H\");\n  \/\/\u958b\u59cb\u50b3\u9001\u5230thingspeak\n  Serial.println(\"\u555f\u52d5\u7db2\u9801\u9023\u7dda\");\n  HTTPClient http;\n  \/\/\u5c07\u6eab\u5ea6\u53ca\u6fd5\u5ea6\u4ee5http get\u53c3\u6578\u65b9\u5f0f\u88dc\u5165\u7db2\u5740\u5f8c\u65b9\n  url = url + \"&amp;field1=\" + (int)temperature + \"&amp;field2=\" + (int)humidity;\n  \/\/http client\u53d6\u5f97\u7db2\u9801\u5167\u5bb9\n  http.begin(url);\n  int httpCode = http.GET();\n  if (httpCode == HTTP_CODE_OK)      {\n    \/\/\u8b80\u53d6\u7db2\u9801\u5167\u5bb9\u5230payload\n    String payload = http.getString();\n    \/\/\u5c07\u5167\u5bb9\u986f\u793a\u51fa\u4f86\n    Serial.print(\"\u7db2\u9801\u5167\u5bb9=\");\n    Serial.println(payload);\n  } else {\n    \/\/\u8b80\u53d6\u5931\u6557\n    Serial.println(\"\u7db2\u8def\u50b3\u9001\u5931\u6557\");\n  }\n  http.end();\n  delay(20000);\/\/\u4f11\u606f20\u79d2\n}<\/code><\/pre>\n\n\n\n<p>\u70ba\u4e86\u8a08\u7b97\u7db2\u8def\u50b3\u9001\u7684\u5ef6\u9072\u6642\u9593\uff0c\u6211\u5011\u53ef\u4ee5\u958b\u555f\u986f\u793a\u6642\u9593\u6233\u8a18Show timestamp\u4f86\u89c0\u5bdf\u6bcf\u6b21\u7684\u50b3\u8f38\u6642\u9593\uff0c\u6211\u5011\u6bd4\u8f03\u4e0a\u57162\u82073\u4e4b\u9593\u7684\u6642\u9593\u5dee\u7570\u767c\u73fe\uff0c\u7d93\u904e\u4e94\u6b21\u7684\u50b3\u9001\uff0c\u6642\u9593\u5df2\u7d93\u6162\u4e86\u7d044\u79d2\u9418\uff0c\u540c\u6642\u6211\u5011\u89c0\u5bdf\u57f7\u884c\u6838\u5fc3\u4e5f\u90fd\u662f\u5728\u7de8\u865f1\u4e0a\u57f7\u884c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1584896512-187667722.png?resize=841%2C854&#038;ssl=1\" alt=\"\" width=\"841\" height=\"854\"\/><figcaption class=\"wp-element-caption\">\u55ae\u6838\u5fc3\u57f7\u884c\u6642\u9593\u5ef6\u9072\u89c0\u5bdf<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-esp321\">\u4e09\u3001\u96d9\u6838\u5fc3\u57f7\u884cESP32\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u4e86\u89e3\u6982\u5ff5\u5f8c\uff0c\u6211\u5011\u5148\u4f86\u5be6\u505aESP32\u591a\u6838\u5fc3\u7684\u5beb\u6cd5\uff0c\u6b65\u9a5f\u662f\u9019\u6a23\u7684<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5ba3\u544a\u4efb\u52d9\u8b8a\u6578\uff1aTaskHandle_t Task1;<\/li>\n\n\n\n<li>\u8a2d\u5b9a\u4e26\u57f7\u884c\u4efb\u52d9\uff1a\/\/\u8a2d\u5b9a\u4efb\u52d9<br>xTaskCreatePinnedToCore(<br>Task1code, \/\/\u672c\u4efb\u52d9\u5be6\u969b\u5c0d\u61c9\u7684Function<br>&#8220;Task1&#8221;, \/\/\u4efb\u52d9\u540d\u7a31\uff08\u81ea\u884c\u8a2d\u5b9a\uff09<br>10000, \/\/\u6240\u9700\u5806\u758a\u7a7a\u9593\uff08\u5e38\u752810000\uff09<br>NULL, \/\/\u8f38\u5165\u503c<br>0, \/\/\u512a\u5148\u5e8f\uff1a0\u4ee3\u8868\u6700\u4f4e\uff0c\u6578\u5b57\u8d8a\u9ad8\u8d8a\u512a\u5148<br>&amp;Task1, \/\/\u5c0d\u61c9\u7684\u4efb\u52d9handle\u8b8a\u6578<br>0); \/\/\u6307\u5b9a\u57f7\u884c\u6838\u5fc3\u7de8\u865f\uff080\u30011\u6216tskNO_AFFINITY\uff1a\u7cfb\u7d71\u6307\u5b9a\uff09<\/li>\n<\/ol>\n\n\n\n<p>\u56e0\u6b64\u6211\u5011\u5c07\u539f\u672cThinkSpeak\u7684\u6d41\u7a0b\u6539\u70ba\u591a\u6838\u5fc3\u67b6\u69cb\uff0c\u6838\u5fc31\u57f7\u884c\u4e3b\u6d41\u7a0bloop()\u76e3\u63a7DHT11\u7684\u6eab\u6ebc\u5ea6\uff0c\u5c07\u6578\u503c\u5b58\u653e\u5728\u516c\u7528\u8b8a\u6578\u5340\uff0c\u4e26\u8a2d\u5b9a\u4e0a\u50b3\u65d7\u6a19=True\uff0c\u800c\u6838\u5fc30\u57f7\u884cTask1\uff0c\u4e3b\u8981\u5de5\u4f5c\u662f\u5c07\u8cc7\u6599\u4e0a\u50b3\uff0c\u7576\u767c\u73fe\u4e0a\u50b3\u65d7\u6a19=True\u5f8c\u5c31\u57f7\u884c\u4e0a\u50b3\uff0c\u4e26\u5728\u5b8c\u6210\u4e0a\u50b3\u5f8c\u4fee\u6539\u4e0a\u50b3\u65d7\u6a19=False\uff0c\u7b49\u5f85\u4e0b\u6b21\u4efb\u52d9\u555f\u52d5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1584896647-2988318161_n.png?resize=839%2C743&#038;ssl=1\" alt=\"\" width=\"839\" height=\"743\"\/><figcaption class=\"wp-element-caption\">\u591a\u6838\u5fc3\u57f7\u884c\u67b6\u69cb\u5716<\/figcaption><\/figure>\n\n\n\n<p>\u6b64\u6642\u6211\u5011\u4ee5\u4e0a\u5716\u65b9\u5f0f\u52a0\u5165\u591a\u6838\u5fc3\u67b6\u69cb\u5f8c\uff0c\u7a0b\u5f0f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h>\n#include &lt;HTTPClient.h>\n#include &lt;SimpleDHT.h>\n\/\/\u8acb\u4fee\u6539\u4ee5\u4e0b\u53c3\u6578--------------------------------------------\nchar ssid&#91;] = \"SSID\";\nchar password&#91;] = \"SSIDpassword\";\n\/\/\u8acb\u4fee\u6539\u70ba\u4f60\u81ea\u5df1\u7684API Key\uff0c\u4e26\u5c07https\u6539\u70bahttp\nString url = \"http:\/\/api.thingspeak.com\/update?api_key=\u63db\u6210\u4f60\u7684APIKey\";\nint pinDHT11 = 14;\/\/\u5047\u8a2dDHT11\u63a5\u5728\u8173\u4f4dGPIO14\uff0c\u9eb5\u5305\u677f\u5de6\u5074\u5e8f\u865f8\n\/\/---------------------------------------------------------\nSimpleDHT11 dht11(pinDHT11);\/\/\u5ba3\u544aSimpleDHT11\u7269\u4ef6\n\n\/\/\u516c\u7528\u8b8a\u6578\u5340\nbyte temperature = 0;\nbyte humidity = 0;\nbool SendFlag = false;\n\/\/\u5ba3\u544a\u4efb\u52d9Task1\nTaskHandle_t Task1;\n\n\/\/\u4efb\u52d91\u526f\u7a0b\u5f0fTask1_senddata\nvoid Task1_senddata(void * pvParameters ) {\n  \/\/\u7121\u7aae\u8ff4\u5708\n  for (;;) {\n    \/\/\u5075\u6e2c\u4e0a\u50b3\u65d7\u6a19\u662f\u5426\u70batrue\n    if (SendFlag) {\n      Serial.print(\"Task1\uff1a\u555f\u52d5\u7db2\u9801\u9023\u7dda\uff0cat core:\");\n      Serial.println(xPortGetCoreID());\n      HTTPClient http;\n      \/\/\u5c07\u6eab\u5ea6\u53ca\u6fd5\u5ea6\u4ee5http get\u53c3\u6578\u65b9\u5f0f\u88dc\u5165\u7db2\u5740\u5f8c\u65b9\n      String url1 = url + \"&amp;field1=\" + (int)temperature + \"&amp;field2=\" + (int)humidity;\n      \/\/http client\u53d6\u5f97\u7db2\u9801\u5167\u5bb9\n      http.begin(url1);\n      int httpCode = http.GET();\n      if (httpCode == HTTP_CODE_OK) {\n        \/\/\u8b80\u53d6\u7db2\u9801\u5167\u5bb9\u5230payload\n        String payload = http.getString();\n        \/\/\u5c07\u5167\u5bb9\u986f\u793a\u51fa\u4f86\n        Serial.print(\"\u7db2\u9801\u5167\u5bb9=\");\n        Serial.println(payload);\n      } else {\n        \/\/\u50b3\u9001\u5931\u6557\n        Serial.println(\"\u7db2\u8def\u50b3\u9001\u5931\u6557\");\n      }\n      \/\/\u4fee\u6539\u5b8c\u7562\uff0c\u4fee\u6539\u50b3\u9001\u65d7\u6a19=false\n      SendFlag = false;\n      http.end();\n    } else {\n      \/\/Task1\u4f11\u606f\uff0cdelay(1)\u4e0d\u53ef\u7701\u7565\n      delay(1);\n    }\n  }\n}\n\nvoid setup()\n{\n  Serial.begin(115200);\n  Serial.print(\"\u958b\u59cb\u9023\u7dda\u5230\u7121\u7dda\u7db2\u8defSSID:\");\n  Serial.println(ssid);\n  WiFi.mode(WIFI_STA);\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    Serial.print(\".\");\n    delay(1000);\n  }\n  Serial.println(\"\u9023\u7dda\u5b8c\u6210\");\n  \/\/\u5728\u6838\u5fc30\u555f\u52d5\u4efb\u52d91\n  xTaskCreatePinnedToCore(\n    Task1_senddata, \/*\u4efb\u52d9\u5be6\u969b\u5c0d\u61c9\u7684Function*\/\n    \"Task1\",        \/*\u4efb\u52d9\u540d\u7a31*\/\n    10000,          \/*\u5806\u758a\u7a7a\u9593*\/\n    NULL,           \/*\u7121\u8f38\u5165\u503c*\/\n    0,                 \/*\u512a\u5148\u5e8f0*\/\n    &amp;Task1,       \/*\u5c0d\u61c9\u7684\u4efb\u52d9\u8b8a\u6578\u4f4d\u5740*\/\n    0);                \/*\u6307\u5b9a\u5728\u6838\u5fc30\u57f7\u884c *\/\n}\n\nvoid loop()\n{\n  Serial.print(\"loop\u4e3b\u6d41\u7a0b\uff1a\u6eab\u6fd5\u5ea6\u8b80\u53d6\uff0cat core:\");\n  Serial.println(xPortGetCoreID());\n  \/\/\u5617\u8a66\u8b80\u53d6\u6eab\u6fd5\u5ea6\u5167\u5bb9\n  int err = SimpleDHTErrSuccess;\n  if ((err = dht11.read(&amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {\n    Serial.print(\"\u6eab\u5ea6\u8a08\u8b80\u53d6\u5931\u6557\uff0c\u932f\u8aa4\u78bc=\"); Serial.println(err); delay(1000);\n    return;\n  }\n  \/\/\u8b80\u53d6\u6210\u529f\uff0c\u5c07\u6eab\u6fd5\u5ea6\u986f\u793a\u5728\u5e8f\u5217\u8996\u7a97\n  Serial.print(\"\u6eab\u5ea6\u8a08\u8b80\u53d6\u6210\u529f: \");\n  Serial.print((int)temperature); Serial.print(\" *C, \");\n  Serial.print((int)humidity); Serial.println(\" H\");\n  \/\/\u4fee\u6539\u4e0a\u50b3\u65d7\u6a19=true\n  SendFlag = true;\n  delay(20000);\/\/\u4f11\u606f20\u79d2\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1584896719-1542021350.png?resize=838%2C813&#038;ssl=1\" alt=\"\" width=\"838\" height=\"813\"\/><figcaption class=\"wp-element-caption\">\u96d9\u6838\u5fc3\u57f7\u884c\u6642\u9593\u8aa4\u5dee\u5c0f<\/figcaption><\/figure>\n\n\n\n<p>\u7d93\u7531\u5c07\u7a0b\u5f0f\u4fee\u6539\u70ba\u591a\u6838\u5fc3\u57f7\u884c\u5f8c\uff0c\u53ef\u4ee5\u767c\u73fe\uff0c\u5118\u7ba1\u7db2\u8def\u6703\u6709\u5ef6\u9072\uff0c\u4f46\u662f\u6bcf\u6b21\u958b\u59cb\u50b3\u9001\u7684\u6642\u9593\u90fd\u4e0d\u6703\u76f8\u5dee\u592a\u591a\uff0c\u591a\u6b21\u57f7\u884c\u5f8c\uff0c\u4ecd\u80fd\u4fdd\u6301\u57280.1\u79d2\u5167\u7684\u8aa4\u5dee\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1584897507-2242237603_n.png?resize=842%2C281&#038;ssl=1\" alt=\"\" width=\"842\" height=\"281\"\/><\/figure>\n\n\n\n<p>\u8b80\u8005\u4e86\u89e3\u591a\u6838\u5fc3\u7684\u512a\u9ede\u5f8c\uff0c\u53ef\u4ee5\u601d\u8003\u8981\u5982\u4f55\u61c9\u7528\u5728\u4e0d\u540c\u7684\u8b70\u984c\u4e0a\u5594\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ESP32\u64c1\u6709\u5169\u500b\u6838\u5fc3\uff0c\u4e0d\u904e\u5e73\u5e38\u90fd\u53ea\u7528\u5230\u4e00\u500b\u6838\u5fc3\uff0c\u9019\u6a23\u662f\u4e0d\u662f\u5f88\u6d6a\u8cbb\uff0c\u6211\u5011\u5982\u4f55\u5584\u7528\u589e\u52a0\u6548\u80fd\u5462\uff1f\u6216\u8005\u5982\u4f55\u4f7f\u7528\u5e73\u884c\u8655 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,29],"tags":[],"class_list":["post-637","post","type-post","status-publish","format-standard","hentry","category-esp32","category-esp32-started"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=637"}],"version-history":[{"count":2,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/637\/revisions"}],"predecessor-version":[{"id":931,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/637\/revisions\/931"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}