Windows 10 Warble exception when calling warble_gattchar_write_without_resp_async()

I am getting the following exception when trying to write to a characteristic:
onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1292)\Windows.Devices.Bluetooth.dll!00007FFE7C6A02D3: (caller: 00007FFE7C69F651) Exception(1) tid(7330) 80070005 Access is denied.
Exception thrown at 0x00007FFEA934A799 in ethble.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000D092AFD8E0.
Exception thrown at 0x00007FFEA934A799 in ethble.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1103)\Windows.Devices.Bluetooth.dll!00007FFE7C75B35C: (caller: 00007FFE7C6A1E77) ReturnHr(1) tid(7330) 80070005 Access is denied.
Msg:[onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1292)\Windows.Devices.Bluetooth.dll!00007FFE7C6A02D3: (caller: 00007FFE7C69F651) Exception(1) tid(7330) 80070005 Access is denied.
]
onecoreuap\drivers\wdm\bluetooth\user\winrt\gatt\gattdeviceservice.cpp(1754)\Windows.Devices.Bluetooth.dll!00007FFE7C6A2609: (caller: 00007FFE7C6A748F) Exception(2) tid(7330) 80070005 Access is denied.
Exception thrown at 0x00007FFEA934A799 in ethble.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000D092AFDA80.
Exception thrown at 0x00007FFEA934A799 in ethble.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.

I use the example-scanner project and added this function to make a connection.
int connect(const char* mac) {
conn_status = -1; //pending

gatt = warble_gatt_create(mac);
for (int i = 0; i < 1; i++) {
    promise<void> connect_task;
    cout << "Connecting to " << mac << endl;
    warble_gatt_connect_async(gatt, &connect_task, [](void* context, WarbleGatt* caller, const char* value) {
        auto task = (promise<void>*) context;

        if (value == nullptr) {
            cout << "Am I connected 1? " << warble_gatt_is_connected(caller) << endl;
            if (warble_gatt_has_service(gatt, "19490001-5537-4f5e-99ca-290f4fbff142"))
            {
                cout << "service ok" << endl;
                gatt_char = warble_gatt_find_characteristic(gatt, "19490002-5537-4f5e-99ca-290f4fbff142");
            }
            else
            {
                cout << "service fail" << endl;
            }
            task->set_value();
        }
        else {
            cout << "conn fail=" << warble_gatt_is_connected(caller) << endl;
            task->set_value();
        }
        });

    connect_task.get_future().get();

    if (gatt_char)
    {
        promise<void> notif_task;
        cout << "char ok" << endl;
        warble_gattchar_enable_notifications_async(gatt_char, &notif_task, [](void* context, WarbleGattChar* caller, const char* value) {
            auto task1 = (promise<void>*) context;
            if (value == nullptr)
            {
                promise<void> read_task;
                conn_status = 0;
                cout << "notify ok" << endl;
                warble_gattchar_on_notification_received(gatt_char, &read_task, on_notify);
            }
            else
                cout << "notify fail" << endl;

            task1->set_value();
            });

        notif_task.get_future().get();

        //ok, write data
        if (conn_status == 0)
        {
            promise<void> write_task;
            cout << "write data" << endl;
            uint8_t buf[] = { 0x94, 0x14, 0x00, 0x01, 0x04, 0x00, 0x00, 0x85, 0x0B, 0x00, 0x00, 0x00 };
            warble_gattchar_write_without_resp_async(gatt_char, buf, 12, &write_task, write_done);
        }
    }
    else
    {
        cout << "char fail" << endl;
    }

    this_thread::sleep_for(5s);

    promise<int32_t> dc_task;
    cout << "Disconnecting..." << endl;
    warble_gatt_on_disconnect(gatt, &dc_task, [](void* context, WarbleGatt* caller, int32_t status) {
        ((promise<int32_t>*) context)->set_value(status);
        });
    warble_gatt_disconnect(gatt);
    cout << "disconnected, status = " << dc_task.get_future().get() << endl;

    cout << "Am I connected? " << warble_gatt_is_connected(gatt) << endl;
}
return 0;

}

void write_done(void* context, WarbleGattChar* caller, const char* value)
{
cout << "write " << endl;
}

The debug prints out:
Connecting to D9:F6:9F:57:F3:42
Am I connected 1? 1
service ok
char ok
notify ok
write data
write

Does anyone know what the problem is?

Sign In or Register to comment.