2017-06-07 54 views
0

我有rPi設置與節點運行bleno公佈特徵。隨着演示,我正在測試Android和iOS,並在閱讀特性時遇到了錯誤。閱讀特徵錯誤BLE與evothings和rPi

到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是正確的控制檯日誌。第二個uuid已經從服務器(rpi)端的代碼中檢查過。

當我運行該控制檯時,控制檯在iOS上登錄時發生了不太可能的錯誤。在Android上它記錄:錯誤1

對於我按照本教程中的服務器上的參考: https://www.hackster.io/inmyorbit/build-a-mobile-app-that-connects-to-your-rpi-3-using-ble-7a7c2c

我想用這個來了解BLE,但不能Google我的出路,這樣的一般錯誤。

回答

0

之前,你可以讀一個特點,你必須遵循以下步驟:

  1. 掃描設備
  2. 連接到設備
  3. 獲取服務
  4. 閱讀特點

......看起來你正在試圖做#4而沒有完成前3個。下面是從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); 
}