{"id":20699,"date":"2025-07-10T20:31:42","date_gmt":"2025-07-10T12:31:42","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=20699"},"modified":"2025-07-14T07:18:40","modified_gmt":"2025-07-13T23:18:40","slug":"esp32-wroom-32-%e4%bd%bf%e7%94%a8-ble-%e4%bd%8e%e5%8a%9f%e8%80%97%e8%93%9d%e7%89%99-4-2%e3%80%90platformioarduino%e3%80%91%ef%bc%88%e7%bc%96%e8%be%91%e4%b8%ad%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=20699","title":{"rendered":"\u57fa\u4e8e ESP32-WROOM-32 \u5b66\u4e60 BLE \u4f4e\u529f\u8017\u84dd\u7259 4.2\u3010PlatformIO+Arduino\u3011\uff08\u7f16\u8f91\u4e2d\uff09"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\" >\u6d4b\u8bd5\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E8%93%9D%E7%89%99%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7\" >\u84dd\u7259\u8c03\u8bd5\u5de5\u5177<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E8%B5%84%E6%96%99\" >\u8d44\u6599<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E5%AD%A6%E4%B9%A0%E5%AE%9E%E8%B7%B5\" >\u5b66\u4e60\u5b9e\u8df5<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E4%BF%A1%E9%81%93\" >\u4fe1\u9053<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E6%89%AB%E6%8F%8F%E8%AE%BE%E5%A4%87\" >\u626b\u63cf\u8bbe\u5907<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E6%9C%8D%E5%8A%A1%E5%99%A8\" >\u670d\u52a1\u5668<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E8%87%AA%E5%AE%9A%E4%B9%89_UUID\" >\u81ea\u5b9a\u4e49 UUID<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E4%BA%A4%E4%BA%92\" >\u4ea4\u4e92<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.iyatt.com\/?p=20699\/#%E9%81%B5%E5%BE%AA_Assigned_Numbers_%E7%9A%84_UUID\" >\u9075\u5faa Assigned Numbers \u7684 UUID<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\"><\/span>\u6d4b\u8bd5\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>\n<p>VScode\uff1a 1.101.2<\/p>\n<\/li>\n<li>\n<p>PlatformIO\uff1aCore 6.1.18\uff0cHome 3.3.4<\/p>\n<\/li>\n<li>\n<p>Espressif 32\uff1a6.11.0\uff08\u5de5\u5177\u94fe\u5e73\u53f0\uff09<\/p>\n<\/li>\n<li>\n<p>ESP32-WROOM-32\uff08\u786c\u4ef6\uff0c\u652f\u6301\u84dd\u7259 4.2 \u7ecf\u5178\u84dd\u7259\u548c\u4f4e\u529f\u8017\u84dd\u7259\uff09<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1751892433605.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 912px; --smush-placeholder-aspect-ratio: 912\/152;\" \/><\/p>\n<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E8%93%9D%E7%89%99%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7\"><\/span>\u84dd\u7259\u8c03\u8bd5\u5de5\u5177<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>Android-nRF-Connect\uff08Android\u624b\u673a\u7aef\uff09\uff1a<a href=\"https:\/\/github.com\/NordicSemiconductor\/Android-nRF-Connect\/releases\">https:\/\/github.com\/NordicSemiconductor\/Android-nRF-Connect\/releases<\/a><\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E8%B5%84%E6%96%99\"><\/span>\u8d44\u6599<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>Core Specification 4.2\uff08\u6838\u5fc3\u89c4\u8303 4.2\uff0c\u4e0b\u79f0 Core\uff09\uff1a<a href=\"https:\/\/www.bluetooth.com\/specifications\/specs\/core-specification-4-2\/\">https:\/\/www.bluetooth.com\/specifications\/specs\/core-specification-4-2\/<\/a><\/li>\n<li>Specifications and documents\uff08\u89c4\u8303\u4e0e\u6587\u6863\uff09\uff1a<a href=\"https:\/\/www.bluetooth.com\/specifications\/specs\/\">https:\/\/www.bluetooth.com\/specifications\/specs\/<\/a><\/li>\n<li>Assigned Numbers\uff08\u5206\u914d\u53f7\u7801\uff09\uff1a<a href=\"https:\/\/www.bluetooth.com\/specifications\/assigned-numbers\/\">https:\/\/www.bluetooth.com\/specifications\/assigned-numbers\/<\/a><\/li>\n<li>GATT Specification Supplement\uff08\u901a\u7528\u5c5e\u6027\u914d\u7f6e\u6587\u4ef6\u89c4\u8303\u8865\u5145\uff09\uff1a<a href=\"https:\/\/www.bluetooth.com\/specifications\/gss\/\">https:\/\/www.bluetooth.com\/specifications\/gss\/<\/a><\/li>\n<li>Device Properties\uff08\u8bbe\u5907\u5c5e\u6027\uff09\uff1a<a href=\"https:\/\/www.bluetooth.com\/specifications\/specs\/device-properties\/\">https:\/\/www.bluetooth.com\/specifications\/specs\/device-properties\/<\/a><\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E5%AD%A6%E4%B9%A0%E5%AE%9E%E8%B7%B5\"><\/span>\u5b66\u4e60\u5b9e\u8df5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"%E4%BF%A1%E9%81%93\"><\/span>\u4fe1\u9053<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5171 40 \u4e2a\u4fe1\u9053\uff0c0\u300112\u300139 \u4e3a\u5e7f\u64ad\u4fe1\u9053\uff0c\u5176\u5b83\u4e3a\u6570\u636e\u4fe1\u9053<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1751903111997.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1223px; --smush-placeholder-aspect-ratio: 1223\/803;\" \/><\/p>\n<p>\u6765\u6e90\uff1aCore Specification 4.2\uff0cBLUETOOTH SPECIFICATION Version 4.2 [Vol 6, Part B]\uff0c1.4.1 Advertising and Data Channel Indices\uff0c<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E6%89%AB%E6%8F%8F%E8%AE%BE%E5%A4%87\"><\/span>\u626b\u63cf\u8bbe\u5907<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-cpp\">#include &quot;Arduino.h&quot;\n\n#include &quot;BLEDevice.h&quot;\n#include &quot;BLEUtils.h&quot;\n#include &quot;BLEScan.h&quot;\n#include &quot;BLEAdvertisedDevice.h&quot;\n\nint scanTime = 5;  \/\/ \u626b\u63cf\u6301\u7eed\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u79d2\nBLEScan *pBLEScan = nullptr;\n\nclass MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks\n{\n    void onResult(BLEAdvertisedDevice advertisedDevice)\n    {\n        Serial.printf(&quot;\u53d1\u73b0\u7684\u8bbe\u5907\uff1a%s \\n&quot;, advertisedDevice.toString().c_str());\n    }\n};\n\nvoid setup()\n{\n    Serial.begin(115200);\n    Serial.println(&quot;\u5f00\u59cb\u626b\u63cf...&quot;);\n\n    BLEDevice::init(&quot;&quot;);\n    pBLEScan = BLEDevice::getScan();  \/\/ \u521b\u5efa\u65b0\u7684\u626b\u63cf\u5bf9\u8c61\n    pBLEScan-&gt;setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); \/\/ \u53d1\u73b0\u84dd\u7259\u8bbe\u5907\u65f6\u6267\u884c\u7684\u64cd\u4f5c\uff08\u56de\u8c03\u51fd\u6570\uff09\n    pBLEScan-&gt;setActiveScan(true);  \/\/ \u8bbe\u7f6e\u4e3b\u52a8\u626b\u63cf\uff08\u4e3b\u52a8\u626b\u63cf\u4f1a\u6d88\u8017\u66f4\u591a\u7535\u91cf\uff0c\u4f46\u7ed3\u679c\u8fd4\u56de\u66f4\u5feb\uff09\n    pBLEScan-&gt;setInterval(100); \/\/ \u4e24\u6b21\u626b\u63cf\u95f4\u9694\u7684\u65f6\u95f4\n    pBLEScan-&gt;setWindow(99);  \/\/ \u6bcf\u6b21\u626b\u63cf\u6301\u7eed\u7684\u65f6\u95f4\uff08\u5c0f\u4e8e\u6216\u7b49\u4e8e setInterval \u7684\u503c\uff09\n}\n\nvoid loop()\n{\n    \/\/ \u4e0b\u9762\u4ee3\u7801\u5faa\u73af\u6267\u884c\n    BLEScanResults foundDevices = pBLEScan-&gt;start(scanTime);\n    Serial.printf(&quot;\\n\u53d1\u73b0\u8bbe\u5907\u6570\u91cf:%d\\n&quot;, foundDevices.getCount());\n    pBLEScan-&gt;clearResults();  \/\/ \u6e05\u9664\u626b\u63cf\u7ed3\u679c\uff0c\u91ca\u653e\u5185\u5b58\n    delay(2000);\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1751793264664.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1649px; --smush-placeholder-aspect-ratio: 1649\/238;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E6%9C%8D%E5%8A%A1%E5%99%A8\"><\/span>\u670d\u52a1\u5668<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>BLE \u91c7\u7528\u201c\u670d\u52a1\u5668\uff08\u4ece\u673a\uff09-\u5ba2\u6237\u7aef\uff08\u4e3b\u673a\uff09\u201d\u7684\u5de5\u4f5c\u6a21\u5f0f\uff0cBLE \u4e2d\u53ef\u4ee5\u6dfb\u52a0\u591a\u4e2a\u670d\u52a1\uff0c\u6bcf\u4e2a\u670d\u52a1\u4e2d\u53ef\u4ee5\u6dfb\u52a0\u591a\u4e2a\u7279\u5f81\u503c\uff0c\u670d\u52a1\u5668\u7aef\u8bbe\u7f6e\u7279\u5f81\u503c\u7684\u8bfb\u5199\u5c5e\u6027\u3002\u4e3b\u673a\u8fde\u63a5\u5230\u4ece\u673a\uff0c\u53ef\u4ee5\u8bfb\u53d6\u5230\u7279\u5f81\u503c\uff0c\u4e00\u5b9a\u6761\u4ef6\u4e0b\u4e5f\u53ef\u4ee5\u4fee\u6539\u7279\u5f81\u503c\u3002<br \/>\n\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6bd4\u5982\u53ef\u4ee5\u76d1\u63a7\u5fc3\u7387\u7684\u624b\u73af\uff0c\u624b\u73af\u5c31\u662f\u670d\u52a1\u5668\uff0c\u624b\u673a\u5c31\u662f\u5ba2\u6237\u7aef\u3002\u9996\u6b21\u4f7f\u7528\u65f6\uff0c\u624b\u73af\u5e7f\u64ad\uff0c\u624b\u673a\u53ef\u4ee5\u626b\u63cf\u5230\u5e76\u8fdb\u884c\u8fde\u63a5\uff0c\u624b\u73af\u84dd\u7259\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5fc3\u7387\u670d\u52a1\uff0c\u670d\u52a1\u4e2d\u5305\u542b\u4e86\u4e00\u4e2a\u5fc3\u7387\u7279\u5f81\uff0c\u624b\u73af\u5c06\u6d4b\u91cf\u7684\u7ed3\u679c\u8bbe\u7f6e\u5230\u5fc3\u7387\u7279\u5f81\u7684\u503c\u91cc\uff0c\u624b\u673a\u8bfb\u53d6\u8fd9\u4e2a\u503c\u5c31\u80fd\u83b7\u53d6\u7ed3\u679c\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E8%87%AA%E5%AE%9A%E4%B9%89_UUID\"><\/span>\u81ea\u5b9a\u4e49 UUID<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-cpp\">#include &quot;Arduino.h&quot;\n\n#include &quot;BLEDevice.h&quot;\n#include &quot;BLEUtils.h&quot;\n#include &quot;BLEServer.h&quot;\n\n\/\/ \u53ef\u4f7f\u7528 https:\/\/www.uuidgenerator.net\/ \u6765\u751f\u6210\u552f\u4e00\u7684 UUID\n#define SERVICE_UUID &quot;412cf883-c8b3-427f-807c-4ff39fda9c1a&quot;        \/\/ \u81ea\u5b9a\u4e49\u670d\u52a1\u7684 UUID\n#define CHARACTERISTIC_UUID &quot;ab6c95dd-82d4-4529-8b7e-d7d16ed93e5a&quot; \/\/ \u81ea\u5b9a\u4e49\u7279\u5f81\u7684 UUID\n\nvoid setup()\n{\n    Serial.begin(115200);\n    Serial.println(&quot;\u5f00\u59cb\u521d\u59cb\u5316 BLE\uff01&quot;);\n\n    \/\/ \u521d\u59cb\u5316 BLE \u8bbe\u5907\uff0c\u8bbe\u7f6e\u8bbe\u5907\u540d\u79f0\n    BLEDevice::init(&quot;ESP32 BLE \u6d4b\u8bd5&quot;);\n\n    \/\/ \u521b\u5efa BLE \u670d\u52a1\u5668\n    BLEServer *pServer = BLEDevice::createServer();\n\n    \/\/ \u521b\u5efa BLE \u670d\u52a1\uff0c\u5e76\u6307\u5b9a UUID\n    BLEService *pService = pServer-&gt;createService(SERVICE_UUID);\n\n    \/\/ \u521b\u5efa BLE \u7279\u5f81\uff08characteristic\uff09\uff0c\u652f\u6301\u8bfb\u53d6\u548c\u5199\u5165\u6743\u9650\n    BLECharacteristic *pCharacteristic = pService-&gt;createCharacteristic(\n        CHARACTERISTIC_UUID,\n        BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);\n\n    \/\/ \u8bbe\u7f6e\u7279\u5f81\u503c\n    pCharacteristic-&gt;setValue(&quot;IYATT-yx BLE Test&quot;);\n\n    \/\/ \u542f\u52a8\u670d\u52a1\n    pService-&gt;start();\n\n    \/\/ \u83b7\u53d6 BLE \u5e7f\u64ad\u5bf9\u8c61\n    BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();\n\n    \/\/ \u6dfb\u52a0\u670d\u52a1 UUID \u5230\u5e7f\u64ad\u5305\u4e2d\n    pAdvertising-&gt;addServiceUUID(SERVICE_UUID);\n\n    \/\/ \u8bbe\u7f6e\u626b\u63cf\u54cd\u5e94\u4e3a true\uff0c\u53ef\u4ee5\u8ba9\u624b\u673a\u626b\u63cf\u65f6\u663e\u793a\u66f4\u591a\u8bbe\u5907\u4fe1\u606f\n    pAdvertising-&gt;setScanResponse(true);\n\n    \/\/ \u5f00\u59cb\u5e7f\u64ad\n    BLEDevice::startAdvertising();\n    Serial.println(&quot;\u7279\u5f81\u5df2\u5b9a\u4e49\uff01\u73b0\u5728\u53ef\u4ee5\u7528\u624b\u673a\u8bfb\u53d6\u5b83\u4e86\uff01&quot;);\n}\n\nvoid loop()\n{\n    delay(2000);\n}<\/code><\/pre>\n<p>\u4e0a\u4f20\u540e\u6d4b\u8bd5\uff0cnRF Connect \u4e2d\u53ef\u4ee5\u641c\u5230 ESP32 \u7684\u84dd\u7259\uff0c\u70b9\u51fb CONNECT \u8fde\u63a5<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752164660630.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 405px; --smush-placeholder-aspect-ratio: 405\/850;\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u6709\u4e2a Unknown Service\uff08\u672a\u77e5\u670d\u52a1\uff09\uff0cUUID \u548c\u4e0a\u9762\u4ee3\u7801\u8bbe\u7f6e\u7684\u4e00\u81f4\uff0c\u70b9\u5f00\u53ef\u4ee5\u770b\u5230\u6709\u4e2a Unknown Characteristic\uff08\u672a\u77e5\u7279\u5f81\uff09\uff0cUUID \u548c\u8bbe\u7f6e\u7684\u4e5f\u662f\u4e00\u81f4\u7684\u3002\u70b9\u51fb\u4e0b\u8f7d\u56fe\u6807\uff0c\u53ef\u4ee5\u770b\u5230 Value\uff08\u503c\uff09\u540e\u7684\u6587\u672c\u4e5f\u662f\u8bbe\u7f6e\u7684 \u201cIYATT-yx BLE Test\u201d<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752164707662.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 401px; --smush-placeholder-aspect-ratio: 401\/601;\" \/><\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E4%BA%A4%E4%BA%92\"><\/span>\u4ea4\u4e92<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u8bbe\u7f6e\u4e86\u7279\u5f81\u4e3a\u53ef\u8bfb\u5199\u7684\uff0c\u70b9\u51fb\u4e0a\u4f20\u6309\u94ae<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752448490282.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 577px; --smush-placeholder-aspect-ratio: 577\/799;\" \/><\/p>\n<p>\u5c06\u53d1\u9001\u503c\u7c7b\u578b\u6539\u4e3a TEXT (UTF-8)\uff0c\u53d1\u9001\u5185\u5bb9\u4e3a hello<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752448588525.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 575px; --smush-placeholder-aspect-ratio: 575\/870;\" \/><\/p>\n<p>\u7136\u540e\u53ef\u4ee5\u770b\u5230\u8bfb\u53d6\u7684\u503c\u4e5f\u6539\u4e3a\u4e86 hello<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752448646337.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 565px; --smush-placeholder-aspect-ratio: 565\/710;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E9%81%B5%E5%BE%AA_Assigned_Numbers_%E7%9A%84_UUID\"><\/span>\u9075\u5faa Assigned Numbers \u7684 UUID<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u53ef\u4ee5\u6ce8\u610f\u5230\u4e0a\u9762\u7684\u670d\u52a1\u548c\u7279\u5f81\u90fd\u662f\u672a\u77e5\uff0c\u56e0\u4e3a\u8fd9\u662f\u81ea\u5b9a\u4e49\u7684 UUID\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u7f51\u7ad9\u751f\u6210\uff1a<a href=\"https:\/\/www.uuidgenerator.net\/\">https:\/\/www.uuidgenerator.net\/<\/a><br \/>\n\u540c\u65f6\u84dd\u7259\u5728 Assigned Numbers \u4e2d\u4e5f\u5b9a\u4e49\u4e86\u6807\u51c6\u7684 UUID\uff0cGATT Specification Supplement \u4e2d\u5b9a\u4e49\u4e86\u7279\u5f81\u503c\u7684\u6570\u636e\u683c\u5f0f\u3002<br \/>\n\u6bd4\u5982\u8fd9\u91cc\u67e5\u9605 Assigned Numbers \u53ef\u77e5\u5fc3\u7387\u670d\u52a1\u4e3a 0x180D<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752166255293.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 646px; --smush-placeholder-aspect-ratio: 646\/592;\" \/><br \/>\n\u67e5 Assigned Numbers \u53ef\u77e5\u5fc3\u7387\u6d4b\u91cf\u7279\u5f81\u4e3a 0x2A37<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752166321821.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 705px; --smush-placeholder-aspect-ratio: 705\/155;\" \/><\/p>\n<p>\u5206\u522b\u8bbe\u7f6e\u8fdb\u4ee3\u7801\u91cc<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752166376659.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 493px; --smush-placeholder-aspect-ratio: 493\/310;\" \/><\/p>\n<p>\u67e5 GATT Specification Supplement \u53ef\u77e5\u5fc3\u7387\u6d4b\u91cf\u7684\u6570\u636e\u683c\u5f0f<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752398054938.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 886px; --smush-placeholder-aspect-ratio: 886\/387;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752398100707.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 635px; --smush-placeholder-aspect-ratio: 635\/989;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752398111862.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 634px; --smush-placeholder-aspect-ratio: 634\/222;\" \/><\/p>\n<p>\u4ee3\u7801\u91cc\u8bbe\u7f6e\u6570\u636e<\/p>\n<pre><code class=\"language-cpp\">    \/\/ \u8bbe\u7f6e\u5fc3\u7387\u503c\n\n    \/\/ \u8bbe\u7f6e\u6807\u5fd7\n    \/\/ \u4f4d 0 = 0\uff0c\u4f7f\u7528 uint8 \u8868\u793a\u5fc3\u7387\n    \/\/ \u4f4d 1 = 1\uff0c\u68c0\u6d4b\u5230\u4f20\u611f\u5668\u63a5\u89e6\u76ae\u80a4\n    \/\/ \u4f4d 2 = 1\uff0c\u4f20\u611f\u5668\u652f\u6301\u63a5\u89e6\u68c0\u6d4b\uff0c\u82e5\u503c\u4e3a 0\uff0c\u5219\u4f4d 1 \u6570\u636e\u65e0\u6548\n    \/\/ \u4f4d 3 = 1\uff0c\u5305\u542b\u80fd\u91cf\u6d88\u8017\u503c\n    \/\/ \u4f4d 4 = 1\uff0c\u5305\u542b RR \u95f4\u671f\u503c\uff08\u76f8\u90bb\u4e24\u6b21\u5fc3\u8df3\u7684\u95f4\u9694\uff09\n    \/\/ \u4f4d 5-7 \u4fdd\u7559\u7ed9\u672a\u6765\u4f7f\u7528\uff0c\u76ee\u524d\u65e0\u610f\u4e49\n    uint8_t flags = 0b00011110;\n\n    \/\/ \u76f8\u5173\u6570\u636e\n    uint8_t heartRate8 = 72; \/\/ \u5fc3\u7387\u503c 72bpm\n    uint16_t energyExpended = 120; \/\/ \u80fd\u91cf\u6d88\u8017 120j\n    uint16_t rrInterval[] = {1024, 980}; \/\/ \u4e24\u4e2a\u5fc3\u8df3\u95f4\u9694\u503c\uff0c\u5355\u4f4d\u4e3a 1\/1024s\uff080.9765625ms\uff09\n\n    \/\/ \u6784\u5efa\u6570\u636e\u5305\n    std::string hrmData = &quot;&quot;;\n    hrmData += (char)flags;\n    hrmData += (char)heartRate8;\n    \/\/ 16\u4f4d\u7684\u6570\u636e\u8981\u62c6\u62102\u4e2a8\u4f4d\u6570\u636e\uff0c\u4e14\u6309\u5c0f\u7aef\u5b57\u8282\u5e8f\u5b58\u50a8\n    hrmData += (char)(energyExpended &amp; 0xff);\n    hrmData += (char)((energyExpended &gt;&gt; 8) &amp; 0xff);\n\n    for (int i = 0; i &lt; sizeof(rrInterval) \/ sizeof(rrInterval[0]); ++i)\n    {\n        hrmData += (char)(rrInterval[i] &amp; 0xff);\n        hrmData += (char)((rrInterval[i] &gt;&gt; 8) &amp; 0xff);\n    }\n\n    \/\/ \u8bbe\u7f6e\u7279\u5f81\u503c\n    pCharacteristic-&gt;setValue(hrmData);<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752402562282.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 758px; --smush-placeholder-aspect-ratio: 758\/857;\" \/><\/p>\n<p>\u8fde\u63a5\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u770b\u5230\u73b0\u5728\u4e0d\u4f1a\u663e\u793a\u672a\u77e5\u670d\u52a1\/\u7279\u5f81\u4e86\uff0cUUID \u4f7f\u7528\u6807\u51c6\u503c\uff0c\u5c31\u53ef\u4ee5\u8bc6\u522b\u4e3a\u6307\u5b9a\u7684\u670d\u52a1\/\u7279\u5f81\u3002\u4e14\u6570\u636e\u548c\u4ee3\u7801\u91cc\u4e00\u81f4\u3002\u5176\u4e2d\u201cContact is Detected\u201d\u8868\u793a\u68c0\u6d4b\u5230\u63a5\u89e6<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752401878408.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 403px; --smush-placeholder-aspect-ratio: 403\/584;\" \/><\/p>\n<p>\u5c06 flags \u91cc\u4f4d 1 \u6539\u4e3a 0\uff0c\u53ef\u4ee5\u770b\u5230\u65f6\u6ca1\u6709\u68c0\u6d4b\u5230\u4e86<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752402105496.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 386px; --smush-placeholder-aspect-ratio: 386\/237;\" \/><\/p>\n<p>\u628a flags \u91cc\u4f4d 2 \u6539\u4e3a 0\uff0c\u53ef\u4ee5\u770b\u5230\u73b0\u5728\u662f\u4e0d\u652f\u6301\u63a5\u89e6\u4f20\u611f\u5668<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/07\/image-1752402321425.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 387px; --smush-placeholder-aspect-ratio: 387\/243;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883 VScode\uff1a 1.101.2 PlatformIO\uff1aCore 6.1.18\uff0cHome 3.3.4  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,603,589,604,647,599],"tags":[],"class_list":["post-20699","post","type-post","status-publish","format-standard","hentry","category-all","category-arduino","category-c-c","category-esp32","category-platformio","category-599"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/20699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20699"}],"version-history":[{"count":24,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/20699\/revisions"}],"predecessor-version":[{"id":20893,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/20699\/revisions\/20893"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}