{"id":25081,"date":"2026-07-26T20:31:53","date_gmt":"2026-07-26T12:31:53","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=25081"},"modified":"2026-07-26T21:31:16","modified_gmt":"2026-07-26T13:31:16","slug":"%e5%9f%ba%e4%ba%8e-esp32-wroom-32-%e5%ae%9e%e8%b7%b5-ibeacon-%e8%93%9d%e7%89%99%e4%bf%a1%e6%a0%87-platformio","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=25081","title":{"rendered":"\u57fa\u4e8e ESP32-WROOM-32 \u5b9e\u8df5 iBeacon \u84dd\u7259\u4fe1\u6807 \u2013 PlatformIO"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 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=25081\/#%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=25081\/#%E5%AE%9E%E8%B7%B5\" >\u5b9e\u8df5<\/a><\/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>ESP32-WROOM-32<\/li>\n<li>PlatformIO IDE 3.3.4<\/li>\n<li>PlatformIO Core 6.1.19<\/li>\n<li>pioarduino platform-espressif32 55.03.311\uff08Arduino Release v3.3.11 based on ESP-IDF v5.5.5\uff09<\/li>\n<\/ul>\n<p>platformio.ini<\/p>\n<pre><code class=\"language-ini\">[env:esp32dev]\nplatform = https:\/\/github.com\/pioarduino\/platform-espressif32\/releases\/download\/55.03.311\/platform-espressif32.zip\nboard = esp32dev\nframework = arduino\nmonitor_speed = 115200<\/code><\/pre>\n<h1><span class=\"ez-toc-section\" id=\"%E5%AE%9E%E8%B7%B5\"><\/span>\u5b9e\u8df5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u6e90\u7801\u53c2\u8003\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/espressif\/arduino-esp32\/blob\/3.3.11\/libraries\/BLE\/examples\/iBeacon\/iBeacon.ino\">https:\/\/github.com\/espressif\/arduino-esp32\/blob\/3.3.11\/libraries\/BLE\/examples\/iBeacon\/iBeacon.ino<\/a><\/p>\n<p>iBeacon \u901a\u5e38\u7528\u4e8e\u5ba4\u5185\u5b9a\u4f4d\u3001\u6253\u5f00\u8003\u52e4\u3001APP\u8d34\u8fd1\u611f\u77e5<\/p>\n<pre><code class=\"language-cpp\">\/*\n    \u3010\u7eaf\u7cb9 iBeacon \u6781\u7b80\u5e7f\u64ad\u793a\u4f8b\u3011\n\n    \u539f\u7406\u8bf4\u660e\uff1a\n    iBeacon \u662f Apple \u5236\u5b9a\u7684\u4e00\u79cd\u57fa\u4e8e BLE \u5e7f\u64ad\u5305\u534f\u8bae\u7684\u201c\u4fe1\u6807\u201d\u6807\u51c6\u3002\n    \u8bbe\u5907\u53ea\u9700\u8981\u6301\u7eed\u5bf9\u5916\u53d1\u9001\u7279\u5b9a\u683c\u5f0f\u7684\u5e7f\u64ad\u6570\u636e\u5305\uff08\u5305\u542b Manufacturer Data \u5382\u5546\u6570\u636e\uff09\uff0c\n    \u4e0d\u9700\u8981\u5efa\u7acb\u4efb\u4f55\u8fde\u63a5\uff0c\u4e5f\u4e0d\u9700\u8981\u521b\u5efa GATT \u670d\u52a1\u6216\u7279\u5f81\u503c\u3002\n*\/\n\n#include &lt;Arduino.h&gt;\n#include &lt;BLEDevice.h&gt;\n#include &lt;BLEServer.h&gt;\n#include &lt;BLEUtils.h&gt;\n#include &lt;BLEBeacon.h&gt; \/\/ ESP32 \u5b98\u65b9\u7684 iBeacon \u6570\u636e\u7ed3\u6784\u5c01\u88c5\u5e93\n\n\/\/ 1. \u5b9a\u4e49\u8bbe\u5907\u540d\u79f0\n#define DEVICE_NAME &quot;ESP32_iBeacon&quot;\n\n\/\/ 2. \u5b9a\u4e49 iBeacon \u7684\u6838\u5fc3\u6807\u8bc6\u7b26\n\/\/ Proximity UUID\uff1a\u7528\u6765\u6807\u8bc6\u540c\u4e00\u7ec4\u6216\u540c\u4e00\u673a\u6784\u7684\u4fe1\u6807\uff08\u5982\u67d0\u4e2a\u5546\u573a\u3001\u67d0\u4e2a\u56ed\u533a\uff09\n#define BEACON_UUID &quot;2D7A9F0C-E0E8-4CC9-A71B-A21DB2D034A1&quot;\n\n\/\/ Major &amp; Minor\uff1a16\u4f4d\u65e0\u7b26\u53f7\u6574\u6570 (0 ~ 65535)\uff0c\u7528\u4e8e\u7ec6\u5206\u8bbe\u5907\n#define BEACON_MAJOR 5  \/\/ \u901a\u5e38\u8868\u793a\u5927\u533a\u57df\/\u697c\u5c42\uff08\u5982\uff1a5\u53f7\u697c\uff09\n#define BEACON_MINOR 88 \/\/ \u901a\u5e38\u8868\u793a\u5177\u4f53\u4f4d\u7f6e\/\u623f\u95f4\uff08\u5982\uff1a88\u53f7\u623f\u95f4\uff09\n\nvoid setup()\n{\n    Serial.begin(115200);\n    Serial.println(&quot;\u6b63\u5728\u521d\u59cb\u5316 ESP32 iBeacon...&quot;);\n\n    \/\/ 1. \u521d\u59cb\u5316 BLE \u8bbe\u5907\u5f15\u64ce\n    BLEDevice::init(DEVICE_NAME);\n\n    \/\/ 2. \u6784\u5efa iBeacon \u683c\u5f0f\u7684\u6570\u636e\u7ed3\u6784\n    BLEBeacon myBeacon;\n    myBeacon.setManufacturerId(0x4C00);              \/\/ 0x4C00 \u4ee3\u8868 Apple \u516c\u53f8 ID\uff08iBeacon \u534f\u8bae\u6807\u51c6\u5f3a\u5236\u8981\u6c42\uff09\n    myBeacon.setMajor(BEACON_MAJOR);                 \/\/ \u8bbe\u7f6e Major \u6807\u8bc6\n    myBeacon.setMinor(BEACON_MINOR);                 \/\/ \u8bbe\u7f6e Minor \u6807\u8bc6\n    myBeacon.setSignalPower(0xC5);                   \/\/ \u8bbe\u7f6e RSSI \u8865\u507f\u503c\/\u6d4b\u8ddd\u53c2\u8003\u529f\u7387\uff080xC5 \u5373 -59dBm\uff0c\u7528\u4e8e\u5728 1 \u7c73\u5904\u4f30\u7b97\u8ddd\u79bb\uff09\n    myBeacon.setProximityUUID(BLEUUID(BEACON_UUID)); \/\/ \u8bbe\u7f6e 128\u4f4d\u7684 UUID\n\n    \/\/ 3. \u6784\u5efa BLE \u5e7f\u64ad\u5305 (Advertisement Data)\n    BLEAdvertisementData advertisementData;\n\n    \/*\n       \u8bbe\u7f6e 0x01 Flags \u6807\u5fd7\u4f4d\uff1a\n       0x1A \u5373\u4e8c\u8fdb\u5236 0001 1010\uff1a\n       - Bit 1 (0x02): LE General Discoverable Mode (\u901a\u7528\u53ef\u53d1\u73b0\u6a21\u5f0f)\n       - Bit 3 (0x08): BR\/EDR Not Supported (\u4e0d\u652f\u6301\u4f20\u7edf\u84dd\u7259\uff0c\u4ec5\u652f\u6301\u4f4e\u529f\u8017\u84dd\u7259)\n       - Bit 4 (0x10): LE only for Controller &amp; Host\n    *\/\n    advertisementData.setFlags(0x1A);\n\n    \/\/ \u5c06\u6253\u5305\u597d\u7684 iBeacon \u6570\u636e\uff08\u683c\u5f0f\u5316\u7684 25 \u5b57\u8282 payload\uff09\u585e\u8fdb\u5e7f\u64ad\u5305\u7684\u5382\u5546\u6570\u636e\u6bb5\u4e2d\n    advertisementData.setManufacturerData(myBeacon.getData());\n\n    \/\/ 4. \u83b7\u53d6\u5e7f\u64ad\u7ba1\u7406\u5668\u5e76\u5e94\u7528\u914d\u7f6e\n    BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();\n    pAdvertising-&gt;setAdvertisementData(advertisementData);\n\n    \/\/ 5. \u5f00\u542f\u5e7f\u64ad\n    pAdvertising-&gt;setScanResponse(true); \/\/ \u5141\u8bb8\u54cd\u5e94\u626b\u63cf\u8bf7\u6c42\uff08\u63d0\u9ad8\u90e8\u5206\u8bbe\u5907\u7684\u53d1\u73b0\u6982\u7387\uff09\n    pAdvertising-&gt;setMinPreferred(0x06); \/\/ \u5e2e\u52a9 iOS \u6539\u5584\u8fde\u63a5\u4e0e\u5e7f\u64ad\u8bc6\u522b\u901f\u5ea6\n    pAdvertising-&gt;setMinPreferred(0x12);\n    pAdvertising-&gt;start();\n\n    Serial.println(&quot;iBeacon \u5e7f\u64ad\u5df2\u542f\u52a8\uff01\u624b\u673a\/\u8c03\u8bd5\u5de5\u5177\u73b0\u5728\u53ef\u4ee5\u626b\u63cf\u5230\u4e86\u3002&quot;);\n}\n\nvoid loop()\n{\n    \/\/ iBeacon \u53ea\u9700\u8981\u5728\u540e\u53f0\u7531\u84dd\u7259\u786c\u4ef6\u81ea\u52a8\u6301\u7eed\u53d1\u5305\n    \/\/ \u4e3b\u5faa\u73af\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u64cd\u4f5c\uff0c\u76f4\u63a5\u4f11\u7720 10 \u79d2\uff0c\u6781\u5927\u5730\u964d\u4f4e CPU \u8d44\u6e90\u6d88\u8017\n    delay(10000);\n}<\/code><\/pre>\n<p>iBeacon \u5c31\u662f\u7528\u4e8e\u5e7f\u64ad\u4fe1\u6807\u7684\uff0c\u6bd4\u5982\u4e00\u4e2a\u5546\u573a\u6709 5 \u5c42\uff0c\u6bcf\u5c42\u6709 100 \u4e2a\u95e8\u5e97\uff0c\u6bcf\u4e2a\u95e8\u5e97\u90fd\u6709\u4e00\u4e2a iBeacon \u4fe1\u53f7\u3002<br \/>\n\u53ef\u4ee5\u5148\u89c4\u5b9a Major \u7528\u4f5c\u697c\u5c42\uff0cMinor \u7528\u4f5c\u5c42\u5185\u95e8\u724c\u53f7\uff0c\u201cRSSI at 1m: -59dBm\u201d \u5c31\u662f\u8bbe\u5b9a\u7684\u5728 1m \u5904\u65e0\u906e\u6321\u7684\u4fe1\u53f7\u5f3a\u5ea6\u3002<br \/>\n\u8bbe\u5907\u63a5\u6536\u5230 iBeacon \u5c31\u53ef\u4ee5\u6839\u636e\u7ea6\u5b9a\u7684\u5185\u5bb9\u7b97\u51fa\u5f53\u524d\u6700\u9760\u8fd1\u54ea\u4e2a\u95e8\u5e97\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2026\/07\/image-1785068214777.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 411px; --smush-placeholder-aspect-ratio: 411\/435;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883 ESP32-WROOM-32 PlatformIO IDE 3.3.4 PlatformIO Cor [&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":null,"zakra_menu_item_active_color":null,"zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,603,589,604,647,599],"tags":[1503,1467,2203,2204,1468],"class_list":["post-25081","post","type-post","status-publish","format-standard","hentry","category-all","category-arduino","category-c-c","category-esp32","category-platformio","category-599","tag-ble","tag-esp32","tag-ibeacon","tag-2204","tag-1468"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/25081","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=25081"}],"version-history":[{"count":4,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/25081\/revisions"}],"predecessor-version":[{"id":25087,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/25081\/revisions\/25087"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}