bleat
Version:
Abstraction library following Web Bluetooth specification for hiding differences in JavaScript BLE APIs
59 lines (45 loc) • 1.6 kB
HTML
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>bleat global</title>
</head>
<body>
<div id="status"></div>
<script src="cordova.js"></script>
<script src="../dist/api.classic.min.js"></script>
<script>
// Redirect console.log to Evothings Workbench
if (window.hyper && window.hyper.log) { console.log = hyper.log; }
var statusEl = document.getElementById("status");
function logStatus(message) {
console.log(message);
statusEl.innerText += message + "\n";
}
bleat.startScan(function(device) {
bleat.stopScan(logStatus);
logStatus("found device: " + device.name);
device.connect(function() {
logStatus("connected to: " + device.name);
Object.keys(device.services).forEach(function(serviceID) {
var service = device.services[serviceID];
logStatus("\nservice: " + service.uuid);
Object.keys(service.characteristics).forEach(function(characteristicID) {
var characteristic = service.characteristics[characteristicID];
logStatus("\t└characteristic: " + characteristic.uuid);
Object.keys(characteristic.descriptors).forEach(function(descriptorID) {
var descriptor = characteristic.descriptors[descriptorID];
logStatus("\t\t└descriptor: " + descriptor.uuid);
});
});
});
device.disconnect(logStatus);
}, function() {
logStatus("disconnected from: " + device.name);
}, logStatus);
}, logStatus);
</script>
</body>
</html>