首页 > 解决方案 > 将 Gatt BLE 通知从 tizen 可穿戴应用程序发送到 Android 应用程序

问题描述

我正在尝试从 Tizen 手表可穿戴应用程序(作为服务器的外围设备)向 Android 智能手机应用程序(作为客户端的中央设备)发送通知。但是从可穿戴应用程序发送通知时出现错误。

在 tizen Wearable App(使用 .net API)中,我发送这样的通知:

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

这会引发以下错误:

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

在 Android App 端,我订阅通知如下:

mBluetoothGatt.setCharacteristicNotification(characteristic, true);

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

我不明白为什么会出现这个错误。我检查了:

该错误似乎意味着 .net API 调用本机 API 函数 bt_gatt_server_notify_characteristic_changed_value() 期望回调,但 .net API 方法 SendNotification() 在其规范中不需要这样的回调,如这里API 规范

有谁知道为什么会出现上述错误?

提前致谢 !

标签: androidbluetooth-lowenergytizengattsamsung-galaxy-gear

解决方案


也许,顺序不正确,或者,值没有改变。

您可以按照下一步进行吗?

1)注册通知状态改变回调(在 GATT 服务器端)-> 使用这个(charc.NotificationStateChanged += Charc_NotificationStateChanged;) 2)启用通知(在 GATT 客户端) 3)收到“NotificationStateChanged”事件后 a)更改值(charc.SetValue(_valueChanged);) b) 调用 SendIndicationAsync (_server.SendIndicationAsync(charc, null);)

您可以在下一个 URL 中参考此过程。(公共异步任务 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;

推荐阅读