android - 将 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);
我不明白为什么会出现这个错误。我检查了:
- Android 客户端设备连接到 BLE 手表设备。
- Gatt服务端App暴露的Gatt服务被客户端App找到。
- 手表设备的远程设备蓝牙地址正是Android在蓝牙设置中显示的。
该错误似乎意味着 .net API 调用本机 API 函数 bt_gatt_server_notify_characteristic_changed_value() 期望回调,但 .net API 方法 SendNotification() 在其规范中不需要这样的回调,如这里API 规范
有谁知道为什么会出现上述错误?
提前致谢 !
解决方案
也许,顺序不正确,或者,值没有改变。
您可以按照下一步进行吗?
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;
推荐阅读
- r - 数据框中的滑动窗口示例
- node.js - maven 和 npm 存储库有什么区别?
- hadoop - 无法在 ubuntu 18.04 中启动 hadoop datanode hadoop 3.1.1
- selenium-ide - 如何在 Selinium Ide 中使用“运行”命令?
- javascript - 在单击画布的位置添加一个点
- c++ - 如何在 C++ 的输出中打印引号?
- android - ionic GeoLocation 检索地址?
- wpf - 除非检查注册表,否则如何更改 WPF 的版本?
- powershell - 新的本地用户/本地组路径?
- javascript - 无法导入和导出类