2016-10-25 6 views
0

私はこのUWPを初めて使っています。私は、次のMS GitHub:Linkのコードを変更して、BTLE広告を「見る」ことができるWindows Phone Appを作成しました。UWP BTLE:デバイスの広告を読むことができません

しかし、広告を読むことはできません。私の携帯電話はBTLEをサポートしていますが、私はWindows BT設定のデバイスを見ることができるので、デバイスもそれを宣伝しています。私がどこが間違っているのか、その理由を見つけるのを助けてください。

はここにJSのために私のコードです:

var watcher = new Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher(); 
//watcher.signalStrengthFilter.inRangeThresholdInDBm = -70; 
//watcher.signalStrengthFilter.outOfRangeThresholdInDBm = -75; 
//watcher.signalStrengthFilter.outOfRangeTimeout = 2000; 

$(document).ready(function() { 
    console.log("HERE: ready"); 
    watcher.onreceived = onAdvertisementReceived; 
    $("button#start").unbind('click').on('click', function (e) { 
     console.log('CLICKED >'); 
     e.preventDefault(); 
     watcher.start(); 
    }); 
    $("button#stop").unbind('click').on('click', function (e) { 
     console.log('CLICKED <'); 
     e.preventDefault(); 
     watcher.stop(); 
    }); 
}); 
function onAdvertisementReceived(eventArgs) { 
    console.log("HERE: function watcher", eventArgs); 
    var timestamp = eventArgs.timestamp; 
    var advertisementType = eventArgs.advertisementType; 
    var rssi = eventArgs.rawSignalStrengthInDBm; 
    var localName = eventArgs.advertisement.localName; 
    $("div#list > ul").append("<li> Timestamp: <strong>" + timestamp.getHours() + ":" + timestamp.getMinutes() + 
     ":" + timestamp.getSeconds() + "</strong> Type:" + advertisementType.toString() + " RSSI:" + rssi.toString() + " Name:" + 
     localName + "</li>"); 
} 

は、ここに私のHTMLコードです:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <title>Bluetooth LE Smart Watch</title> 
    <link href="css/default.css" rel="stylesheet" /> 
    <link href="css/materialize.min.css" rel="stylesheet" /> 
</head> 
<body class="container"> 
    <div class="row"> 
     <h4>List of BTLE Devices</h4> 
     <button class="btn" id="start">Start Watcher</button><button class="btn" id="stop">Stop Watcher</button> 
     <div id="list" class="col m12 s12"> 
      <ul> 

      </ul> 
     </div> 
    </div> 
    <script src="js/jquery-2.2.4.min.js"></script> 
    <script src="js/materialize.min.js"></script> 
    <script src="js/main.js"></script> 
</body> 
</html> 

答えて

1

しかし、それを任意の広告を読み取ることができません。私の携帯電話はBTLEをサポートしていますが、私はWindows BT設定のデバイスを見ることができるので、デバイスもそれを宣伝しています。私がどこが間違っているのか、その理由を見つけるのを助けてください。

BTLEの作業を行うには、package.appxmannifestのBlueTooth機能を有効にする必要があります。

VS2015->ダブルクリックpackage.appxmannifest - >機能 - > Bluetooth機能を確認してください。

か、コードビューでpackage.appxmannifestを開き、機能タグに<DeviceCapability Name="bluetooth" />を追加することができます。

<Capabilities> 
    <Capability Name="internetClient" /> 
    <DeviceCapability Name="bluetooth" /> 
</Capabilities> 
関連する問題