Listening to and accepting a BLE Connect request in windows

丶灬走出姿态 提交于 2019-12-08 07:14:18

问题


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!

来源:https://stackoverflow.com/questions/41962514/listening-to-and-accepting-a-ble-connect-request-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!