Data transfer BLE Xamarin Forms

Hi everyone. I am new to BLE and I hope that any of you can guide me through what I want to solve. I want to send data via BLE but without pairing with any device. More specific, I want to open a door via Bluetooth LE but I do not want to pair with the door lock in order to lock or unlock the door. Has anyone done something like this or can any of you guide me on how can I solve this ? (Xamarin Forms - Android)

Thanks

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    What you described above seems that you wanted to advertise data through BLE.
    This plugin could help you: https://github.com/aritchie/bluetoothle
    Use this to advertise:

    CrossBleAdapter.Current.Advertiser.Start(new AdvertisementData
    {
        LocalName = "TestServer",
        ServiceUUIDs = new Guid[] { /* your custom UUIDs here */ }
    });
    
    CrossBleAdapter.Current.Advertiser.Stop();
    

    Moreover, you could refer to the advertising documentation: https://github.com/aritchie/bluetoothle/blob/master/docs/advertising.md

  • calincozmincalincozmin Member ✭✭

    @LandLu I just tried with their last version and it's not working as it should.

    After a couple of failures I did something like the code below. It's working but only with data smaller than 31 bytes. There is any possibility to increase the limit of data ?

    Thanks

    ` AdvertiseSettings settings = new AdvertiseSettings.Builder()
    .SetAdvertiseMode(AdvertiseMode.LowLatency).SetTxPowerLevel(AdvertiseTx.PowerHigh).SetConnectable(true).Build();

                            ParcelUuid pUuid = new ParcelUuid(UUID.FromString(UuiD));
    
                            AdvertiseData data = new AdvertiseData.Builder()
                                .SetIncludeDeviceName(false)
                                .AddServiceUuid(pUuid )
                                .AddServiceData(pUuid , bytes)
                                .Build(); //.SetIncludeDeviceName(true)
    
                            _manager.Adapter.BluetoothLeAdvertiser.StartAdvertising(settings, data, new AdvertiseCallBackClass());`
    
Sign In or Register to comment.