Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBEACON not working #281

Open
Makuo12 opened this issue Feb 1, 2025 · 0 comments
Open

IBEACON not working #281

Makuo12 opened this issue Feb 1, 2025 · 0 comments

Comments

@Makuo12
Copy link

Makuo12 commented Feb 1, 2025

I tried setting up a ibeacon but it is not working properly

const IBEACON_PREFIX: [u8; 2] = [0x02, 0x15]; // iBeacon prefix // Apple's prefix
const BEACON_UUID: &str = "87b99d1c-4828-4b91-bed5-9054731a2356";
const MAJOR: [u8; 2] = [0x00, 0x01]; // Major value 1
const MINOR: [u8; 2] = [0x00, 0x01]; // Minor value 1
const TX_POWER: i8 = -59; // Calibrated Tx power at 1 meter
fn create_ibeacon_data() -> Vec<u8, 31> {
    let beacon_uuid = uuid::Uuid::parse_str(BEACON_UUID).expect("uuid_failed");
    let mut data: Vec<u8, 31> = Vec::new();
    data.extend_from_slice(&[0x02, 0x15]); // iBeacon prefix
    data.extend_from_slice(beacon_uuid.as_bytes());
    data.extend_from_slice(&MAJOR);
    data.extend_from_slice(&MINOR);
    data.push(TX_POWER as u8);
    
    data
}
async fn advertise<'a, C: Controller>(
    name: &'a str,
    peripheral: &mut Peripheral<'a, C>,
) -> Result<Connection<'a>, BleHostError<C::Error>> {
    let ibeacon_structure = create_ibeacon_data(); // Ensure this returns AdStructure::ManufacturerData

    let mut advertiser_data = [0; 31];
    AdStructure::encode_slice(
        &[
            AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED),
            AdStructure::ManufacturerSpecificData { company_identifier: 0x004C, payload: &ibeacon_structure },
        ],
        &mut advertiser_data[..],
    )?;

    // let mut scan_data_buffer = [0; 31];
    // AdStructure::encode_slice(
    //     &[
    //         AdStructure::ServiceUuids16(&[Uuid::Uuid16([0x3b, 0x18])]),
    //         AdStructure::CompleteLocalName(name.as_bytes()),
    //     ],
    //     &mut scan_data_buffer[..],
    // )?;

    let advertiser = peripheral
        .advertise(
            &Default::default(),
            Advertisement::ConnectableScannableUndirected {
                adv_data: &advertiser_data[..],
                scan_data: &[],
            },
        )
        .await?;
    info!("[adv]  advertising");
    let conn = advertiser.accept().await.unwrap();
    info!("[adv] connection established");
    Ok(conn)
}

When I also try to included scan_data_buffer into scan_data: &scan_data_buffer,I get an error. I am trying to use the esp32 as an Ibeacon, but I still want to be able to transmit data between the IOS device and the esp32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant