Last active
March 28, 2018 11:29
-
-
Save grapswiz/63d2e73d8c58c1218740bda61107505b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
16行目でerrorに入る
app.js:20 DOMException: Unsupported device.