2014-11-28 4 views
1

BLE (Bluetooth Low Energy)가 포함 된 Android 애플리케이션의 경우 evothings 플러그인을 사용하여 심박수 측정을위한 수신 장치 알림을 신청하려고합니다. 장치를 검색하고, 판독 서비스를 연결할 수는 있지만 가입 할 수는 없습니다.evothings 플러그인을 사용하여 BLE에 대한 알림을 구독하십시오.

app.connect = function(address, name) 
{ 
    app.stopLeScan(); 
    console.log('connect('+address+')'); 
    document.getElementById('deviceName').innerHTML = address + " " + name; 
    ble.connect(address, function(r) 
    { 
     app.deviceHandle = r.deviceHandle; 
     console.log('connect '+r.deviceHandle+' state '+r.state); 
     document.getElementById('deviceState').innerHTML = r.state; 
     if (r.state == 2) // connected 
     { 
      console.log('connected, requesting services...'); 
      app.getServices(r.deviceHandle); 
      app.subscribe(r.deviceHandle); 
     } 


    }, function(errorCode) 
    { 
     console.log('connect error: ' + errorCode); 
    }); 
}; 

그리고 구독 기능 : 여기

일부 코드 조각입니다

Write Descriptor.. index.js:44 
Subscribe.. index.js:62 
connected, requesting services... index.js:211 
Error: enableNotification: JSON error. index.js:71 
Status: writeDescriptor ok. index.js:51 
s1: 0 00001800-0000-1000-8000-00805f9b34fb. 2 chars. index.js:231 
c11: 00002a00-0000-1000-8000-00805f9b34fb. 0 desc. index.js:248 
    properties: PROPERTY_READ index.js:249 
    writeType: WRITE_TYPE_DEFAULT index.js:250 
c12: 00002a01-0000-1000-8000-00805f9b34fb. 0 desc. index.js:248 
    properties: PROPERTY_READ index.js:249 
    writeType: WRITE_TYPE_DEFAULT index.js:250 
s2: 0 00001801-0000-1000-8000-00805f9b34fb. 1 chars. index.js:231 
c13: 00002a05-0000-1000-8000-00805f9b34fb. 1 desc. index.js:248 
    properties: PROPERTY_INDICATE index.js:249 
    writeType: WRITE_TYPE_DEFAULT index.js:250 
    d26: 00002902-0000-1000-8000-00805f9b34fb index.js:268 
s3: 0 0000180d-0000-1000-8000-00805f9b34fb. 3 chars. index.js:231 
c14: 00002a37-0000-1000-8000-00805f9b34fb. 1 desc. index.js:248 
    properties: PROPERTY_NOTIFY index.js:249 
    writeType: WRITE_TYPE_DEFAULT index.js:250 
    d27: 00002902-0000-1000-8000-00805f9b34fb index.js:268 
c15: 00002a38-0000-1000-8000-00805f9b34fb. 0 desc. index.js:248 
    properties: PROPERTY_READ index.js:249 
    writeType: WRITE_TYPE_DEFAULT index.js:250 
c16: 00002a39-0000-1000-8000-00805f9b34fb. 0 desc. index.js:248 
    properties: PROPERTY_WRITE index.js:249 
    writeType: WRITE_TYPE_DEFAULT index.js:250 

나는에 관심이 있어요 :

app.subscribe = function(deviceHandle) 
{ 

    console.log('Write Descriptor..'); 
    ble.writeDescriptor(deviceHandle, 
     "00002a37-0000-1000-8000-00805f9b34fb", // Characteristic 
     "00002902-0000-1000-8000-00805f9b34fb", // descriptor 
     new Uint8Array([1,0]), 
     function() 
     { 
      console.log('Status: writeDescriptor ok.'); 
     }, 
     function(errorCode) 
     { 
      // This error will happen on iOS, since this descriptor is not 
      // listed when requesting descriptors. On iOS you are not allowed 
      // to use the configuration descriptor explicitly. It should be 
      // safe to ignore this error. 
      console.log('Error: writeDescriptor: ' + errorCode + '.'); 
     }); 

    console.log('Subscribe..'); 
    ble.enableNotification(deviceHandle, 
     "00002a37-0000-1000-8000-00805f9b34fb", 
     function(data) 
     { 
      console.log('byteLength: '+data.byteLength); 
     }, 
     function(errorCode) 
     { 
      console.log('Error: enableNotification: ' + errorCode + '.'); 
    }); 

} 

로그의 출력은 다음을 보여줍니다 s3으로 표시된 고각 서비스. 알림을 활성화하면 JSON 오류가 발생합니다. 누군가가 조언을 해줄 수 있기를 바랍니다. 사전에

덕분에

Maverick2k

답변

1

당신이 evothings-예에서 "easyble"라이브러리를 사용하고있는 것 같다. 내가 맞습니까?

또한 "app.getServices"함수는 예제에 나열되어 있지 않지만 "subscribe"를 호출하기 전에 완료되지 않은 것처럼 보입니다. 따라서 "subscribe"중에 특성 및 설명자에 대한 UUID 및 핸들을 사용할 수 없으며이를 사용하려는 시도가 실패합니다.

이 상황에서 어떻게 "writeDescriptor"가 성공할 수 있는지는 알 수 없습니다. 아마도 오류 처리가 어떻게 든 망가져 있습니다.

어쨌든 "getServices"콜백 끝에 "subscribe"를 호출하십시오. 그것은 당신의 문제를 해결해야합니다.

+0

답변 해 주셔서 감사합니다. 나는 ble.evothings.com과 easyble 예제를 함께 사용했다. 이제 bleble.com.com API를 래핑하는 easyble에 내 코드를 전적으로 의존하게 만들었습니다. – EmbedWise

관련 문제