Android 使用evothings和rPi读取特征错误
我有rPi设置,其中节点运行bleno来公布特性。使用evothings,我正在测试Android和iOS,在读取特性时,我都遇到了一个错误 读取evothings内特征的代码为:Android 使用evothings和rPi读取特征错误,android,ios,raspberry-pi,bluetooth-lowenergy,evo,Android,Ios,Raspberry Pi,Bluetooth Lowenergy,Evo,我有rPi设置,其中节点运行bleno来公布特性。使用evothings,我正在测试Android和iOS,在读取特性时,我都遇到了一个错误 读取evothings内特征的代码为: device.readServiceCharacteristic( 'ff51b30e-d7e2-4d93-8842-a7c4a57dfb07', 'ff51b30e-d7e2-4d93-8842-a7c4a57dfb08', function
device.readServiceCharacteristic(
'ff51b30e-d7e2-4d93-8842-a7c4a57dfb07',
'ff51b30e-d7e2-4d93-8842-a7c4a57dfb08',
function(data)
{
console.log('characteristic data: ' + evothings.ble.fromUtf8(data));
},
function(errorCode)
{
console.log('readCharacteristic error: ' + errorCode);
});
传入的第一个uuid是我可以在控制台日志上看到的服务ID。已经从服务器(rpi)端的代码中检查了第二个uuid
当我运行此命令时,控制台会在iOS上记录发生了不太可能的错误。在Android上,它记录:错误1
为了在服务器上提供参考,我遵循了本教程:
我正试图用它来了解BLE,但无法通过谷歌搜索走出此类常见错误。在阅读特征之前,必须遵循以下步骤:
var服务=[];
var-readData;
//开始扫描可扩展设备
evothings.ble.startScan(
onDeviceFound,
onScanError);
//此函数在检测到设备时调用,如下所示
//我们检查是否找到了我们要找的设备。
函数onDeviceFound(设备)
{
//停止扫描。
evelothings.ble.stopScan();
//连接。
evothings.ble.connectToDevice(
装置,
未连接,
断开连接,
非连接字符);
}
//连接设备时调用。
未连接的功能(设备)
{
console.log(“连接到设备”);
//得到服务
service=evothings.ble.getService(设备,);
//读取特征数据
可唤起的事物(
装置,
,
阅读成功,
读取错误);
}
//在设备断开连接时调用。
断开连接的功能(设备)
{
console.log(“与设备断开连接”);
}
//发生连接错误时调用。
函数onConnectError(错误)
{
console.log('连接错误:'+错误)
}
//读取成功回调
var readSuccess=函数(数据){
readData=evothings.ble.fromUtf8(数据);
};
//读取错误回调
var readError=函数(错误){
log('读取错误:'+错误);
}
var service = [];
var readData;
// Start scanning for BLE devices
evothings.ble.startScan(
onDeviceFound,
onScanError);
// This function is called when a device is detected, here
// we check if we found the device we are looking for.
function onDeviceFound(device)
{
// Stop scanning.
evothings.ble.stopScan();
// Connect.
evothings.ble.connectToDevice(
device,
onConnected,
onDisconnected,
onConnectError);
}
// Called when device is connected.
function onConnected(device)
{
console.log('Connected to device');
// Get service
service = evothings.ble.getService(device, <insert service UUID>);
// Read characteristic data
evothings.ble.readCharacteristic(
device,
<insert characteristic UUID>,
readSuccess,
readError);
}
// Called if device disconnects.
function onDisconnected(device)
{
console.log('Disconnected from device');
}
// Called when a connect error occurs.
function onConnectError(error)
{
console.log('Connect error: ' + error)
}
// Read success callback
var readSuccess = function (data) {
readData = evothings.ble.fromUtf8(data);
};
// Read error callback
var readError = function (error) {
console.log('Read error: ' + error);
}