GithubHelp home page GithubHelp logo

Comments (12)

grishka avatar grishka commented on August 22, 2024

You need to advertise a BLE service with these parameters:

  • Service UUID = fe 2c
  • Service data = fc 12 8e 01 42 00 00 00 00 00 00 00 00 00 [10 random bytes]

If you're using win32 APIs, this looks like a good starting point (it's unreasonably messy though).

For UWP/WinRT, use this.

(sorry, I'm too lazy to set up Visual Studio on my VM to provide you with a minimal working code example for this specific case)

from neardrop.

aditya-mankal avatar aditya-mankal commented on August 22, 2024

Thank you, @grishka!
I have broadcasted a BLE service as you have suggested, but the Android device is still not discoverable until I fire the Activity Intent or use an older version of the Google Files app and tap "receive".

Can you please tell me if I am missing something here? Thank you!

` public sealed class BLEAdvertisementService
{
private BluetoothLEAdvertisementWatcher watcher;
private BluetoothLEAdvertisementPublisher publisher;

    // Service UUID: fe2c
    private const string ServiceUuid = "0000fe2c-0000-1000-8000-00805f9b34fb";

    // Service Data: fc 12 8e 01 42 00 00 00 00 00 00 00 00 00 [10 random bytes]
    private readonly byte[] serviceData = { 0xFC, 0x12, 0x8E, 0x01, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

    public void StartAdvertising()
    {
        publisher = new BluetoothLEAdvertisementPublisher();

        // Create the service data section of the advertisement
        var serviceDataSection = new BluetoothLEAdvertisementDataSection();
        var writer = new DataWriter();
        writer.WriteBytes(serviceData);
        serviceDataSection.Data = writer.DetachBuffer();

        // Add the service data section to the advertisement
        publisher.Advertisement.DataSections.Add(serviceDataSection);

        // Set the UUIDs of the services being advertised
        publisher.Advertisement.ServiceUuids.Add(new Guid(ServiceUuid));

        // Start advertising
        publisher.Start();
    }

    public void StopAdvertising()
    {
        publisher?.Stop();
        publisher = null;
    }
}`

from neardrop.

grishka avatar grishka commented on August 22, 2024

You need to append 10 random bytes to the service data.

from neardrop.

aditya-mankal avatar aditya-mankal commented on August 22, 2024

Excuse my naivety here. Can you please explain what the service data should be? Is it any random 10 bytes? Or should I append 10 random bytes to the service data that you have already given - fc 12 8e 01 42 00 00 00 00 00 00 00 00 00

from neardrop.

grishka avatar grishka commented on August 22, 2024

Yes, to the one I already given

from neardrop.

aditya-mankal avatar aditya-mankal commented on August 22, 2024

Thank you, @grishka! Can you please tell me if I can run this BLE service as a separate process (independent of my actual UWP app) for now? I have a few build issues with my UWP app as of now. I want to quickly establish if the whole approach works for me.

And in case you have a publicly available Windows equivalent of this project of yours, it would be a great inspiration to me!

from neardrop.

grishka avatar grishka commented on August 22, 2024

You can. It doesn't matter which process you run it in, that doesn't change the broadcasts that go out. I was able to make them with "nRF Connect" Android app, for example. That app is also how I determined the format.

from neardrop.

aditya-mankal avatar aditya-mankal commented on August 22, 2024

Hello @grishka,

Despite broadcasting the said signal, my Android device is still not visible without using an older version of the Google Files app and tapping "receive".

Here is my broadcast code:

namespace App1.Source
{
    using System;
    using Windows.Devices.Bluetooth.Advertisement;
    using Windows.Storage.Streams;
    public sealed class BLEAdvertisementService
    {
        private BluetoothLEAdvertisementPublisher publisher;
        private string serviceUuid = "0000fe2c-0000-1000-8000-00805f9b34fb";
        private byte[] serviceData = { 0xFC, 0x12, 0x8E, 0x01, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40 };

        public void StartAdvertising()
        {
            publisher = new BluetoothLEAdvertisementPublisher();

            // Create the service data section of the advertisement
            var serviceDataSection = new BluetoothLEAdvertisementDataSection();
            var writer = new DataWriter();
            writer.WriteBytes(serviceData);
            serviceDataSection.Data = writer.DetachBuffer();

            // Add the service data section to the advertisement
            publisher.Advertisement.DataSections.Add(serviceDataSection);

            // Set the UUIDs of the services being advertised - NOT WORKING
            //publisher.Advertisement.ServiceUuids.Add(new Guid(serviceUuid));

            // Start advertising
            publisher.Start();
        }

        public void StopAdvertising()
        {
            publisher?.Stop();
            publisher = null;
        }
    }
}

Edit: @grishka, if I set the serviceUuid, then I see an exception "Value does not fall within the expected range" when the publisher starts. I tried to understand the significance of Service Uuid and the Service Data, but I am just getting started.
Any help from your end to correctly broadcast would be critical in me succeeding with this project!

Thanks a lot!

from neardrop.

aditya-mankal avatar aditya-mankal commented on August 22, 2024

Hello @grishka, hope you are doing great! I spent some more time debugging my code and gained a deeper understanding. Updated my previous question. Please consider responding when feasible.

#154 (comment)

from neardrop.

aditya-mankal avatar aditya-mankal commented on August 22, 2024

Hello @grishka, hope you are doing great! Looking forward to your inputs in fixing this.
Thanks a lot!

from neardrop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.