Skip to content

Instantly share code, notes, and snippets.

@grapswiz
Last active March 28, 2018 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grapswiz/63d2e73d8c58c1218740bda61107505b to your computer and use it in GitHub Desktop.
Save grapswiz/63d2e73d8c58c1218740bda61107505b to your computer and use it in GitHub Desktop.
let printCharacteristic;
sendTextData = () => {
let encoder = new TextEncoder('utf-8');
};
document.querySelector("#requestButton").addEventListener("click", () => {
navigator.bluetooth.requestDevice({
filters: [{
services: ['000018f0-0000-1000-8000-00805f9b34fb']
}]
})
.then(device => {
console.log('> Found ' + device.name);
console.log('Connecting to GATT Server...');
return device.gatt.connect();
})
.then(server => server.getPrimaryService("000018f0-0000-1000-8000-00805f9b34fb"))
.then(service => service.getCharacteristic("00002af1-0000-1000-8000-00805f9b34fb"))
.then(characteristic => {
printCharacteristic = characteristic;
console.log(printCharacteristic); // printCharacteristic.writeValueで書き込めるっぽい
})
.catch(error => console.log(error));
}, false);
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button id="requestButton">requestDevice</button>
<script src="app.js"></script>
</body>
</html>
@grapswiz
Copy link
Author

16行目でerrorに入る
app.js:20 DOMException: Unsupported device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment