You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在Eddystone-TLM中添加extraDataField,接收端字段长度为0求助

Fixing Eddystone-TLM Extra Data Not Showing Up

Hey there, let's figure out why your Eddystone-TLM extra data is showing up with length 0 on the receiver side. Looking at your code, there are a few key issues with how you're combining Eddystone URL and TLM frames, plus how you're setting TLM fields. Let's break it down and fix it step by step.

Key Problems in Your Current Code

  1. Mixing Eddystone URL and TLM Frames Incorrectly
    Eddystone URL and TLM are separate frame types—you can't pack both into a single Beacon object. TLM is meant to be an auxiliary frame that broadcasts alongside a main frame (like URL), not merged into it.

  2. Using setExtraDataFields for TLM
    Eddystone-TLM has a fixed, predefined structure (version, battery voltage, temperature, advertising count, uptime). The extraDataFields method is for custom extensions, not for setting these standard TLM fields. You need to use setDataFields instead to map to the TLM frame's expected structure.

  3. Incorrect Beacon Type Codes & Configuration
    You set setBeaconTypeCode(0x20) (which is TLM) but then set the main layout to URL. This mismatch confuses the transmitter about which frame type to prioritize.

Corrected Code Implementation

Let's rewrite your code to properly broadcast both Eddystone URL and TLM frames together:

Step 1: Build the Eddystone URL Beacon

byte[] urlBytes;
try {
    urlBytes = UrlBeaconUrlCompressor.compress("http://www.google.com");
} catch (MalformedURLException e) {
    e.printStackTrace();
    return; // Exit if URL compression fails
}

Identifier encodedUrlIdentifier = Identifier.fromBytes(urlBytes, 0, urlBytes.length, false);
Beacon urlBeacon = new Beacon.Builder()
        .setIdentifiers(Collections.singletonList(encodedUrlIdentifier))
        .setServiceUuid(0xfeaa) // Eddystone service UUID
        .setBeaconTypeCode(0x10) // Eddystone URL frame type code
        .setTxPower(-65)
        .build();

Step 2: Build the Eddystone TLM Beacon

Note how we use setDataFields here, and format the temperature correctly (TLM expects a 16-bit signed integer, so multiply your temperature value by 256):

// Parse user input values
int batteryVoltage = Integer.parseInt(et_Voltage.getText().toString());
float temperature = Float.parseFloat(et_temp.getText().toString());

// Convert temperature to TLM's required 16-bit format (multiply by 256)
int tempRawValue = (int) (temperature * 256);

// TLM data fields order: version, battery (mV), temperature (raw), advertising count, uptime (seconds)
ArrayList<Long> tlmDataFields = new ArrayList<>();
tlmDataFields.add(1L);          // TLM version (always 1 for current spec)
tlmDataFields.add((long) batteryVoltage);
tlmDataFields.add((long) tempRawValue);
tlmDataFields.add(0L);          // Advertising count (start at 0, increment if needed)
tlmDataFields.add(0L);          // Uptime (start at 0, update if needed)

Beacon tlmBeacon = new Beacon.Builder()
        .setServiceUuid(0xfeaa)
        .setBeaconTypeCode(0x20) // Eddystone TLM frame type code
        .setDataFields(tlmDataFields)
        .build();

Step 3: Configure Beacon Parser and Start Advertising

We'll configure the parser to support both frame types, then broadcast both beacons at once:

BeaconParser beaconParser = new BeaconParser()
        .setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT)
        .addExtraDataParser(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT));

BeaconTransmitter beaconTransmitter = new BeaconTransmitter(this, beaconParser);
beaconTransmitter.setConnectable(true);
// Broadcast both URL and TLM frames simultaneously
beaconTransmitter.startAdvertising(Arrays.asList(urlBeacon, tlmBeacon));

Key Notes to Remember

  • TLM Frame is Auxiliary: It always needs to be broadcast alongside a main Eddystone frame (URL, UID, or EID). Receivers expect this pairing.
  • Temperature Format: Eddystone-TLM uses a 16-bit signed integer where 1 unit = 1/256 °C. So 25.5°C becomes 25 * 256 + 128 = 6528.
  • Frame Type Codes: Double-check these: URL = 0x10, TLM = 0x20, UID = 0x00. Using the wrong code will break frame detection.

Give this code a try—your receiver should now pick up the TLM fields with the correct values instead of a 0-length extra data field.

内容的提问来源于stack exchange,提问作者Parvinder06

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:26:26