{"id":25093,"date":"2026-07-26T22:42:35","date_gmt":"2026-07-26T14:42:35","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=25093"},"modified":"2026-07-26T23:02:03","modified_gmt":"2026-07-26T15:02:03","slug":"%e5%9f%ba%e4%ba%8e-esp32-wroom-32-%e5%ae%9e%e8%b7%b5-eddystonetlm_beacon-%e9%81%a5%e6%b5%8b%ef%bc%88%e5%b9%bf%e6%92%ad%e7%94%b5%e5%8e%8b%e3%80%81%e6%b8%a9%e5%ba%a6%e3%80%81%e8%bf%90%e8%a1%8c%e6%97%b6","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=25093","title":{"rendered":"\u57fa\u4e8e ESP32-WROOM-32 \u5b9e\u8df5 EddystoneTLM_Beacon \u9065\u6d4b\uff08\u5e7f\u64ad\u7535\u538b\u3001\u6e29\u5ea6\u3001\u8fd0\u884c\u65f6\u95f4\uff09 \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=25093\/#%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=25093\/#%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\/EddystoneTLM_Beacon\/EddystoneTLM_Beacon.ino\">https:\/\/github.com\/espressif\/arduino-esp32\/blob\/3.3.11\/libraries\/BLE\/examples\/EddystoneTLM_Beacon\/EddystoneTLM_Beacon.ino<\/a><\/p>\n<p>EddystoneTLM_Beacon \u662f\u8c37\u6b4c\u8bbe\u8ba1\u7684\uff0c\u7528\u4e8e\u5e7f\u64ad\u8bbe\u5907\u7684\u7535\u538b\u3001\u6e29\u5ea6\u548c\u8fd0\u884c\u65f6\u95f4\u3002\u4e00\u822c\u662f\u8fd0\u7ef4\u4eba\u5458\u67e5\u770b\u8bbe\u5907\u5065\u5eb7\u72b6\u6001\u7684\u60c5\u5883\u4e0b\u4f1a\u4f7f\u7528\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u6848\u4f8b\u4f1a\u5e7f\u64ad\u7535\u538b\u548c\u6e29\u5ea6\uff0c\u6e29\u5ea6\u90e8\u5206\u6211\u5bf9\u53c2\u8003\u6848\u4f8b\u505a\u4e86\u4fee\u6539\uff0c\u4f1a\u8bfb\u53d6\u771f\u5b9e\u7684\u82af\u7247\u4f20\u611f\u5668\u6e29\u5ea6\uff0c\u800c\u4e0d\u662f\u968f\u673a\u6570\u3002<\/p>\n<pre><code class=\"language-cpp\">\/*\n   ESP32-WROOM-32 Eddystone-TLM \u9065\u6d4b\u4fe1\u6807\uff08\u4f7f\u7528\u771f\u5b9e\u7247\u4e0a\u6e29\u5ea6\uff09\n\n   \u6570\u636e\u8bf4\u660e\uff1a\n   - \u6e29\u5ea6\uff1a\u63d0\u53d6 ESP32 \u5185\u90e8\u6676\u5706\u7ed3\u6e29\uff0c\u5e76\u8f6c\u6362\u88c5\u8f7d\u5230 TLM 8.8 \u5b9a\u70b9\u6570\u683c\u5f0f\u4e2d\n   - \u7535\u6c60\uff1a\u6a21\u62df\u7535\u6c60\u7535\u538b\uff08\u5982\u786c\u4ef6\u8fde\u63a5\u4e86 VBAT \u5206\u538b ADC\uff0c\u53ef\u66ff\u6362\u4e3a\u771f\u5b9e\u91c7\u6837\u503c\uff09\n*\/\n\n#include &quot;sys\/time.h&quot;\n#include &lt;Arduino.h&gt;\n\n#include &quot;BLEDevice.h&quot;\n#include &quot;BLEUtils.h&quot;\n#include &quot;BLEBeacon.h&quot;\n#include &quot;BLEAdvertising.h&quot;\n#include &quot;BLEEddystoneTLM.h&quot;\n#include &quot;esp_sleep.h&quot;\n\n\/\/ 1. C \u8bed\u8a00\u5916\u90e8\u58f0\u660e\uff1a\u5f15\u7528 ESP32-WROOM-32 \u5e95\u5c42\u7247\u4e0a\u6e29\u5ea6\u4f20\u611f\u5668\u63a5\u53e3\n#ifdef __cplusplus\nextern &quot;C&quot;\n{\n#endif\n    uint8_t temprature_sens_read();\n#ifdef __cplusplus\n}\n#endif\n\n#define GPIO_DEEP_SLEEP_DURATION 2 \/\/ \u5524\u9192\u540e\u5e7f\u64ad 10 \u79d2\uff0c\u4f11\u7720 2 \u79d2\n#define BEACON_POWER ESP_PWR_LVL_N12\n\nRTC_DATA_ATTR static time_t last;        \/\/ RTC \u6162\u901f\u5185\u5b58\uff1a\u4fdd\u5b58\u4e0a\u4e00\u6b21\u5524\u9192\u7684 Unix \u65f6\u95f4\u6233\nRTC_DATA_ATTR static uint32_t bootcount; \/\/ RTC \u6162\u901f\u5185\u5b58\uff1a\u4fdd\u5b58\u8bbe\u5907\u5524\u9192\u603b\u6b21\u6570\n\nBLEAdvertising *pAdvertising;\nstruct timeval nowTimeStruct;\n\n\/**\n * @brief \u8bfb\u53d6\u771f\u5b9e\u82af\u7247\u6e29\u5ea6\u5e76\u6784\u5efa Eddystone-TLM \u9065\u6d4b\u5e7f\u64ad\u5e27\n *\/\nvoid setBeacon()\n{\n    BLEEddystoneTLM EddystoneTLM;\n\n    \/\/ -------------------------------------------------------------\n    \/\/ \u8bfb\u53d6 ESP32 \u82af\u7247\u5185\u90e8\u4f20\u611f\u5668\n    \/\/ -------------------------------------------------------------\n    uint8_t raw_temp = temprature_sens_read();     \/\/ \u83b7\u53d6\u539f\u59cb ADC \u91c7\u6837\u503c\n    float chip_temp_c = (raw_temp - 32.0f) \/ 1.8f; \/\/ \u534e\u6c0f\u5ea6\u8f6c\u6362\u4e3a\u6444\u6c0f\u5ea6 (\u00b0C)\n\n    \/\/ \u5c06\u6444\u6c0f\u5ea6\u8bbe\u7f6e\u5230 TLM \u7c7b\u4e2d\uff0c\u5e95\u5c42\u4f1a\u81ea\u52a8\u7f16\u7801\u4e3a Eddystone \u8981\u6c42\u7684 8.8 \u5b9a\u70b9\u6570\n    EddystoneTLM.setTemp(chip_temp_c);\n\n    \/\/ \u6a21\u62df\u8bbe\u5b9a\u7cfb\u7edf\u7535\u538b\uff08\u5355\u4f4d\uff1amV\uff0c\u5982 3300mV = 3.3V\uff09\n    \/\/ \u540e\u7eed\u82e5\u6709\u786c\u4ef6\u5206\u538b\u7535\u8def\u63a5\u5165 ADC\uff0c\u53ef\u5728\u6b64\u66ff\u6362\u4e3a\u771f\u5b9e\u7684\u7535\u6c60\u8bfb\u53d6\u6570\u503c\n    EddystoneTLM.setVolt((uint16_t)random(3200, 3300));\n\n    \/\/ \u4e32\u53e3\u8c03\u8bd5\u8f93\u51fa\n    Serial.printf(&quot;TSENS Raw Value : %u\\n&quot;, raw_temp);\n    Serial.printf(&quot;Real Chip Temp  : %.2f \u00b0C\\n&quot;, EddystoneTLM.getTemp());\n    Serial.printf(&quot;TLM 8.8 Format  : 0x%04X\\n&quot;, EddystoneTLM.getRawTemp());\n    Serial.printf(&quot;Battery Voltage : %u mV\\n&quot;, EddystoneTLM.getVolt());\n\n    \/\/ -------------------------------------------------------------\n    \/\/ \u6253\u5305\u5e7f\u64ad\u6570\u636e\u5305\n    \/\/ -------------------------------------------------------------\n    BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();\n    BLEAdvertisementData oScanResponseData = BLEAdvertisementData();\n\n    \/\/ \u5c06 TLM \u8d1f\u8f7d\u88c5\u8f7d\u81f3 Service Data \u4e2d\uff0c\u6302\u8f7d Google \u4e13\u7528\u7684 0xFEAA 16\u4f4d\u77ed UUID\n    oScanResponseData.setServiceData(\n        BLEUUID((uint16_t)0xFEAA),\n        String(EddystoneTLM.getData().c_str(), EddystoneTLM.getData().length()));\n\n    oAdvertisementData.setName(&quot;ESP32 TLM Beacon&quot;);\n\n    pAdvertising-&gt;setAdvertisementData(oAdvertisementData);\n    pAdvertising-&gt;setScanResponseData(oScanResponseData);\n}\n\nvoid setup()\n{\n    Serial.begin(115200);\n    gettimeofday(&amp;nowTimeStruct, NULL);\n\n    Serial.printf(&quot;\\n=========================================\\n&quot;);\n    Serial.printf(&quot;Starting ESP32 TLM Beacon (BootCount: %&quot; PRIu32 &quot;)\\n&quot;, bootcount++);\n    Serial.printf(&quot;Time since last boot: %&quot; PRIu32 &quot;s\\n&quot;, (uint32_t)(nowTimeStruct.tv_sec - last));\n    Serial.printf(&quot;=========================================\\n&quot;);\n\n    last = nowTimeStruct.tv_sec;\n\n    \/\/ \u521d\u59cb\u5316 BLE \u5f15\u64ce\u4e0e\u8bbe\u7f6e\u786c\u4ef6\u53d1\u5c04\u529f\u7387\n    BLEDevice::init(&quot;TLMBeacon&quot;);\n    BLEDevice::setPower(BEACON_POWER);\n\n    pAdvertising = BLEDevice::getAdvertising();\n\n    \/\/ \u88c5\u8f7d\u9065\u6d4b\u6570\u636e\n    setBeacon();\n\n    \/\/ \u5f00\u542f\u5e7f\u64ad\u5e76\u7ef4\u6301 10 \u79d2\n    pAdvertising-&gt;start();\n    Serial.println(&quot;Advertising TLM data for 10s...&quot;);\n    delay(10000);\n\n    \/\/ \u505c\u6b62\u5e7f\u64ad\u5e76\u8fdb\u5165 Deep Sleep\n    pAdvertising-&gt;stop();\n    Serial.println(&quot;Entering Deep Sleep...&quot;);\n    esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);\n}\n\nvoid loop()\n{\n    \/\/ Deep Sleep \u5524\u9192\u540e\u82af\u7247\u76f4\u63a5\u590d\u4f4d\u91cd\u8d70 setup()\uff0c\u4e0d\u4f1a\u6267\u884c loop\n}<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u5b57\u6bb5\u540d\u79f0<\/th>\n<th style=\"text-align: center;\">\u5b57\u8282\u5927\u5c0f<\/th>\n<th style=\"text-align: left;\">\u8bf4\u660e\u4e0e\u683c\u5f0f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><strong>Frame Type<\/strong> (\u7c7b\u578b)<\/td>\n<td style=\"text-align: center;\">1 \u5b57\u8282<\/td>\n<td style=\"text-align: left;\">\u56fa\u5b9a\u4e3a <code>0x20<\/code>\uff0c\u7528\u4e8e\u6807\u8bc6\u8be5\u5e7f\u64ad\u5305\u4e3a TLM \u9065\u6d4b\u5e27\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>VERSION<\/strong> (\u7248\u672c)<\/td>\n<td style=\"text-align: center;\">1 \u5b57\u8282<\/td>\n<td style=\"text-align: left;\">\u56fa\u5b9a\u4e3a <code>0x00<\/code>\uff08\u5f53\u524d\u534f\u8bae\u7248\u672c\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>VBATT<\/strong> (\u7535\u6c60\u7535\u538b)<\/td>\n<td style=\"text-align: center;\">2 \u5b57\u8282<\/td>\n<td style=\"text-align: left;\">\u65e0\u7b26\u53f7 16 \u4f4d\u6574\u6570\uff0c\u5355\u4f4d\u4e3a\u6beb\u4f0f\uff08mV\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>TEMP<\/strong> (\u6e29\u5ea6)<\/td>\n<td style=\"text-align: center;\">2 \u5b57\u8282<\/td>\n<td style=\"text-align: left;\">\u5e26\u7b26\u53f7\u7684 8.8 \u5b9a\u70b9\u6570\u683c\u5f0f\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>ADV_CNT<\/strong> (\u5e7f\u64ad\u8ba1\u6570\u5668)<\/td>\n<td style=\"text-align: center;\">4 \u5b57\u8282<\/td>\n<td style=\"text-align: left;\">\u81ea\u8bbe\u5907\u4e0a\u7535\u6216\u91cd\u542f\u4ee5\u6765\uff0c\u5df2\u53d1\u9001\u7684\u5e7f\u64ad\u5e27\u603b\u6570\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>SEC_CNT<\/strong> (\u8fd0\u884c\u65f6\u95f4)<\/td>\n<td style=\"text-align: center;\">4 \u5b57\u8282<\/td>\n<td style=\"text-align: left;\">\u81ea\u8bbe\u5907\u4e0a\u7535\u6216\u91cd\u542f\u4ee5\u6765\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u7cbe\u5ea6\u4e3a 0.1 \u79d2\uff08\u6bcf\u8fc7 1 \u79d2\u8be5\u503c\u52a0 10\uff09\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2026\/07\/image-1785076936967.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 405px; --smush-placeholder-aspect-ratio: 405\/327;\" \/><\/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,2206,1467,1468],"class_list":["post-25093","post","type-post","status-publish","format-standard","hentry","category-all","category-arduino","category-c-c","category-esp32","category-platformio","category-599","tag-ble","tag-eddystonetlm_beacon","tag-esp32","tag-1468"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/25093","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=25093"}],"version-history":[{"count":3,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/25093\/revisions"}],"predecessor-version":[{"id":25097,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/25093\/revisions\/25097"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}