1

I've been trying to connect an iOS device to windows using Bluetooth low energy, and I find the windows BLE API very.. unclear.

The windows is acting as the peripheral and the iOS device the Central

I think that my Swift code on the iOS device is fine, it works with BLE devices (like a climate device I have) what I'm doing on the iOS side is: - Launching the scan for BLE Advertisements - Upon receiving an Advertisements, if the ManufacturerData is what I'm looking for, I try to connect to the peripheral.

On the windows side, I: - prepare my Advert package - publish it

For the moment, I receive the package on iOS, I launch the connection attempt... and nothing! (didFailToConnect isn't even called)

I think I'm missing something on the windows side, I imagine there's some kind of connection request listener? that I need to say "yes I accept this connection!" Or "no, I do not!" And as this does not exist in my code, the connection request is never answered? Am I in the ball park?

On googling, stackoverflowing and WindowsAPIing I can't find how to do this, if it's this that I do indeed need to do, or if what I'm trying can even be done in this manner!

It goes without saying that any help would be much appreciated. Here is my C# code on the windows side, for testing purposes, it's a simple console application that then stays in an ugly loop as to not terminate till I want it too:

namespace BluetoothClient
{
    class Program
    {
        static void Main(string[] args)
        {
            BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();

            var manufacturerData = new BluetoothLEManufacturerData();
            manufacturerData.CompanyId = 0xFFFA;

            var writer = new DataWriter();
            writer.WriteString("Testme");

            manufacturerData.Data = writer.DetachBuffer();

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            publisher.Start();

            publisher.StatusChanged += Publisher_StatusChanged;

            Console.Write("Started\n");

            while (true) { }
        }

        private static void Publisher_StatusChanged(BluetoothLEAdvertisementPublisher sender, BluetoothLEAdvertisementPublisherStatusChangedEventArgs args)
        {
            Console.Write("Status: "+args.Status+"\n");
        }
    }
}

I look forward to your kind replies and hope you can help me crawl out of this rut, much appreciated and thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
beau c
  • 93
  • 1
  • 9
  • 1
    Maybe your `while(true)` loop is blocking the thread, instead of that (what will consume a full processor core for nothing) use `Console.ReadKey();` to stop the execution until a key is pressed. – Gusman Jan 31 '17 at 16:30
  • Good point, I've replaced my ugly loop with your suggestion, but sadly it changes nothing, and even if it did, I would still have no way of knowing on the windows side that there has been a connection request / connection established. – beau c Jan 31 '17 at 16:50
  • Ok, it has been a while since I programmed BLE devices, but if I don't recall it wrong, you don't establish a connection to a BLE device, you subscribe to changes on charactersitics from the centra, so the publisher doesn't knows if anyone has been connected, it just broadcasts changes in characteristics. I know this is not precissely C#, but these can help you understand the ble infrastructure and roles: https://devzone.nordicsemi.com/tutorials/ Look at the "Bluetooth Low Energy" tutorials, they're really great. – Gusman Jan 31 '17 at 17:06
  • Check this sample, I think you need to set the UUID / Major / Minor data properly for the iOS side to properly receive it. http://stackoverflow.com/questions/31564207/windows-10-bluetooth-advertisement-api – Jon Jan 31 '17 at 17:08
  • @Gusman, Thanks for the advice, I attempted to discover the available services on the iOS side, and iOS tells me that I must be connected to the peripheral to do so. And when I've worked in the past with a ble climate reader (BeeWi SmartClim) a connection was necessary. So I do feel that I'm missing something to do with the connection on the Windows side, but I will take the time to read your suggestion, Thank you. – beau c Feb 01 '17 at 09:58
  • @Mangist , the iOS side does receive it, and the data is there, it's just the connection that doesn't work, though it might be because of this. I'll give it a try, thank you. – beau c Feb 01 '17 at 10:03
  • Just curious, but do you know that Windows BLE supports peripheral mode? Even Android didn't until 5.0. I can imagine the number of people writing Windows-powered peripherals to be a very small number. – O'Rooney Feb 07 '17 at 21:25

0 Answers0