简体   繁体   English

将 Gatt BLE 通知从 tizen 可穿戴应用程序发送到 Android 应用程序

[英]Send Gatt BLE notification from tizen Wearable App to Android App

I'm trying to send a notification from a Tizen watch Wearable App (peripheral device as server) to an Android Smartphone App (central device as client).我正在尝试从 Tizen 手表可穿戴应用程序(作为服务器的外围设备)向 Android 智能手机应用程序(作为客户端的中央设备)发送通知。 But I got an error when sending the notification from the wearable App.但是从可穿戴应用程序发送通知时出现错误。

In tizen Wearable App (using .net API) I send the notification like this :在tizen Wearable App(使用.net API)中,我发送这样的通知:

string remoteDeviceAddress = "10:C7:53:50:C4:E5";
server.SendNotification(charc, remoteDeviceAddress);

Which raise the error below :这引发了以下错误:

11-25 10:46:05.969  Error   8874    8874    CAPI_NETWORK_BLUETOOTH  bluetooth-gatt.c: bt_gatt_server_notify_characteristic_changed_value(2964) > [bt_gatt_server_notify_characteristic_changed_value] INVALID_PARAMETER(0callback=NULL)

11-25 17:20:18.225  Error   15042   15042   Tizen.Network.Bluetooth BluetoothGattImpl.cs: SendNotification(113) > Failed to send value changed notification for characteristic uuid 00000002-1000-2000-3000-111122223333, err: InvalidParameter

In Android App side, I subscribe to notifications as below :在 Android 应用程序方面,我订阅通知如下:

mBluetoothGatt.setCharacteristicNotification(characteristic, true);

BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                    UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

I don't understand why this error is raised.我不明白为什么会出现这个错误。 I checked that :我查了一下:

  • the Android client device is connected to the BLE watch device. Android 客户端设备连接到 BLE 手表设备。
  • the Gatt service exposed by the Gatt server App is find by the client App. Gatt 服务端 App 暴露的 Gatt 服务由客户端 App 查找。
  • the remote device bluetooth address of the watch device is exactly that is display by Android in bluetooth settings.手表设备的远程设备蓝牙地址正是Android在蓝牙设置中显示的。

The error seems to mean that the .net API call the native API function bt_gatt_server_notify_characteristic_changed_value() which expect a callback but the .net API method SendNotification() does not require a such callback in its specifications as here API specifications该错误似乎意味着 .net API 调用本机 API 函数 bt_gatt_server_notify_characteristic_changed_value() 期望回调,但 .net API 方法 SendNotification() 在其规范中不需要这样的回调,如此处的API 规范

Does anyone has an idea why the error above is raised ?有谁知道为什么会出现上述错误?

Thanks in advance !提前致谢 !

Maybe, the sequence is not proper or,, the value is not changed.也许,顺序不正确,或者,值没有改变。

Can you follow next step for it?你能按照下一步吗?

1) Register notification state changed callback (On GATT server side) -> Using this (charc.NotificationStateChanged += Charc_NotificationStateChanged;) 2) Enable the notification (On GATT client side) 3) After receiving "NotificationStateChanged" event a) Change the value (charc.SetValue(_valueChanged);) b) Calls SendIndicationAsync (_server.SendIndicationAsync(charc, null);) 1) 注册通知状态改变回调(在 GATT 服务器端) -> 使用这个 (charc.NotificationStateChanged += Charc_NotificationStateChanged;) 2) 启用通知 (在 GATT 客户端) 3) 收到“NotificationStateChanged”事件后 a) 更改值(charc.SetValue(_valueChanged);) b) 调用 SendIndicationAsync (_server.SendIndicationAsync(charc, null);)

You can refer this procedure in next URL.您可以在下一个 URL 中参考此过程。 (public async Task ClientAddress_PROPERTY_READ_ONLY() function) https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSNotificationSentEventArg.cs;h=10a88576e7c86fc49d88490a83489aa8f92b2460;hb=refs/heads/tizen (公共异步任务 ClientAddress_PROPERTY_READ_ONLY() 函数) https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth .Manual.Tests/testcase/TSNotificationSentEventArg.cs;h=10a88576e7c86fc49d88490a83489aa8f92b2460;hb=refs/heads/tizen

                EventHandler<NotificationSentEventArg> Server_NotificationSent = null;

            Server_NotificationSent = (sender, e) => {
                _server.NotificationSent -= Server_NotificationSent;
                Assert.IsNotNull(e.ClientAddress, "[TestCase][ClientAddress_PROPERTY_READ_ONLY] Failed");
                Assert.IsInstanceOf<string>(e.ClientAddress, "[TestCase][ClientAddress_PROPERTY_READ_ONLY] Failed");
                BluetoothHelper.DisplayPassLabel("ClientAddress_PROPERTY_READ_ONLY");
            };

            EventHandler<NotificationStateChangedEventArg> Charc_NotificationStateChanged = null;

            Charc_NotificationStateChanged = (sender, e) => {
                try
                {
                    Log.Info(Globals.LogTag, "Charc_NotificationStateChanged");
                    _server.NotificationSent += Server_NotificationSent;

                    origin_val = charc.GetValue(0);
                    charc.SetValue(_valueChanged);
                    _server.SendIndicationAsync(charc, null);

                    charc.SetValue(origin_val);
                }
                catch (Exception ex)
                {
                    Assert.Fail("[TestCase][ClientAddress_PROPERTY_READ_ONLY] FAIL " + ex.Message);
                }
            };

            srv = _server.GetService(_svcUuid);
            charc = srv.GetCharacteristic(_charUuid);

            charc.NotificationStateChanged += Charc_NotificationStateChanged;

Can you use "SendIndicationAsync" method instead of SendNotification?您可以使用“SendIndicationAsync”方法而不是 SendNotification 吗?

Ex)前任)

server.SendIndicationAsync(charc, null); server.SendIndicationAsync(charc, null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM