質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

0回答

775閲覧

ボタンをクリックするだけでBLEデバイスに接続したい

marumori

総合スコア8

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

0クリップ

投稿2017/12/19 09:33

編集2017/12/19 10:27

bluejellyを用いて、BLEデバイスをスキャンし、ブラウザからデバイスを制御したいと考えています。

<動作環境>
・Raspberry PI3 Model B
・chromium

bluejelly内にあるデモページとローカル環境で試せるソースコードどちらも試したのですが、以下のエラーが出ます。

**error** Execute : requestDevice bluejelly.js:58 Error : TypeError: Failed to execute 'requestDevice' on 'Bluetooth': required member filters is undefined. bluejelly.js:37 onError

ソースコードは以下のとおりです。

**bluejelly.js** var BlueJelly = function(){ this.bluetoothDevice = null; this.dataCharacteristic = null; this.hashUUID ={}; this.hashUUID_lastConnected; //callBack this.onScan = function(deviceName){console.log("onScan");}; this.onConnectGATT = function(uuid){console.log("onConnectGATT");}; this.onRead = function(data, uuid){console.log("onRead");}; this.onWrite = function(uuid){console.log("onWrite");}; this.onStartNotify = function(uuid){console.log("onStartNotify");}; this.onStopNotify = function(uuid){console.log("onStopNotify");}; this.onDisconnect = function(){console.log("onDisconnect");}; this.onClear = function(){console.log("onClear");}; this.onReset = function(){console.log("onReset");}; this.onError = function(error){console.log("onError");}; } //-------------------------------------------------- //setUUID //-------------------------------------------------- BlueJelly.prototype.setUUID = function(name, serviceUUID, characteristicUUID){ console.log('Execute : setUUID'); console.log(this.hashUUID); this.hashUUID[name] = {'serviceUUID':serviceUUID, 'characteristicUUID':characteristicUUID}; } BlueJelly.prototype.scan = function(uuid){ return (this.bluetoothDevice ? Promise.resolve() : this.requestDevice(uuid)) .catch(error => { console.log('Error : ' + error); this.onError(error); }); } BlueJelly.prototype.requestDevice = function(uuid) { console.log('Execute : requestDevice'); return navigator.bluetooth.requestDevice({ acceptAllDevices: true, optionalServices: [this.hashUUID[uuid].serviceUUID]}) .then(device => { this.bluetoothDevice = device; this.bluetoothDevice.addEventListener('gattserverdisconnected', this.onDisconnect); this.onScan(this.bluetoothDevice.name); }); } BlueJelly.prototype.connectGATT = function(uuid) { if(!this.bluetoothDevice) { var error = "No Bluetooth Device"; console.log('Error : ' + error); this.onError(error); return; } if (this.bluetoothDevice.gatt.connected && this.dataCharacteristic) { if(this.hashUUID_lastConnected == uuid) return Promise.resolve(); } this.hashUUID_lastConnected = uuid; console.log('Execute : connect'); return this.bluetoothDevice.gatt.connect() .then(server => { console.log('Execute : getPrimaryService'); return server.getPrimaryService(this.hashUUID[uuid].serviceUUID); }) .then(service => { console.log('Execute : getCharacteristic'); return service.getCharacteristic(this.hashUUID[uuid].characteristicUUID); }) .then(characteristic => { this.dataCharacteristic = characteristic; this.dataCharacteristic.addEventListener('characteristicvaluechanged',this.dataChanged(this, uuid)); this.onConnectGATT(uuid); }) .catch(error => { console.log('Error : ' + error); this.onError(error); }); } BlueJelly.prototype.dataChanged = function(self, uuid) { return function(event) { self.onRead(event.target.value, uuid); } } //-------------------------------------------------- //read //-------------------------------------------------- BlueJelly.prototype.read= function(uuid) { return (this.scan(uuid)) .then( () => { return this.connectGATT(uuid); }) .then( () => { console.log('Execute : readValue'); return this.dataCharacteristic.readValue(); }) .catch(error => { console.log('Error : ' + error); this.onError(error); }); } BlueJelly.prototype.write = function(uuid, array_value) { return (this.scan(uuid)) .then( () => { return this.connectGATT(uuid); }) .then( () => { console.log('Execute : writeValue'); data = Uint8Array.from(array_value); return this.dataCharacteristic.writeValue(data); }) .then( () => { this.onWrite(uuid); }) .catch(error => { console.log('Error : ' + error); this.onError(error); }); } BlueJelly.prototype.startNotify = function(uuid) { return (this.scan(uuid)) .then( () => { return this.connectGATT(uuid); }) .then( () => { console.log('Execute : startNotifications'); this.dataCharacteristic.startNotifications() }) .then( () => { this.onStartNotify(uuid); }) .catch(error => { console.log('Error : ' + error); this.onError(error); }); } BlueJelly.prototype.stopNotify = function(uuid){ return (this.scan(uuid)) .then( () => { return this.connectGATT(uuid); }) .then( () => { console.log('Execute : stopNotifications'); this.dataCharacteristic.stopNotifications() }) .then( () => { this.onStopNotify(uuid); }) .catch(error => { console.log('Error : ' + error); this.onError(error); }); } BlueJelly.prototype.disconnect= function() { if (!this.bluetoothDevice) { var error = "No Bluetooth Device"; console.log('Error : ' + error); this.onError(error); return; } if (this.bluetoothDevice.gatt.connected) { console.log('Execute : disconnect'); this.bluetoothDevice.gatt.disconnect(); } else { var error = "Bluetooth Device is already disconnected"; console.log('Error : ' + error); this.onError(error); return; } } BlueJelly.prototype.clear= function() { console.log('Excute : Clear Device and Characteristic'); this.bluetoothDevice = null; this.dataCharacteristic = null; this.onClear(); } BlueJelly.prototype.reset= function() { console.log('Excute : reset'); this.disconnect(); //disconnect() is not Promise Object this.clear(); this.onReset(); }
**scan.html** <!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="BlueJelly"> <meta name="viewport" content="width=640, maximum-scale=1.0, user-scalable=yes"> <title>BlueJelly</title> <link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="style.css"> <script type="text/javascript" src="bluejelly.js"></script> </head> <body> <h1></h1> <div class="container"> <div class="title margin"> <p id="title">BlueJelly Sample</p> <p id="subtitle">Hello, BLE</p> </div> <div class="contents margin"> <button id="scan" class="button">Scan</button> <hr> <div id="device_name"> </div> </div> <div class="footer margin"> For more information, see <a href="http://jellyware.jp/kurage" target="_blank">jellyware.jp</a> and <a href="https://github.com/electricbaka/bluejelly" target="_blank">GitHub</a> ! </div> </div> <script> //-------------------------------------------------- //Global変数 //-------------------------------------------------- //BlueJellyのインスタンス生成 var ble = new BlueJelly(); //-------------------------------------------------- //ロード時の処理 //-------------------------------------------------- window.onload = function () { //UUIDの設定 ble.setUUID("UUID1", "00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"); } //-------------------------------------------------- //Scan後の処理 //-------------------------------------------------- ble.onScan = function (deviceName) { document.getElementById('device_name').innerHTML = deviceName; } //------------------------------------------------- //ボタンが押された時のイベント登録 //-------------------------------------------------- document.getElementById('scan').addEventListener('click', function() { ble.scan('UUID1'); }); </script> </body> </html>

参考サイト(bluejelly)にある、「serviceのUUIDとCharacteristicのUUID」の意味も教えていただきたいです。
ご教示お願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問