我有运行bleno的节点的rPi设置来宣传一个特征。随着evothings我正在测试Android和iOS两者,我在读取特征时遇到了错误。
阅读evothings中的特征的代码是:
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
在服务器上的参考我已经按照本教程: https://www.hackster.io/inmyorbit/build-a-mobile-app-that-connects-to-your-rpi-3-using-ble-7a7c2c
我正在尝试使用此功能来了解BLE,但无法通过谷歌解决这些常规错误。
答案 0 :(得分:0)
在阅读特征之前,您必须按照以下步骤操作:
...看来你在没有完成第一个的情况下尝试做#4。这里有一个来自Evothings API Guide的例子:
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);
}