UT-201BLEおよびUA-651BLEの値を読み出そうとするとObnizBleHciStateErrorが発生する



  • 弊社ではUT-201BLEおよびUA-651BLEを以下ドキュメントを参考に技術検証しています。

    https://obniz.com/ja/sdk/parts/UT201BLE/README.md
    https://obniz.com/ja/sdk/parts/UA651BLE/README.md

    以下の内容をobnizクラウドのHTMLプログラムに入力して実行したところ、BLE通信を行うタイミングで50%程度の確率でエラーとなります。

    <html>
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link
          rel="stylesheet"
          href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        />
        <link rel="stylesheet" href="/css/starter-sample.css" />
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
        <script
          src="https://unpkg.com/obniz@3.16.0/obniz.js"
          crossorigin="anonymous"
        ></script>
      </head>
      <body>
        <h1>動作確認結果<h1>
        <script>
    const obniz = new Obniz("xxxx-xxxx");
    const IBS02 = Obniz.getPartsClass('iBS02PIR');
    const UT201BLE = Obniz.getPartsClass("UT201BLE");
    const UA651BLE = Obniz.getPartsClass("UA651BLE");
    
    obniz.onconnect = async () => {
    	await obniz.ble.initWait();
    
    	obniz.ble.scan.onfind = async (peripheral) => {
    		if (IBS02.isDevice(peripheral)) {
    			const data = IBS02.getData(peripheral);
    			console.log(data);
    		} else if (UT201BLE.isDevice(peripheral)) {
    			const device = new UT201BLE(peripheral);
    			const data = await device.getDataWait();
    			console.log(data);
    			obniz.ble.scan.startWait(null, { duplicate: true, duration: null });
    		} else if (UA651BLE.isDevice(peripheral)) {
    			const device = new UA651BLE(peripheral);
    			const data = await device.getDataWait();
    			console.log(data);
    			obniz.ble.scan.startWait(null, { duplicate: true, duration: null });
    		}
    	};
    	
    	obniz.ble.scan.onfinish = async (peripherals, error) => {
    		console.log("scan timeout!")
    	};
    	
    	obniz.ble.scan.startWait(null, { duplicate: true, duration: null });
    };
        </script>
      </body>
    </html>
    
    
    

    エラーが発生した時、以下のerror1またはerror2のいずれかのログが出力されます。

    /Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizConnection.js:378
                            throw err;
                            ^
    
    ObnizBleHciStateError: Connection Failed to be Established / Synchronization Timeout  {"peripheralAddress":"b8804f58aa42"}
        at NobleBindings.onDisconnComplete (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/protocol/central/bindings.js:189:27)
        at Hci.emit (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/eventemitter3/index.js:203:33)
        at Hci.onHciEventData (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/protocol/hci.js:888:18)
        at Hci.onSocketData (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/protocol/hci.js:954:18)
        at ObnizBLEHci.notified (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/hci.js:69:22)
        at ObnizBLE.notifyFromObniz (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/ble.js:122:22)
        at Obniz._notifyToModule (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizComponents.js:271:37)
        at Obniz._notifyToModule (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizDevice.js:149:15)
        at Obniz.wsOnMessage (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizConnection.js:437:26)
        at WebSocket.<anonymous> (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizConnection.js:598:18) {
      code: 10,
      state: 62
    }
    
    /Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizConnection.js:378
                            throw err;
                            ^
    
    ObnizBleHciStateError: Remote User Terminated Connection  {"peripheralAddress":"b8804f58aa42"}
        at NobleBindings.onDisconnComplete (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/protocol/central/bindings.js:189:27)
        at Hci.emit (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/eventemitter3/index.js:203:33)
        at Hci.onHciEventData (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/protocol/hci.js:888:18)
        at Hci.onSocketData (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/protocol/hci.js:954:18)
        at ObnizBLEHci.notified (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/hci.js:69:22)
        at ObnizBLE.notifyFromObniz (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/libs/embeds/bleHci/ble.js:122:22)
        at Obniz._notifyToModule (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizComponents.js:271:37)
        at Obniz._notifyToModule (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizDevice.js:149:15)
        at Obniz.wsOnMessage (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizConnection.js:437:26)
        at WebSocket.<anonymous> (/Users/user/src/github.com/githubuser/proto-hydra/device/obniz/IoTGateway/node_modules/obniz/dist/src/obniz/ObnizConnection.js:598:18) {
      code: 10,
      state: 19
    }
    

    何か回避策はありますでしょうか?



  • エラーの内容を見るとBLEの接続に失敗しているようです。
    BLEは環境に大きく依存しやすいので、有線でのセンサと比べて失敗確率は高くなります。

    • BLEが混雑していない場所でしようする
    • 近づけてみる
    • 電波の出力を上げてみる(デバイス側)

    などの対処で改善できないでしょうか。

    また、接続前にperipheral.rssi(電波強度)を確認すると、接続に成功しやすいか失敗しやすいかの傾向がわかるかもしれません


Log in to reply
 

SUGGESTED TOPICS

  • 3
  • 2
  • 2
  • 3
  • 7
  • 2