-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 08e86cd
Showing
5 changed files
with
565 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tmp | ||
*.pyc |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# konashi for Web Bluetooth | ||
|
||
konashi を Web Bluetooth で動かす試み。 | ||
https://github.com/toyoshim/konashi-js-sdk/tree/web_bluetooth は konashi.js をそのまま動かす想定で実装されているが、このリポジトリでは Web Bluetooth を Promise で操作するもっと薄いラッパーを実装することを目指す。 | ||
|
||
|
||
## 導入 | ||
|
||
1. Android 6 に [Chrome Dev](https://play.google.com/store/apps/details?id=com.chrome.dev&hl=en) をインストール。 | ||
2. `chrome://flags/#enable-web-bluetooth` を開いて Web Bluetooth を有効にする。 | ||
3. https://jsfiddle.net/kiryuxxu/kpok7sw4/ でサンプルを試す | ||
|
||
|
||
## 開発ツール | ||
|
||
- `fab run_web_server` で https の開発サーバーが起動する。 | ||
- PC 上に Android Chrome のログを表示 [Remote Debugging on Android with Chrome](https://developer.chrome.com/devtools/docs/remote-debugging) | ||
|
||
|
||
## メモ | ||
|
||
- Android の Chrome Dev が一番実装が進んでいる。 参考: [Implementation Status](https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md) | ||
- notify がまだ使えないので値がちゃんと取れない。 | ||
- Android 上では Bluetooth の他に位置情報も ON にしないといけない。 | ||
- Mac Chrome ではペアリング可能だが characteristic がちゃんと取れない? | ||
|
||
|
||
## 参考 | ||
|
||
- [Web Bluetooth Draft Community Group Report](https://webbluetoothcg.github.io/web-bluetooth/) | ||
- [Interact with BLE devices on the Web - Google Developers](https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web?hl=en) | ||
- [chrome.bluetoothLowEnergy - Google Chrome](https://developer.chrome.com/apps/bluetoothLowEnergy) | ||
- [Web Bluetoothを使ってkonashi2.0でLチカしてみる](http://qiita.com/toyoshim/items/74ae7551dc2c9ab9cbf6) | ||
- [konashi.js向けのコードをChromeで実行](http://qiita.com/toyoshim/items/05b1d14ca925d5df3e43) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | ||
<script src="js/konashi.js"></script> | ||
<script> | ||
window.addEventListener('load', () => { | ||
var $id = (id) => { return document.getElementById(id); }; | ||
|
||
$id('start').addEventListener('click', () => { | ||
Konashi.find(true).then((k) => { | ||
k.pinMode(k.PIO0, k.INPUT) | ||
.then(() => k.pinMode(k.PIO1, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO2, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO3, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO4, k.OUTPUT)) | ||
.then(() => { | ||
var i = 0, | ||
cancelRead = false, | ||
timeline = [[k.PIO1, k.HIGH], | ||
[k.PIO1, k.LOW], | ||
[k.PIO2, k.HIGH], | ||
[k.PIO2, k.LOW], | ||
[k.PIO3, k.HIGH], | ||
[k.PIO3, k.LOW], | ||
[k.PIO4, k.HIGH], | ||
[k.PIO4, k.LOW]]; | ||
setInterval(() => { | ||
cancelRead = true; | ||
if (timeline.length <= i) { | ||
i = 0; | ||
} | ||
var values = timeline[i]; | ||
k.digitalWrite(values[0], values[1]).then(() => { | ||
cancelRead = false; | ||
}); | ||
|
||
setTimeout(() => { | ||
if (!cancelRead) { | ||
k.digitalRead(k.PIO0).then((v) => { | ||
$id('pio0').innerHTML = v; | ||
}); | ||
} | ||
}, 50); | ||
|
||
i++; | ||
}, 200); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>konashi Web Bluetooth</h1> | ||
<button class="btn btn-large btn-block" id="start">Find konashi</button> | ||
<br /> | ||
<span class="badge">PIO0</span> <span id="pio0"></span> | ||
</div> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import socket | ||
import BaseHTTPServer, SimpleHTTPServer | ||
import ssl | ||
|
||
from fabric.api import * | ||
|
||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
TEMP_DIR = os.path.join(ROOT_DIR, 'tmp') | ||
|
||
|
||
def run_web_server(): | ||
local('mkdir -p {}'.format(TEMP_DIR)) | ||
ssl_key = os.path.join(TEMP_DIR, 'ssl.key') | ||
ssl_csr = os.path.join(TEMP_DIR, 'ssl.csr') | ||
ssl_cert = os.path.join(TEMP_DIR, 'ssl.crt') | ||
ssl_pem = os.path.join(TEMP_DIR, 'ssl.pem') | ||
if not os.path.isfile(ssl_key): | ||
local('openssl genrsa -out {} 1024'.format(ssl_key)) | ||
local('openssl req -new -key {} -out {}'.format(ssl_key, ssl_csr)) | ||
local('openssl x509 -req -days 3650 -in {} -signkey {} -out {}'.format(ssl_csr, ssl_key, ssl_cert)) | ||
local('cat {} {} > {}'.format(ssl_cert, ssl_key, ssl_pem)) | ||
port = 10443 | ||
host = socket.gethostbyname(socket.gethostname()) | ||
puts('Starting https server on https://{}:{}'.format(host, port)) | ||
httpd = BaseHTTPServer.HTTPServer((host, port), | ||
SimpleHTTPServer.SimpleHTTPRequestHandler) | ||
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=ssl_pem, server_side=True) | ||
httpd.serve_forever() |
Oops, something went wrong.