这里的每件事:https://github.com/evothings/cordova-ble/issues/134
我试图通过蓝牙向我的rpi发送时间。
但我不能让evothings.ble.writeCharacteristic
因为不明原因而工作:/
我使用了writeCharacteristic:
app.js
ui.append('Time is being updated ...');
device.writeCharacteristic(
app.SYSTEMINFORMATIONSERVICE,
characteristic_uuid,
new Uint8Array([1]),
function(){
ui.append('DONE', true);
},
function(error){
ui.append('ERROR', true);
ui.text('Warning : '+error);
}
);
应用程序在显示"时间正在更新后崩溃..."
logcat:
02-05 11:03:54.416 20011 20011 D BluetoothGatt: readCharacteristic() - uuid: ffffffff-ffff-ffff-ffff-fffffffffff1
02-05 11:03:54.577 1049 1049 E WifiTrafficPoller: TRAFFIC_STATS_POLL true Token 65 num clients 9
02-05 11:03:54.578 1049 1049 E WifiTrafficPoller: packet count Tx=94854 Rx=127944
02-05 11:03:54.670 2185 2206 I bt_btif_gatt: set_read_value unformat.len = 42
02-05 11:03:54.671 20011 20878 D BluetoothGatt: onCharacteristicRead() - Device=B8:27:EB:6C:4F:9C UUID=ffffffff-ffff-ffff-ffff-fffffffffff1 Status=0 srvcType=0 srvcInstId=0 charInstId=0
02-05 11:03:54.694 20011 20011 E AndroidRuntime: FATAL EXCEPTION: main
02-05 11:03:54.694 20011 20011 E AndroidRuntime: Process: com.evothings.evothingsviewer, PID: 20011
02-05 11:03:54.694 20011 20011 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.BluetoothGattCharacteristic.setWriteType(int)' on a null object reference
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at com.evothings.BLE$12.run(BLE.java:988)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:815)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:104)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at android.os.Looper.loop(Looper.java:207)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5728)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-05 11:03:54.694 20011 20011 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
在服务方面,除了OnWriteRequest没有被调用外,一切都很好。所以Android应用程序在发送信息之前就崩溃了。
答案 0 :(得分:0)
在你的logcat中,uuid对我来说很奇怪
我不知道你正在测试什么样的设备,但是uuid不满足它的基本格式。
请参考
Service Discovery in Bluetooth website。
如果您对uuid及其获得方式有所了解,请检查特征uuid 简单地检查字符串并检查如何检索characteristic_uuid并不意味着 检索它的最好方法是调用getService然后调用getCharacteristic。
所以例如,
var service = evothings.ble.getService(deviceObject, '12345678-0000-1000-8000-00805f9b34fb');
var characteristic_uuid = evothings.ble.getCharacteristic(service, '11111111-0000-1000-8000-00805f9b34fb');
evothings.ble.writeCharacteristic(deviceObject, characteristic_uuid, new Uint8Array([1]), success, error);
如果这些都很好,请检查设备是否可以接收Uint8Array类型。